@google-cloud/spanner 8.2.2 → 8.3.1

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 CHANGED
@@ -80,14 +80,38 @@ 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
- Spanner's Multiplexed Sessions can now be used as an efficient alternative to the default session pool. This feature helps reduce
86
- session management overhead and minimize session-related errors. Multiplexed sessions can be enabled for all transaction types via environment variables.
107
+ Spanner's Multiplexed Sessions is now default enabled session mode in node client. This feature helps reduce
108
+ session management overhead and minimize session-related errors.
109
+
110
+ For a detailed explanation on multiplexed sessions, please refer to the [official documentation](https://cloud.google.com/spanner/docs/sessions#multiplexed_sessions).
87
111
 
88
- ### Configuration
112
+ ## Regular Sessions
89
113
 
90
- To enable this feature, set the following environment variables to `true`:
114
+ To use regular sessions, disable the multiplexed sessions and set the following environment variables to `false`:
91
115
 
92
116
  * **For Read-Only Transactions:**
93
117
  - `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS`
@@ -98,7 +122,7 @@ To enable this feature, set the following environment variables to `true`:
98
122
  - `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS`
99
123
  - `GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW`
100
124
 
101
- For a detailed explanation of this feature, please refer to the [official documentation](https://cloud.google.com/spanner/docs/sessions#multiplexed_sessions).
125
+ For a detailed explanation on session modes and env configurations, please refer to the [official documentation](https://cloud.google.com/spanner/docs/sessions).
102
126
 
103
127
 
104
128
  ## Samples
@@ -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
 
@@ -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
 
@@ -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
 
@@ -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,
@@ -241,8 +241,7 @@ class Spanner extends service_1.GrpcService {
241
241
  libVersion: require('../../package.json').version,
242
242
  scopes,
243
243
  // Add grpc keep alive setting
244
- 'grpc.keepalive_time_ms': 30000,
245
- 'grpc.keepalive_timeout_ms': 10000,
244
+ 'grpc.keepalive_time_ms': 120000,
246
245
  // Enable grpc-gcp support
247
246
  'grpc.callInvocationTransformer': grpcGcp.gcpCallInvocationTransformer,
248
247
  'grpc.channelFactoryOverride': grpcGcp.gcpChannelFactoryOverride,
@@ -920,7 +919,7 @@ class Spanner extends service_1.GrpcService {
920
919
  let metricsTracer = null;
921
920
  if (config.client === 'SpannerClient' && this.projectId_) {
922
921
  metricsTracer =
923
- 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;
922
+ 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;
924
923
  }
925
924
  metricsTracer?.recordOperationStart();
926
925
  if (typeof callback === 'function') {
@@ -83,7 +83,7 @@ class MultiplexedSession extends events_1.EventEmitter {
83
83
  multiplexed: true,
84
84
  });
85
85
  this._multiplexedSession = createSessionResponse;
86
- span.addEvent(`Created multiplexed session ${this._multiplexedSession.id}`);
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 `true`, the method will attempt to
105
- * retrieve a multiplexed session. Otherwise, it will retrieve a session from the regular pool.
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 enabled.
112
+ * based on whether multiplexed sessions are disabled or not.
113
113
  *
114
- * If multiplexed sessions are enabled for partitioned ops this methods delegates the request to `getSession()`, which returns
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 is retrieved from the regular session pool.
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 enabled for read write this methods delegates the request to `getSession()`, which returns
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 is retrieved from the regular session pool.
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
- // set the isMultiplexed property to true if multiplexed session is enabled, otherwise set the property to false
52
- process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'true'
53
- ? (this.isMultiplexed = true)
54
- : (this.isMultiplexed = false);
55
- // set the isMultiplexedPartitionedOps property to true if multiplexed session is enabled for paritioned ops, otherwise set the property to false
56
- this.isMultiplexedPartitionOps =
57
- process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'true' &&
58
- process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_PARTITIONED_OPS ===
59
- 'true';
60
- this.isMultiplexedRW =
61
- process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS === 'true' &&
62
- process.env.GOOGLE_CLOUD_SPANNER_MULTIPLEXED_SESSIONS_FOR_RW === 'true';
63
- // Multiplexed sessions should only be created if its enabled.
64
- if (this.isMultiplexed) {
65
- this.multiplexedSession_.on('error', this.emit.bind(database, 'error'));
66
- this.multiplexedSession_.createSession();
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 `true`, the method will attempt to
73
- * retrieve a multiplexed session. Otherwise, it will retrieve a session from the regular pool.
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 enabled.
88
+ * based on whether multiplexed sessions are disabled or not.
86
89
  *
87
- * If multiplexed sessions are enabled for partitioned ops this methods delegates the request to `getSession()`, which returns
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 is retrieved from the regular session pool.
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 enabled for read write this methods delegates the request to `getSession()`, which returns
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 is retrieved from the regular session pool.
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.2.2",
4
+ "version": "8.3.1",
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.3",
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": "^4.0.0",
122
- "jsdoc-region-tag": "^3.0.0",
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",