@google-cloud/spanner 8.2.1 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -1
- package/build/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto +7 -0
- package/build/protos/protos.d.ts +6 -0
- package/build/protos/protos.js +28 -0
- package/build/protos/protos.json +15 -1
- package/build/src/index.d.ts +7 -0
- package/build/src/index.js +59 -14
- package/build/src/metrics/interceptor.js +7 -1
- package/build/src/metrics/metrics-tracer-factory.d.ts +2 -3
- package/build/src/metrics/metrics-tracer-factory.js +3 -5
- package/build/src/metrics/metrics-tracer.d.ts +2 -1
- package/build/src/metrics/metrics-tracer.js +4 -2
- package/build/src/metrics/spanner-metrics-exporter.d.ts +2 -1
- package/build/src/metrics/spanner-metrics-exporter.js +16 -23
- package/build/src/metrics/transform.d.ts +2 -2
- package/build/src/metrics/transform.js +7 -7
- package/build/src/multiplexed-session.js +3 -1
- package/build/src/session-factory.d.ts +11 -9
- package/build/src/session-factory.js +32 -27
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# [Cloud Spanner: Node.js Client](https://github.com/googleapis/nodejs-spanner)
|
|
6
6
|
|
|
7
7
|
[](https://cloud.google.com/terms/launch-stages)
|
|
8
|
-
[](https://www.npmjs.
|
|
8
|
+
[](https://www.npmjs.com/package/@google-cloud/spanner)
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
@@ -80,6 +80,28 @@ console.log(`Query: ${rows.length} found.`);
|
|
|
80
80
|
rows.forEach(row => console.log(row));
|
|
81
81
|
|
|
82
82
|
```
|
|
83
|
+
## Metrics
|
|
84
|
+
|
|
85
|
+
Cloud Spanner client supports [client-side metrics](https://cloud.google.com/spanner/docs/view-manage-client-side-metrics) that you can use along with server-side metrics to optimize performance and troubleshoot performance issues if they occur.
|
|
86
|
+
|
|
87
|
+
Client-side metrics are measured from the time a request leaves your application to the time your application receives the response.
|
|
88
|
+
In contrast, server-side metrics are measured from the time Spanner receives a request until the last byte of data is sent to the client.
|
|
89
|
+
|
|
90
|
+
These metrics are enabled by default. You can opt out of using client-side metrics with the following code:
|
|
91
|
+
|
|
92
|
+
```javascript
|
|
93
|
+
const spanner = new Spanner({
|
|
94
|
+
disableBuiltInMetrics: true
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
You can also disable these metrics by setting `SPANNER_DISABLE_BUILTIN_METRICS` to `true`.
|
|
99
|
+
|
|
100
|
+
> Note: Client-side metrics needs `monitoring.timeSeries.create` IAM permission to export metrics data. Ask your administrator to grant your service account the [Monitoring Metric Writer](https://cloud.google.com/iam/docs/roles-permissions/monitoring#monitoring.metricWriter) (roles/monitoring.metricWriter) IAM role on the project.
|
|
101
|
+
|
|
102
|
+
## Traces
|
|
103
|
+
Refer to the Observability README to know more about tracing support in the Cloud Spanner client.
|
|
104
|
+
|
|
83
105
|
## Multiplexed Sessions
|
|
84
106
|
|
|
85
107
|
Spanner's Multiplexed Sessions can now be used as an efficient alternative to the default session pool. This feature helps reduce
|
|
@@ -209,6 +231,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-spanner/tre
|
|
|
209
231
|
| Queryoptions | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/queryoptions.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/queryoptions.js,samples/README.md) |
|
|
210
232
|
| Quickstart | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
|
|
211
233
|
| Read data with database role | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/read-data-with-database-role.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/read-data-with-database-role.js,samples/README.md) |
|
|
234
|
+
| Performs a read-write transaction with isolation level option | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/repeatable-reads.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/repeatable-reads.js,samples/README.md) |
|
|
212
235
|
| Sets a request tag for a single query | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/request-tag.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/request-tag.js,samples/README.md) |
|
|
213
236
|
| Run Batch update with RPC priority | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/rpc-priority-batch-dml.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/rpc-priority-batch-dml.js,samples/README.md) |
|
|
214
237
|
| Run partitioned update with RPC priority | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/rpc-priority-partitioned-dml.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/rpc-priority-partitioned-dml.js,samples/README.md) |
|
|
@@ -1755,6 +1755,13 @@ message InstancePartition {
|
|
|
1755
1755
|
int32 processing_units = 6;
|
|
1756
1756
|
}
|
|
1757
1757
|
|
|
1758
|
+
// Optional. The autoscaling configuration. Autoscaling is enabled if this
|
|
1759
|
+
// field is set. When autoscaling is enabled, fields in compute_capacity are
|
|
1760
|
+
// treated as OUTPUT_ONLY fields and reflect the current compute capacity
|
|
1761
|
+
// allocated to the instance partition.
|
|
1762
|
+
AutoscalingConfig autoscaling_config = 13
|
|
1763
|
+
[(google.api.field_behavior) = OPTIONAL];
|
|
1764
|
+
|
|
1758
1765
|
// Output only. The current instance partition state.
|
|
1759
1766
|
State state = 7 [(google.api.field_behavior) = OUTPUT_ONLY];
|
|
1760
1767
|
|
package/build/protos/protos.d.ts
CHANGED
|
@@ -18097,6 +18097,9 @@ export namespace google {
|
|
|
18097
18097
|
/** InstancePartition processingUnits */
|
|
18098
18098
|
processingUnits?: (number|null);
|
|
18099
18099
|
|
|
18100
|
+
/** InstancePartition autoscalingConfig */
|
|
18101
|
+
autoscalingConfig?: (google.spanner.admin.instance.v1.IAutoscalingConfig|null);
|
|
18102
|
+
|
|
18100
18103
|
/** InstancePartition state */
|
|
18101
18104
|
state?: (google.spanner.admin.instance.v1.InstancePartition.State|keyof typeof google.spanner.admin.instance.v1.InstancePartition.State|null);
|
|
18102
18105
|
|
|
@@ -18140,6 +18143,9 @@ export namespace google {
|
|
|
18140
18143
|
/** InstancePartition processingUnits. */
|
|
18141
18144
|
public processingUnits?: (number|null);
|
|
18142
18145
|
|
|
18146
|
+
/** InstancePartition autoscalingConfig. */
|
|
18147
|
+
public autoscalingConfig?: (google.spanner.admin.instance.v1.IAutoscalingConfig|null);
|
|
18148
|
+
|
|
18143
18149
|
/** InstancePartition state. */
|
|
18144
18150
|
public state: (google.spanner.admin.instance.v1.InstancePartition.State|keyof typeof google.spanner.admin.instance.v1.InstancePartition.State);
|
|
18145
18151
|
|
package/build/protos/protos.js
CHANGED
|
@@ -46366,6 +46366,7 @@
|
|
|
46366
46366
|
* @property {string|null} [displayName] InstancePartition displayName
|
|
46367
46367
|
* @property {number|null} [nodeCount] InstancePartition nodeCount
|
|
46368
46368
|
* @property {number|null} [processingUnits] InstancePartition processingUnits
|
|
46369
|
+
* @property {google.spanner.admin.instance.v1.IAutoscalingConfig|null} [autoscalingConfig] InstancePartition autoscalingConfig
|
|
46369
46370
|
* @property {google.spanner.admin.instance.v1.InstancePartition.State|null} [state] InstancePartition state
|
|
46370
46371
|
* @property {google.protobuf.ITimestamp|null} [createTime] InstancePartition createTime
|
|
46371
46372
|
* @property {google.protobuf.ITimestamp|null} [updateTime] InstancePartition updateTime
|
|
@@ -46431,6 +46432,14 @@
|
|
|
46431
46432
|
*/
|
|
46432
46433
|
InstancePartition.prototype.processingUnits = null;
|
|
46433
46434
|
|
|
46435
|
+
/**
|
|
46436
|
+
* InstancePartition autoscalingConfig.
|
|
46437
|
+
* @member {google.spanner.admin.instance.v1.IAutoscalingConfig|null|undefined} autoscalingConfig
|
|
46438
|
+
* @memberof google.spanner.admin.instance.v1.InstancePartition
|
|
46439
|
+
* @instance
|
|
46440
|
+
*/
|
|
46441
|
+
InstancePartition.prototype.autoscalingConfig = null;
|
|
46442
|
+
|
|
46434
46443
|
/**
|
|
46435
46444
|
* InstancePartition state.
|
|
46436
46445
|
* @member {google.spanner.admin.instance.v1.InstancePartition.State} state
|
|
@@ -46541,6 +46550,8 @@
|
|
|
46541
46550
|
writer.uint32(/* id 11, wireType 2 =*/90).string(message.referencingBackups[i]);
|
|
46542
46551
|
if (message.etag != null && Object.hasOwnProperty.call(message, "etag"))
|
|
46543
46552
|
writer.uint32(/* id 12, wireType 2 =*/98).string(message.etag);
|
|
46553
|
+
if (message.autoscalingConfig != null && Object.hasOwnProperty.call(message, "autoscalingConfig"))
|
|
46554
|
+
$root.google.spanner.admin.instance.v1.AutoscalingConfig.encode(message.autoscalingConfig, writer.uint32(/* id 13, wireType 2 =*/106).fork()).ldelim();
|
|
46544
46555
|
return writer;
|
|
46545
46556
|
};
|
|
46546
46557
|
|
|
@@ -46597,6 +46608,10 @@
|
|
|
46597
46608
|
message.processingUnits = reader.int32();
|
|
46598
46609
|
break;
|
|
46599
46610
|
}
|
|
46611
|
+
case 13: {
|
|
46612
|
+
message.autoscalingConfig = $root.google.spanner.admin.instance.v1.AutoscalingConfig.decode(reader, reader.uint32());
|
|
46613
|
+
break;
|
|
46614
|
+
}
|
|
46600
46615
|
case 7: {
|
|
46601
46616
|
message.state = reader.int32();
|
|
46602
46617
|
break;
|
|
@@ -46682,6 +46697,11 @@
|
|
|
46682
46697
|
if (!$util.isInteger(message.processingUnits))
|
|
46683
46698
|
return "processingUnits: integer expected";
|
|
46684
46699
|
}
|
|
46700
|
+
if (message.autoscalingConfig != null && message.hasOwnProperty("autoscalingConfig")) {
|
|
46701
|
+
var error = $root.google.spanner.admin.instance.v1.AutoscalingConfig.verify(message.autoscalingConfig);
|
|
46702
|
+
if (error)
|
|
46703
|
+
return "autoscalingConfig." + error;
|
|
46704
|
+
}
|
|
46685
46705
|
if (message.state != null && message.hasOwnProperty("state"))
|
|
46686
46706
|
switch (message.state) {
|
|
46687
46707
|
default:
|
|
@@ -46743,6 +46763,11 @@
|
|
|
46743
46763
|
message.nodeCount = object.nodeCount | 0;
|
|
46744
46764
|
if (object.processingUnits != null)
|
|
46745
46765
|
message.processingUnits = object.processingUnits | 0;
|
|
46766
|
+
if (object.autoscalingConfig != null) {
|
|
46767
|
+
if (typeof object.autoscalingConfig !== "object")
|
|
46768
|
+
throw TypeError(".google.spanner.admin.instance.v1.InstancePartition.autoscalingConfig: object expected");
|
|
46769
|
+
message.autoscalingConfig = $root.google.spanner.admin.instance.v1.AutoscalingConfig.fromObject(object.autoscalingConfig);
|
|
46770
|
+
}
|
|
46746
46771
|
switch (object.state) {
|
|
46747
46772
|
default:
|
|
46748
46773
|
if (typeof object.state === "number") {
|
|
@@ -46817,6 +46842,7 @@
|
|
|
46817
46842
|
object.createTime = null;
|
|
46818
46843
|
object.updateTime = null;
|
|
46819
46844
|
object.etag = "";
|
|
46845
|
+
object.autoscalingConfig = null;
|
|
46820
46846
|
}
|
|
46821
46847
|
if (message.name != null && message.hasOwnProperty("name"))
|
|
46822
46848
|
object.name = message.name;
|
|
@@ -46852,6 +46878,8 @@
|
|
|
46852
46878
|
}
|
|
46853
46879
|
if (message.etag != null && message.hasOwnProperty("etag"))
|
|
46854
46880
|
object.etag = message.etag;
|
|
46881
|
+
if (message.autoscalingConfig != null && message.hasOwnProperty("autoscalingConfig"))
|
|
46882
|
+
object.autoscalingConfig = $root.google.spanner.admin.instance.v1.AutoscalingConfig.toObject(message.autoscalingConfig, options);
|
|
46855
46883
|
return object;
|
|
46856
46884
|
};
|
|
46857
46885
|
|
package/build/protos/protos.json
CHANGED
|
@@ -460,7 +460,14 @@
|
|
|
460
460
|
"type": "ServiceOptions",
|
|
461
461
|
"id": 3
|
|
462
462
|
}
|
|
463
|
-
}
|
|
463
|
+
},
|
|
464
|
+
"reserved": [
|
|
465
|
+
[
|
|
466
|
+
4,
|
|
467
|
+
4
|
|
468
|
+
],
|
|
469
|
+
"stream"
|
|
470
|
+
]
|
|
464
471
|
},
|
|
465
472
|
"MethodDescriptorProto": {
|
|
466
473
|
"edition": "proto2",
|
|
@@ -5317,6 +5324,13 @@
|
|
|
5317
5324
|
"type": "int32",
|
|
5318
5325
|
"id": 6
|
|
5319
5326
|
},
|
|
5327
|
+
"autoscalingConfig": {
|
|
5328
|
+
"type": "AutoscalingConfig",
|
|
5329
|
+
"id": 13,
|
|
5330
|
+
"options": {
|
|
5331
|
+
"(google.api.field_behavior)": "OPTIONAL"
|
|
5332
|
+
}
|
|
5333
|
+
},
|
|
5320
5334
|
"state": {
|
|
5321
5335
|
"type": "State",
|
|
5322
5336
|
"id": 7,
|
package/build/src/index.d.ts
CHANGED
|
@@ -177,6 +177,7 @@ declare class Spanner extends GrpcService {
|
|
|
177
177
|
instances_: Map<string, Instance>;
|
|
178
178
|
instanceConfigs_: Map<string, InstanceConfig>;
|
|
179
179
|
projectIdReplaced_: boolean;
|
|
180
|
+
projectId_?: string;
|
|
180
181
|
projectFormattedName_: string;
|
|
181
182
|
commonHeaders_: {
|
|
182
183
|
[k: string]: string;
|
|
@@ -851,6 +852,12 @@ declare class Spanner extends GrpcService {
|
|
|
851
852
|
* Setup the OpenTelemetry metrics capturing for service metrics to Google Cloud Monitoring.
|
|
852
853
|
*/
|
|
853
854
|
configureMetrics_(disableBuiltInMetrics?: boolean): void;
|
|
855
|
+
/**
|
|
856
|
+
* Logs the Spanner configurations that have been set.
|
|
857
|
+
*
|
|
858
|
+
* @private
|
|
859
|
+
*/
|
|
860
|
+
private _logSpannerConfigurations;
|
|
854
861
|
/**
|
|
855
862
|
* Prepare a gapic request. This will cache the GAX client and replace
|
|
856
863
|
* {{projectId}} placeholders, if necessary.
|
package/build/src/index.js
CHANGED
|
@@ -153,6 +153,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
153
153
|
instances_;
|
|
154
154
|
instanceConfigs_;
|
|
155
155
|
projectIdReplaced_;
|
|
156
|
+
projectId_;
|
|
156
157
|
projectFormattedName_;
|
|
157
158
|
commonHeaders_;
|
|
158
159
|
routeToLeaderEnabled = true;
|
|
@@ -240,8 +241,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
240
241
|
libVersion: require('../../package.json').version,
|
|
241
242
|
scopes,
|
|
242
243
|
// Add grpc keep alive setting
|
|
243
|
-
'grpc.keepalive_time_ms':
|
|
244
|
-
'grpc.keepalive_timeout_ms': 10000,
|
|
244
|
+
'grpc.keepalive_time_ms': 120000,
|
|
245
245
|
// Enable grpc-gcp support
|
|
246
246
|
'grpc.callInvocationTransformer': grpcGcp.gcpCallInvocationTransformer,
|
|
247
247
|
'grpc.channelFactoryOverride': grpcGcp.gcpChannelFactoryOverride,
|
|
@@ -305,7 +305,9 @@ class Spanner extends service_1.GrpcService {
|
|
|
305
305
|
(0, instrument_1.ensureInitialContextManagerSet)();
|
|
306
306
|
this._nthClientId = (0, request_id_header_1.nextSpannerClientId)();
|
|
307
307
|
this._universeDomain = universeEndpoint;
|
|
308
|
+
this.projectId_ = options.projectId;
|
|
308
309
|
this.configureMetrics_(options.disableBuiltInMetrics);
|
|
310
|
+
this._logSpannerConfigurations(config);
|
|
309
311
|
}
|
|
310
312
|
get universeDomain() {
|
|
311
313
|
return this._universeDomain;
|
|
@@ -761,18 +763,61 @@ class Spanner extends service_1.GrpcService {
|
|
|
761
763
|
* Setup the OpenTelemetry metrics capturing for service metrics to Google Cloud Monitoring.
|
|
762
764
|
*/
|
|
763
765
|
configureMetrics_(disableBuiltInMetrics) {
|
|
766
|
+
// Only enable metrics if not explicitly disabled and we are not using
|
|
767
|
+
// insecure credentials.
|
|
764
768
|
const metricsEnabled = process.env.SPANNER_DISABLE_BUILTIN_METRICS !== 'true' &&
|
|
765
769
|
!disableBuiltInMetrics &&
|
|
766
770
|
!this._isInSecureCredentials;
|
|
767
|
-
metrics_tracer_factory_1.MetricsTracerFactory.enabled = metricsEnabled;
|
|
768
771
|
if (metricsEnabled) {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
772
|
+
try {
|
|
773
|
+
this.auth.getProjectId((err, projectId) => {
|
|
774
|
+
if (err || !projectId) {
|
|
775
|
+
console.error('Unable to get Project Id for client side metrics, will skip exporting client' +
|
|
776
|
+
' side metrics' +
|
|
777
|
+
err);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
metrics_tracer_factory_1.MetricsTracerFactory.enabled = metricsEnabled;
|
|
781
|
+
this.projectId_ = projectId;
|
|
782
|
+
const factory = metrics_tracer_factory_1.MetricsTracerFactory.getInstance(projectId);
|
|
783
|
+
const periodicReader = new sdk_metrics_1.PeriodicExportingMetricReader({
|
|
784
|
+
exporter: new spanner_metrics_exporter_1.CloudMonitoringMetricsExporter({ auth: this.auth }, projectId),
|
|
785
|
+
exportIntervalMillis: 60000,
|
|
786
|
+
});
|
|
787
|
+
// Retrieve the MeterProvider to trigger construction
|
|
788
|
+
factory.getMeterProvider([periodicReader]);
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
catch (err) {
|
|
792
|
+
console.error('Unable to configure client side metrics, will skip exporting client' +
|
|
793
|
+
' side metrics' +
|
|
794
|
+
err);
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Logs the Spanner configurations that have been set.
|
|
800
|
+
*
|
|
801
|
+
* @private
|
|
802
|
+
*/
|
|
803
|
+
_logSpannerConfigurations(config) {
|
|
804
|
+
try {
|
|
805
|
+
const afeServerTiming = Spanner.isAFEServerTimingEnabled();
|
|
806
|
+
console.log('Spanner configurations:\n' +
|
|
807
|
+
` Project ID: ${this.projectId_}\n` +
|
|
808
|
+
` Spanner Emulator Host: ${process.env.SPANNER_EMULATOR_HOST || 'not set'}\n` +
|
|
809
|
+
` Base URL: ${config.baseUrl}\n` +
|
|
810
|
+
` Leader aware routing enabled: ${this.routeToLeaderEnabled}\n` +
|
|
811
|
+
` Built in metrics enabled: ${metrics_tracer_factory_1.MetricsTracerFactory.enabled}\n` +
|
|
812
|
+
` AFE Server Timing enabled: ${afeServerTiming}\n` +
|
|
813
|
+
` Spanner extended tracing enabled: ${this._observabilityOptions?.enableExtendedTracing === true || process.env.SPANNER_ENABLE_EXTENDED_TRACING === 'true' || false}\n` +
|
|
814
|
+
` Spanner end-to-end tracing enabled: ${this._observabilityOptions?.enableEndToEndTracing === true || process.env.SPANNER_ENABLE_END_TO_END_TRACING === 'true' || false}\n` +
|
|
815
|
+
` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS || 'not set'}\n` +
|
|
816
|
+
` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS || 'not set'}\n` +
|
|
817
|
+
` GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW: ${process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW || 'not set'}\n `);
|
|
818
|
+
}
|
|
819
|
+
catch (error) {
|
|
820
|
+
console.log('Unable to log Spanner configurations:\n' + error);
|
|
776
821
|
}
|
|
777
822
|
}
|
|
778
823
|
/**
|
|
@@ -898,9 +943,9 @@ class Spanner extends service_1.GrpcService {
|
|
|
898
943
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
899
944
|
request(config, callback) {
|
|
900
945
|
let metricsTracer = null;
|
|
901
|
-
if (config.client === 'SpannerClient') {
|
|
946
|
+
if (config.client === 'SpannerClient' && this.projectId_) {
|
|
902
947
|
metricsTracer =
|
|
903
|
-
metrics_tracer_factory_1.MetricsTracerFactory?.getInstance()?.createMetricsTracer(config.method, config.reqOpts.
|
|
948
|
+
metrics_tracer_factory_1.MetricsTracerFactory?.getInstance(this.projectId_)?.createMetricsTracer(config.method, config.reqOpts.database ?? config.reqOpts.session, config.headers['x-goog-spanner-request-id']) ?? null;
|
|
904
949
|
}
|
|
905
950
|
metricsTracer?.recordOperationStart();
|
|
906
951
|
if (typeof callback === 'function') {
|
|
@@ -961,9 +1006,9 @@ class Spanner extends service_1.GrpcService {
|
|
|
961
1006
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
962
1007
|
requestStream(config) {
|
|
963
1008
|
let metricsTracer = null;
|
|
964
|
-
if (config.client === 'SpannerClient') {
|
|
1009
|
+
if (config.client === 'SpannerClient' && this.projectId_) {
|
|
965
1010
|
metricsTracer =
|
|
966
|
-
metrics_tracer_factory_1.MetricsTracerFactory?.getInstance()?.createMetricsTracer(config.method, config.reqOpts.session ?? config.reqOpts.database, config.headers['x-goog-spanner-request-id']) ?? null;
|
|
1011
|
+
metrics_tracer_factory_1.MetricsTracerFactory?.getInstance(this.projectId_)?.createMetricsTracer(config.method, config.reqOpts.session ?? config.reqOpts.database, config.headers['x-goog-spanner-request-id']) ?? null;
|
|
967
1012
|
}
|
|
968
1013
|
metricsTracer?.recordOperationStart();
|
|
969
1014
|
const stream = streamEvents(through.obj());
|
|
@@ -31,7 +31,13 @@ const MetricInterceptor = (options, nextCall) => {
|
|
|
31
31
|
return new google_gax_1.grpc.InterceptingCall(nextCall(options), {
|
|
32
32
|
start: function (metadata, listener, next) {
|
|
33
33
|
// Record attempt metric on request start
|
|
34
|
-
const
|
|
34
|
+
const resourcePrefix = metadata.get('google-cloud-resource-prefix')[0];
|
|
35
|
+
const match = resourcePrefix?.match(/^projects\/([^/]+)\//);
|
|
36
|
+
const projectId = match ? match[1] : undefined;
|
|
37
|
+
let factory;
|
|
38
|
+
if (projectId) {
|
|
39
|
+
factory = metrics_tracer_factory_1.MetricsTracerFactory.getInstance(projectId);
|
|
40
|
+
}
|
|
35
41
|
const requestId = metadata.get('x-goog-spanner-request-id')[0];
|
|
36
42
|
const metricsTracer = factory?.getCurrentTracer(requestId);
|
|
37
43
|
metricsTracer?.recordAttemptStart();
|
|
@@ -33,7 +33,6 @@ export declare class MetricsTracerFactory {
|
|
|
33
33
|
private _currentOperationTracers;
|
|
34
34
|
private _currentOperationLastUpdatedMs;
|
|
35
35
|
private _intervalTracerCleanup;
|
|
36
|
-
static _readers: MetricReader[];
|
|
37
36
|
static enabled: boolean;
|
|
38
37
|
/**
|
|
39
38
|
* Private constructor to enforce singleton pattern.
|
|
@@ -49,7 +48,7 @@ export declare class MetricsTracerFactory {
|
|
|
49
48
|
* @param projectId Optional GCP project ID for the factory instantiation. Does nothing for subsequent calls.
|
|
50
49
|
* @returns The singleton MetricsTracerFactory instance or null if disabled.
|
|
51
50
|
*/
|
|
52
|
-
static getInstance(projectId
|
|
51
|
+
static getInstance(projectId: string): MetricsTracerFactory | null;
|
|
53
52
|
/**
|
|
54
53
|
* Returns the MeterProvider, creating it and metric instruments if not already initialized.
|
|
55
54
|
* Client-wide attributes that are known at this time are cached to be provided to all MetricsTracers.
|
|
@@ -60,7 +59,7 @@ export declare class MetricsTracerFactory {
|
|
|
60
59
|
/**
|
|
61
60
|
* Resets the singleton instance of the MetricsTracerFactory.
|
|
62
61
|
*/
|
|
63
|
-
static resetInstance(): Promise<void>;
|
|
62
|
+
static resetInstance(projectId?: string): Promise<void>;
|
|
64
63
|
/**
|
|
65
64
|
* Resets the MeterProvider.
|
|
66
65
|
*/
|
|
@@ -56,7 +56,6 @@ class MetricsTracerFactory {
|
|
|
56
56
|
_currentOperationTracers = new Map();
|
|
57
57
|
_currentOperationLastUpdatedMs = new Map();
|
|
58
58
|
_intervalTracerCleanup;
|
|
59
|
-
static _readers = [];
|
|
60
59
|
static enabled = true;
|
|
61
60
|
/**
|
|
62
61
|
* Private constructor to enforce singleton pattern.
|
|
@@ -91,7 +90,7 @@ class MetricsTracerFactory {
|
|
|
91
90
|
* @param projectId Optional GCP project ID for the factory instantiation. Does nothing for subsequent calls.
|
|
92
91
|
* @returns The singleton MetricsTracerFactory instance or null if disabled.
|
|
93
92
|
*/
|
|
94
|
-
static getInstance(projectId
|
|
93
|
+
static getInstance(projectId) {
|
|
95
94
|
if (!MetricsTracerFactory.enabled) {
|
|
96
95
|
return null;
|
|
97
96
|
}
|
|
@@ -116,7 +115,6 @@ class MetricsTracerFactory {
|
|
|
116
115
|
[Constants.MONITORED_RES_LABEL_KEY_INSTANCE]: 'unknown',
|
|
117
116
|
[Constants.MONITORED_RES_LABEL_KEY_INSTANCE_CONFIG]: 'unknown',
|
|
118
117
|
});
|
|
119
|
-
MetricsTracerFactory._readers = readers;
|
|
120
118
|
this._meterProvider = new sdk_metrics_1.MeterProvider({
|
|
121
119
|
resource: resource,
|
|
122
120
|
readers: readers,
|
|
@@ -129,7 +127,7 @@ class MetricsTracerFactory {
|
|
|
129
127
|
/**
|
|
130
128
|
* Resets the singleton instance of the MetricsTracerFactory.
|
|
131
129
|
*/
|
|
132
|
-
static async resetInstance() {
|
|
130
|
+
static async resetInstance(projectId) {
|
|
133
131
|
clearInterval(MetricsTracerFactory._instance?._intervalTracerCleanup);
|
|
134
132
|
await MetricsTracerFactory._instance?.resetMeterProvider();
|
|
135
133
|
MetricsTracerFactory._instance = null;
|
|
@@ -209,7 +207,7 @@ class MetricsTracerFactory {
|
|
|
209
207
|
return this._currentOperationTracers.get(operationRequest);
|
|
210
208
|
}
|
|
211
209
|
const { instance, database } = this.getInstanceAttributes(formattedName);
|
|
212
|
-
const tracer = new metrics_tracer_1.MetricsTracer(this._instrumentAttemptCounter, this._instrumentAttemptLatency, this._instrumentOperationCounter, this._instrumentOperationLatency, this._instrumentGfeConnectivityErrorCount, this._instrumentGfeLatency, this._instrumentAfeConnectivityErrorCount, this._instrumentAfeLatency, MetricsTracerFactory.enabled, database, instance, method, operationRequest);
|
|
210
|
+
const tracer = new metrics_tracer_1.MetricsTracer(this._instrumentAttemptCounter, this._instrumentAttemptLatency, this._instrumentOperationCounter, this._instrumentOperationLatency, this._instrumentGfeConnectivityErrorCount, this._instrumentGfeLatency, this._instrumentAfeConnectivityErrorCount, this._instrumentAfeLatency, MetricsTracerFactory.enabled, database, instance, this._projectId, method, operationRequest);
|
|
213
211
|
this._currentOperationTracers.set(operationRequest, tracer);
|
|
214
212
|
this._currentOperationLastUpdatedMs.set(operationRequest, Date.now());
|
|
215
213
|
return tracer;
|
|
@@ -79,6 +79,7 @@ export declare class MetricsTracer {
|
|
|
79
79
|
enabled: boolean;
|
|
80
80
|
private _database;
|
|
81
81
|
private _instance;
|
|
82
|
+
private _projectId;
|
|
82
83
|
private _methodName;
|
|
83
84
|
private _request;
|
|
84
85
|
/**
|
|
@@ -104,7 +105,7 @@ export declare class MetricsTracer {
|
|
|
104
105
|
* @param _instrumentAfeLatency Histogram for AFE latency metrics.
|
|
105
106
|
* @param enabled Whether metrics recording is enabled.
|
|
106
107
|
*/
|
|
107
|
-
constructor(_instrumentAttemptCounter: Counter | null, _instrumentAttemptLatency: Histogram | null, _instrumentOperationCounter: Counter | null, _instrumentOperationLatency: Histogram | null, _instrumentGfeConnectivityErrorCount: Counter | null, _instrumentGfeLatency: Histogram | null, _instrumentAfeConnectivityErrorCount: Counter | null, _instrumentAfeLatency: Histogram | null, enabled: boolean, _database: string, _instance: string, _methodName: string, _request: string);
|
|
108
|
+
constructor(_instrumentAttemptCounter: Counter | null, _instrumentAttemptLatency: Histogram | null, _instrumentOperationCounter: Counter | null, _instrumentOperationLatency: Histogram | null, _instrumentGfeConnectivityErrorCount: Counter | null, _instrumentGfeLatency: Histogram | null, _instrumentAfeConnectivityErrorCount: Counter | null, _instrumentAfeLatency: Histogram | null, enabled: boolean, _database: string, _instance: string, _projectId: string, _methodName: string, _request: string);
|
|
108
109
|
/**
|
|
109
110
|
* Returns the difference in milliseconds between two Date objects.
|
|
110
111
|
* @param start The start time.
|
|
@@ -115,6 +115,7 @@ class MetricsTracer {
|
|
|
115
115
|
enabled;
|
|
116
116
|
_database;
|
|
117
117
|
_instance;
|
|
118
|
+
_projectId;
|
|
118
119
|
_methodName;
|
|
119
120
|
_request;
|
|
120
121
|
/**
|
|
@@ -146,7 +147,7 @@ class MetricsTracer {
|
|
|
146
147
|
* @param _instrumentAfeLatency Histogram for AFE latency metrics.
|
|
147
148
|
* @param enabled Whether metrics recording is enabled.
|
|
148
149
|
*/
|
|
149
|
-
constructor(_instrumentAttemptCounter, _instrumentAttemptLatency, _instrumentOperationCounter, _instrumentOperationLatency, _instrumentGfeConnectivityErrorCount, _instrumentGfeLatency, _instrumentAfeConnectivityErrorCount, _instrumentAfeLatency, enabled, _database, _instance, _methodName, _request) {
|
|
150
|
+
constructor(_instrumentAttemptCounter, _instrumentAttemptLatency, _instrumentOperationCounter, _instrumentOperationLatency, _instrumentGfeConnectivityErrorCount, _instrumentGfeLatency, _instrumentAfeConnectivityErrorCount, _instrumentAfeLatency, enabled, _database, _instance, _projectId, _methodName, _request) {
|
|
150
151
|
this._instrumentAttemptCounter = _instrumentAttemptCounter;
|
|
151
152
|
this._instrumentAttemptLatency = _instrumentAttemptLatency;
|
|
152
153
|
this._instrumentOperationCounter = _instrumentOperationCounter;
|
|
@@ -158,6 +159,7 @@ class MetricsTracer {
|
|
|
158
159
|
this.enabled = enabled;
|
|
159
160
|
this._database = _database;
|
|
160
161
|
this._instance = _instance;
|
|
162
|
+
this._projectId = _projectId;
|
|
161
163
|
this._methodName = _methodName;
|
|
162
164
|
this._request = _request;
|
|
163
165
|
this._clientAttributes[constants_1.METRIC_LABEL_KEY_DATABASE] = _database;
|
|
@@ -250,7 +252,7 @@ class MetricsTracer {
|
|
|
250
252
|
const operationLatencyMilliseconds = this._getMillisecondTimeDifference(this.currentOperation.startTime, endTime);
|
|
251
253
|
this.instrumentOperationCounter?.add(1, operationAttributes);
|
|
252
254
|
this.instrumentOperationLatency?.record(operationLatencyMilliseconds, operationAttributes);
|
|
253
|
-
metrics_tracer_factory_1.MetricsTracerFactory.getInstance().clearCurrentTracer(this._request);
|
|
255
|
+
metrics_tracer_factory_1.MetricsTracerFactory.getInstance(this._projectId).clearCurrentTracer(this._request);
|
|
254
256
|
}
|
|
255
257
|
/**
|
|
256
258
|
* Extracts the GFE latency value (in milliseconds) from a 'server-timing' header string.
|
|
@@ -9,7 +9,8 @@ export declare class CloudMonitoringMetricsExporter implements PushMetricExporte
|
|
|
9
9
|
private _projectId;
|
|
10
10
|
private _lastExported;
|
|
11
11
|
private readonly _client;
|
|
12
|
-
|
|
12
|
+
private _metricsExportFailureLogged;
|
|
13
|
+
constructor({ auth }: ExporterOptions, projectId: string);
|
|
13
14
|
/**
|
|
14
15
|
* Implementation for {@link PushMetricExporter.export}.
|
|
15
16
|
* Calls the async wrapper method {@link _exportAsync} and
|
|
@@ -29,13 +29,10 @@ class CloudMonitoringMetricsExporter {
|
|
|
29
29
|
_projectId;
|
|
30
30
|
_lastExported = new Date(0);
|
|
31
31
|
_client;
|
|
32
|
-
|
|
32
|
+
_metricsExportFailureLogged = false;
|
|
33
|
+
constructor({ auth }, projectId) {
|
|
33
34
|
this._client = new monitoring_1.MetricServiceClient({ auth: auth });
|
|
34
|
-
|
|
35
|
-
// awaited on the first export because constructors are synchronous
|
|
36
|
-
this._projectId = auth.getProjectId().catch(err => {
|
|
37
|
-
console.error(err);
|
|
38
|
-
});
|
|
35
|
+
this._projectId = projectId;
|
|
39
36
|
}
|
|
40
37
|
/**
|
|
41
38
|
* Implementation for {@link PushMetricExporter.export}.
|
|
@@ -54,7 +51,6 @@ class CloudMonitoringMetricsExporter {
|
|
|
54
51
|
}
|
|
55
52
|
this._lastExported = now;
|
|
56
53
|
this._exportAsync(metrics).then(resultCallback, err => {
|
|
57
|
-
console.error(err.message);
|
|
58
54
|
resultCallback({ code: core_1.ExportResultCode.FAILED, error: err });
|
|
59
55
|
});
|
|
60
56
|
}
|
|
@@ -68,28 +64,25 @@ class CloudMonitoringMetricsExporter {
|
|
|
68
64
|
* @param resourceMetrics Metrics to be sent to the Google Cloud Monitoring backend
|
|
69
65
|
*/
|
|
70
66
|
async _exportAsync(resourceMetrics) {
|
|
71
|
-
|
|
72
|
-
this._projectId = await this._projectId;
|
|
73
|
-
}
|
|
74
|
-
if (!this._projectId) {
|
|
75
|
-
const error = new Error('expecting a non-blank ProjectID');
|
|
76
|
-
console.error(error.message);
|
|
77
|
-
return { code: core_1.ExportResultCode.FAILED, error };
|
|
78
|
-
}
|
|
79
|
-
const timeSeriesList = (0, transform_1.transformResourceMetricToTimeSeriesArray)(resourceMetrics);
|
|
67
|
+
const timeSeriesList = (0, transform_1.transformResourceMetricToTimeSeriesArray)(resourceMetrics, this._projectId);
|
|
80
68
|
let failure = {
|
|
81
69
|
sendFailed: false,
|
|
82
70
|
};
|
|
83
71
|
await Promise.all(this._partitionList(timeSeriesList, exports.MAX_BATCH_EXPORT_SIZE).map(async (batchedTimeSeries) => this._sendTimeSeries(batchedTimeSeries))).catch(e => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
if (!this._metricsExportFailureLogged) {
|
|
73
|
+
const error = e;
|
|
74
|
+
let msg = 'Send TimeSeries failed:';
|
|
75
|
+
if (error.code === grpc_js_1.status.PERMISSION_DENIED) {
|
|
76
|
+
msg += ` Need monitoring metric writer permission on project ${this._projectId}. Follow https://cloud.google.com/spanner/docs/view-manage-client-side-metrics#access-client-side-metrics to set up permissions`;
|
|
77
|
+
}
|
|
78
|
+
console.warn(msg);
|
|
79
|
+
this._metricsExportFailureLogged = true;
|
|
87
80
|
}
|
|
88
|
-
|
|
89
|
-
err.message = `Send TimeSeries failed: ${err.message}`;
|
|
90
|
-
failure = { sendFailed: true, error: err };
|
|
91
|
-
console.error(`ERROR: ${err.message}`);
|
|
81
|
+
failure = { sendFailed: true, error: asError(e) };
|
|
92
82
|
});
|
|
83
|
+
if (!failure.sendFailed && this._metricsExportFailureLogged) {
|
|
84
|
+
this._metricsExportFailureLogged = false;
|
|
85
|
+
}
|
|
93
86
|
return failure.sendFailed
|
|
94
87
|
? {
|
|
95
88
|
code: core_1.ExportResultCode.FAILED,
|
|
@@ -13,7 +13,7 @@ declare function _transformValueType(metric: MetricData): ValueType;
|
|
|
13
13
|
/**
|
|
14
14
|
* Convert the metrics data to a list of Google Cloud Monitoring time series.
|
|
15
15
|
*/
|
|
16
|
-
export declare function transformResourceMetricToTimeSeriesArray(resourceMetrics: ResourceMetrics): {
|
|
16
|
+
export declare function transformResourceMetricToTimeSeriesArray(resourceMetrics: ResourceMetrics, projectId: string): {
|
|
17
17
|
metric: {
|
|
18
18
|
type: string;
|
|
19
19
|
labels: {};
|
|
@@ -121,7 +121,7 @@ declare function _transformPoint<T>(metric: MetricData, dataPoint: DataPoint<T>)
|
|
|
121
121
|
};
|
|
122
122
|
};
|
|
123
123
|
/** Extracts metric and monitored resource labels from data point */
|
|
124
|
-
declare function _extractLabels<T>({ attributes }: DataPoint<T> | Resource): {
|
|
124
|
+
declare function _extractLabels<T>({ attributes }: DataPoint<T> | Resource, projectId: string): {
|
|
125
125
|
metricLabels: {};
|
|
126
126
|
monitoredResourceLabels: {};
|
|
127
127
|
};
|
|
@@ -62,7 +62,7 @@ function _transformValueType(metric) {
|
|
|
62
62
|
/**
|
|
63
63
|
* Convert the metrics data to a list of Google Cloud Monitoring time series.
|
|
64
64
|
*/
|
|
65
|
-
function transformResourceMetricToTimeSeriesArray(resourceMetrics) {
|
|
65
|
+
function transformResourceMetricToTimeSeriesArray(resourceMetrics, projectId) {
|
|
66
66
|
const resource = resourceMetrics?.resource;
|
|
67
67
|
const scopeMetrics = resourceMetrics?.scopeMetrics;
|
|
68
68
|
if (!scopeMetrics)
|
|
@@ -75,17 +75,17 @@ function transformResourceMetricToTimeSeriesArray(resourceMetrics) {
|
|
|
75
75
|
// Only keeps metrics that match our spanner metric names
|
|
76
76
|
metrics.filter(metric => constants_1.METRIC_NAMES.has(metric.descriptor.name)))
|
|
77
77
|
// Flatmap the data points in each metric to create a TimeSeries for each point
|
|
78
|
-
.flatMap(metric => metric.dataPoints.flatMap(dataPoint => _createTimeSeries(metric, dataPoint, resource))));
|
|
78
|
+
.flatMap(metric => metric.dataPoints.flatMap(dataPoint => _createTimeSeries(metric, dataPoint, resource, projectId))));
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Creates a GCM TimeSeries.
|
|
82
82
|
*/
|
|
83
|
-
function _createTimeSeries(metric, dataPoint, resource) {
|
|
83
|
+
function _createTimeSeries(metric, dataPoint, resource, projectId) {
|
|
84
84
|
const type = path.posix.join(constants_1.CLIENT_METRICS_PREFIX, metric.descriptor.name);
|
|
85
85
|
const resourceLabels = resource
|
|
86
|
-
? _extractLabels(resource)
|
|
86
|
+
? _extractLabels(resource, projectId)
|
|
87
87
|
: { metricLabels: {}, monitoredResourceLabels: {} };
|
|
88
|
-
const dataLabels = _extractLabels(dataPoint);
|
|
88
|
+
const dataLabels = _extractLabels(dataPoint, projectId);
|
|
89
89
|
const labels = {
|
|
90
90
|
...resourceLabels.metricLabels,
|
|
91
91
|
...dataLabels.metricLabels,
|
|
@@ -153,8 +153,8 @@ function _transformPoint(metric, dataPoint) {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
/** Extracts metric and monitored resource labels from data point */
|
|
156
|
-
function _extractLabels({ attributes = {} }) {
|
|
157
|
-
const factory = metrics_tracer_factory_1.MetricsTracerFactory.getInstance();
|
|
156
|
+
function _extractLabels({ attributes = {} }, projectId) {
|
|
157
|
+
const factory = metrics_tracer_factory_1.MetricsTracerFactory.getInstance(projectId);
|
|
158
158
|
// Add Client name and Client UID metric labels
|
|
159
159
|
attributes[constants_1.METRIC_LABEL_KEY_CLIENT_UID] =
|
|
160
160
|
factory?.clientUid ?? constants_1.UNKNOWN_ATTRIBUTE;
|
|
@@ -83,7 +83,7 @@ class MultiplexedSession extends events_1.EventEmitter {
|
|
|
83
83
|
multiplexed: true,
|
|
84
84
|
});
|
|
85
85
|
this._multiplexedSession = createSessionResponse;
|
|
86
|
-
span.addEvent(
|
|
86
|
+
span.addEvent('Created a multiplexed session');
|
|
87
87
|
this.emit(exports.MUX_SESSION_AVAILABLE);
|
|
88
88
|
}
|
|
89
89
|
catch (e) {
|
|
@@ -143,7 +143,9 @@ class MultiplexedSession extends events_1.EventEmitter {
|
|
|
143
143
|
*
|
|
144
144
|
*/
|
|
145
145
|
async _acquire() {
|
|
146
|
+
const span = (0, instrument_1.getActiveOrNoopSpan)();
|
|
146
147
|
const session = await this._getSession();
|
|
148
|
+
span.addEvent('Acquired multiplexed session');
|
|
147
149
|
return session;
|
|
148
150
|
}
|
|
149
151
|
/**
|
|
@@ -101,20 +101,21 @@ export declare class SessionFactory extends common.GrpcServiceObject implements
|
|
|
101
101
|
/**
|
|
102
102
|
* Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
|
|
103
103
|
*
|
|
104
|
-
* If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `
|
|
105
|
-
* retrieve a
|
|
104
|
+
* If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `false`, the method will attempt to
|
|
105
|
+
* retrieve a regular session. Otherwise, it will return a multiplexed session.
|
|
106
106
|
*
|
|
107
107
|
* @param {GetSessionCallback} callback The callback function.
|
|
108
108
|
*/
|
|
109
109
|
getSession(callback: GetSessionCallback): void;
|
|
110
110
|
/**
|
|
111
111
|
* Retrieves a session for partitioned operations, selecting the appropriate session type
|
|
112
|
-
* based on whether multiplexed sessions are
|
|
112
|
+
* based on whether multiplexed sessions are disabled or not.
|
|
113
113
|
*
|
|
114
|
-
* If multiplexed sessions are
|
|
115
|
-
* either a multiplexed session or a regular session based on the configuration.
|
|
114
|
+
* If multiplexed sessions are disabled for partitioned ops this methods delegates the request to `getSession()`, which returns
|
|
115
|
+
* either a multiplexed session or a regular session based on the env configuration.
|
|
116
116
|
*
|
|
117
|
-
* If the multiplexed sessions are disabled, a session
|
|
117
|
+
* If the multiplexed sessions are disabled, a session will get retrieved from the regular session pool.
|
|
118
|
+
* Otherwise a multiplexed session will be used.
|
|
118
119
|
*
|
|
119
120
|
* @param {GetSessionCallback} callback The callback function.
|
|
120
121
|
*/
|
|
@@ -123,10 +124,11 @@ export declare class SessionFactory extends common.GrpcServiceObject implements
|
|
|
123
124
|
* Retrieves a session for read write operations, selecting the appropriate session type
|
|
124
125
|
* based on whether multiplexed sessions are enabled.
|
|
125
126
|
*
|
|
126
|
-
* If multiplexed sessions are
|
|
127
|
-
* either a multiplexed session or a regular session based on the configuration.
|
|
127
|
+
* If multiplexed sessions are disabled for read write this methods delegates the request to `getSession()`, which returns
|
|
128
|
+
* either a multiplexed session or a regular session based on the env configuration.
|
|
128
129
|
*
|
|
129
|
-
* If the multiplexed sessions are disabled, a session
|
|
130
|
+
* If the multiplexed sessions are disabled, a session will get retrieved from the regular session pool.
|
|
131
|
+
* Otherise a multiplexed session will be used.
|
|
130
132
|
*
|
|
131
133
|
* @param {GetSessionCallback} callback The callback function.
|
|
132
134
|
*/
|
|
@@ -45,32 +45,35 @@ class SessionFactory extends common.GrpcServiceObject {
|
|
|
45
45
|
typeof poolOptions === 'function'
|
|
46
46
|
? new poolOptions(database, null)
|
|
47
47
|
: new session_pool_1.SessionPool(database, poolOptions);
|
|
48
|
-
this.pool_.on('error', this.emit.bind(database, 'error'));
|
|
49
|
-
this.pool_.open();
|
|
50
48
|
this.multiplexedSession_ = new multiplexed_session_1.MultiplexedSession(database);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.
|
|
49
|
+
this.multiplexedSession_.on('error', this.emit.bind(database, 'error'));
|
|
50
|
+
this.multiplexedSession_.createSession();
|
|
51
|
+
// set the isMultiplexed property to false if multiplexed session is disabled, otherwise set the property to true
|
|
52
|
+
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'false'
|
|
53
|
+
? (this.isMultiplexed = false)
|
|
54
|
+
: (this.isMultiplexed = true);
|
|
55
|
+
// set the isMultiplexedPartitionedOps property to false if multiplexed session is disabled for paritioned ops, otherwise set the property to true
|
|
56
|
+
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'false' &&
|
|
57
|
+
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS ===
|
|
58
|
+
'false'
|
|
59
|
+
? (this.isMultiplexedPartitionOps = false)
|
|
60
|
+
: (this.isMultiplexedPartitionOps = true);
|
|
61
|
+
// set the isMultiplexedRW property to false if multiplexed session is disabled for read/write, otherwise set the property to true
|
|
62
|
+
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'false' &&
|
|
63
|
+
process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW === 'false'
|
|
64
|
+
? (this.isMultiplexedRW = false)
|
|
65
|
+
: (this.isMultiplexedRW = true);
|
|
66
|
+
// Regular sessions should only be created if mux is disabled.
|
|
67
|
+
if (!this.isMultiplexed) {
|
|
68
|
+
this.pool_.on('error', this.emit.bind(database, 'error'));
|
|
69
|
+
this.pool_.open();
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
/**
|
|
70
73
|
* Retrieves a session, either a regular session or a multiplexed session, based on the environment variable configuration.
|
|
71
74
|
*
|
|
72
|
-
* If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `
|
|
73
|
-
* retrieve a
|
|
75
|
+
* If the environment variable `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS` is set to `false`, the method will attempt to
|
|
76
|
+
* retrieve a regular session. Otherwise, it will return a multiplexed session.
|
|
74
77
|
*
|
|
75
78
|
* @param {GetSessionCallback} callback The callback function.
|
|
76
79
|
*/
|
|
@@ -82,12 +85,13 @@ class SessionFactory extends common.GrpcServiceObject {
|
|
|
82
85
|
}
|
|
83
86
|
/**
|
|
84
87
|
* Retrieves a session for partitioned operations, selecting the appropriate session type
|
|
85
|
-
* based on whether multiplexed sessions are
|
|
88
|
+
* based on whether multiplexed sessions are disabled or not.
|
|
86
89
|
*
|
|
87
|
-
* If multiplexed sessions are
|
|
88
|
-
* either a multiplexed session or a regular session based on the configuration.
|
|
90
|
+
* If multiplexed sessions are disabled for partitioned ops this methods delegates the request to `getSession()`, which returns
|
|
91
|
+
* either a multiplexed session or a regular session based on the env configuration.
|
|
89
92
|
*
|
|
90
|
-
* If the multiplexed sessions are disabled, a session
|
|
93
|
+
* If the multiplexed sessions are disabled, a session will get retrieved from the regular session pool.
|
|
94
|
+
* Otherwise a multiplexed session will be used.
|
|
91
95
|
*
|
|
92
96
|
* @param {GetSessionCallback} callback The callback function.
|
|
93
97
|
*/
|
|
@@ -100,10 +104,11 @@ class SessionFactory extends common.GrpcServiceObject {
|
|
|
100
104
|
* Retrieves a session for read write operations, selecting the appropriate session type
|
|
101
105
|
* based on whether multiplexed sessions are enabled.
|
|
102
106
|
*
|
|
103
|
-
* If multiplexed sessions are
|
|
104
|
-
* either a multiplexed session or a regular session based on the configuration.
|
|
107
|
+
* If multiplexed sessions are disabled for read write this methods delegates the request to `getSession()`, which returns
|
|
108
|
+
* either a multiplexed session or a regular session based on the env configuration.
|
|
105
109
|
*
|
|
106
|
-
* If the multiplexed sessions are disabled, a session
|
|
110
|
+
* If the multiplexed sessions are disabled, a session will get retrieved from the regular session pool.
|
|
111
|
+
* Otherise a multiplexed session will be used.
|
|
107
112
|
*
|
|
108
113
|
* @param {GetSessionCallback} callback The callback function.
|
|
109
114
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google-cloud/spanner",
|
|
3
3
|
"description": "Cloud Spanner Client Library for Node.js",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.3.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Google Inc.",
|
|
7
7
|
"engines": {
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"events-intercept": "^2.0.0",
|
|
77
77
|
"extend": "^3.0.2",
|
|
78
78
|
"google-auth-library": "^10.0.0-rc.1",
|
|
79
|
-
"google-gax": "5.0.
|
|
79
|
+
"google-gax": "5.0.4",
|
|
80
80
|
"grpc-gcp": "^1.0.1",
|
|
81
81
|
"lodash.snakecase": "^4.1.1",
|
|
82
82
|
"merge-stream": "^2.0.0",
|
|
@@ -108,7 +108,6 @@
|
|
|
108
108
|
"@types/request": "^2.48.12",
|
|
109
109
|
"@types/sinon": "^17.0.4",
|
|
110
110
|
"@types/through2": "^2.0.41",
|
|
111
|
-
"@types/uuid": "^10.0.0",
|
|
112
111
|
"binary-search-bounds": "^2.0.5",
|
|
113
112
|
"c8": "^10.1.3",
|
|
114
113
|
"codecov": "^3.8.3",
|
|
@@ -118,8 +117,8 @@
|
|
|
118
117
|
"gapic-tools": "^1.0.1",
|
|
119
118
|
"gts": "^6.0.2",
|
|
120
119
|
"jsdoc": "^4.0.4",
|
|
121
|
-
"jsdoc-fresh": "^
|
|
122
|
-
"jsdoc-region-tag": "^
|
|
120
|
+
"jsdoc-fresh": "^5.0.0",
|
|
121
|
+
"jsdoc-region-tag": "^4.0.0",
|
|
123
122
|
"linkinator": "^6.1.2",
|
|
124
123
|
"lodash.random": "^3.2.0",
|
|
125
124
|
"mocha": "^11.1.0",
|