@google-cloud/spanner 8.2.0 → 8.2.2
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 +20 -1
- package/build/protos/google/spanner/v1/keys.proto +2 -2
- package/build/protos/google/spanner/v1/mutation.proto +31 -23
- package/build/protos/google/spanner/v1/query_plan.proto +21 -18
- package/build/protos/google/spanner/v1/spanner.proto +198 -204
- package/build/protos/google/spanner/v1/transaction.proto +3 -2
- package/build/protos/protos.json +3 -1
- package/build/src/index.d.ts +1 -0
- package/build/src/index.js +32 -12
- package/build/src/metrics/interceptor.js +10 -2
- 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/v1/spanner_client.d.ts +155 -159
- package/build/src/v1/spanner_client.js +47 -52
- package/package.json +2 -2
|
@@ -166,8 +166,9 @@ message TransactionOptions {
|
|
|
166
166
|
// actually occurred in parallel. Spanner assigns commit timestamps that
|
|
167
167
|
// reflect the order of committed transactions to implement this property.
|
|
168
168
|
// Spanner offers a stronger guarantee than serializability called external
|
|
169
|
-
// consistency. For
|
|
170
|
-
//
|
|
169
|
+
// consistency. For more information, see
|
|
170
|
+
// [TrueTime and external
|
|
171
|
+
// consistency](https://cloud.google.com/spanner/docs/true-time-external-consistency#serializability).
|
|
171
172
|
SERIALIZABLE = 1;
|
|
172
173
|
|
|
173
174
|
// All reads performed during the transaction observe a consistent snapshot
|
package/build/protos/protos.json
CHANGED
|
@@ -8263,7 +8263,9 @@
|
|
|
8263
8263
|
"Session": {
|
|
8264
8264
|
"options": {
|
|
8265
8265
|
"(google.api.resource).type": "spanner.googleapis.com/Session",
|
|
8266
|
-
"(google.api.resource).pattern": "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}"
|
|
8266
|
+
"(google.api.resource).pattern": "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}",
|
|
8267
|
+
"(google.api.resource).plural": "sessions",
|
|
8268
|
+
"(google.api.resource).singular": "session"
|
|
8267
8269
|
},
|
|
8268
8270
|
"fields": {
|
|
8269
8271
|
"name": {
|
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;
|
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;
|
|
@@ -305,6 +306,7 @@ class Spanner extends service_1.GrpcService {
|
|
|
305
306
|
(0, instrument_1.ensureInitialContextManagerSet)();
|
|
306
307
|
this._nthClientId = (0, request_id_header_1.nextSpannerClientId)();
|
|
307
308
|
this._universeDomain = universeEndpoint;
|
|
309
|
+
this.projectId_ = options.projectId;
|
|
308
310
|
this.configureMetrics_(options.disableBuiltInMetrics);
|
|
309
311
|
}
|
|
310
312
|
get universeDomain() {
|
|
@@ -761,18 +763,36 @@ 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
|
+
}
|
|
776
796
|
}
|
|
777
797
|
}
|
|
778
798
|
/**
|
|
@@ -898,9 +918,9 @@ class Spanner extends service_1.GrpcService {
|
|
|
898
918
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
899
919
|
request(config, callback) {
|
|
900
920
|
let metricsTracer = null;
|
|
901
|
-
if (config.client === 'SpannerClient') {
|
|
921
|
+
if (config.client === 'SpannerClient' && this.projectId_) {
|
|
902
922
|
metricsTracer =
|
|
903
|
-
metrics_tracer_factory_1.MetricsTracerFactory?.getInstance()?.createMetricsTracer(config.method, config.reqOpts.session ?? config.reqOpts.database, config.headers['x-goog-spanner-request-id']) ?? null;
|
|
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;
|
|
904
924
|
}
|
|
905
925
|
metricsTracer?.recordOperationStart();
|
|
906
926
|
if (typeof callback === 'function') {
|
|
@@ -961,9 +981,9 @@ class Spanner extends service_1.GrpcService {
|
|
|
961
981
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
962
982
|
requestStream(config) {
|
|
963
983
|
let metricsTracer = null;
|
|
964
|
-
if (config.client === 'SpannerClient') {
|
|
984
|
+
if (config.client === 'SpannerClient' && this.projectId_) {
|
|
965
985
|
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;
|
|
986
|
+
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
987
|
}
|
|
968
988
|
metricsTracer?.recordOperationStart();
|
|
969
989
|
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();
|
|
@@ -66,7 +72,9 @@ const MetricInterceptor = (options, nextCall) => {
|
|
|
66
72
|
metricsTracer?.recordAfeLatency(status.code);
|
|
67
73
|
}
|
|
68
74
|
else {
|
|
69
|
-
|
|
75
|
+
// Disable afe_connectivity_error_count metric as AFE header is disabled in backend
|
|
76
|
+
// currently.
|
|
77
|
+
// metricsTracer?.recordAfeConnectivityErrorCount(status.code);
|
|
70
78
|
}
|
|
71
79
|
},
|
|
72
80
|
};
|
|
@@ -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;
|