diff --git a/src/request_id_header.ts b/src/request_id_header.ts index d4259d0b3..34ca0ca21 100644 --- a/src/request_id_header.ts +++ b/src/request_id_header.ts @@ -88,8 +88,6 @@ function newAtomicCounter(n?: number): AtomicCounter { return new AtomicCounter(n); } -const X_GOOG_REQ_ID_REGEX = /(\d+\.){5}\d+/; - interface withHeaders { headers: {[k: string]: string}; } @@ -189,8 +187,11 @@ export interface RequestIDError extends grpc.ServiceError { requestID: string; } +const X_GOOG_REQ_ID_REGEX = /^1\.[0-9A-Fa-f]{8}(\.\d+){3}\.\d+/; + export { AtomicCounter, + X_GOOG_REQ_ID_REGEX, X_GOOG_SPANNER_REQUEST_ID_HEADER, craftRequestId, injectRequestIDIntoError, diff --git a/test/gapic_spanner_v1.ts b/test/gapic_spanner_v1.ts index 3b63c6909..3605e6c66 100644 --- a/test/gapic_spanner_v1.ts +++ b/test/gapic_spanner_v1.ts @@ -26,6 +26,10 @@ import * as spannerModule from '../src'; import {PassThrough} from 'stream'; import {protobuf} from 'google-gax'; +import { + X_GOOG_REQ_ID_REGEX, + X_GOOG_SPANNER_REQUEST_ID_HEADER, +} from '../src/request_id_header'; // Dynamically loaded proto JSON is needed to get the type information // to fill in default values for request objects @@ -486,9 +490,9 @@ describe('v1.SpannerClient', () => { ).getCall(0).args[1].otherArgs.headers; const actualHeaderRequestParams = actualHeaders['x-goog-request-params']; assert(actualHeaderRequestParams.includes(expectedHeaderRequestParams)); - // const actualRequestID = actualHeaders['x-goog-spanner-request-id']; - // console.log('headers', actualHeaders); - // assert.deepStrictEqual(actualRequestID, 'foo'); + // const actualRequestID = actualHeaders[X_GOOG_SPANNER_REQUEST_ID_HEADER]; + // console.log(`headers ${JSON.stringify(actualHeaders)}`); + // assert.deepStrictEqual(actualRequestID!.match(X_GOOG_REQ_ID_REGEX) !== null, true); }); it('invokes batchCreateSessions without error using callback', async () => { diff --git a/test/spanner.ts b/test/spanner.ts index 0199f6cf6..dce92ade7 100644 --- a/test/spanner.ts +++ b/test/spanner.ts @@ -59,6 +59,8 @@ import { } from '../src/common'; import { RequestIDError, + X_GOOG_REQ_ID_REGEX, + X_GOOG_SPANNER_REQUEST_ID_HEADER, randIdForProcess, resetNthClientId, } from '../src/request_id_header'; @@ -74,7 +76,6 @@ import Priority = google.spanner.v1.RequestOptions.Priority; import TypeCode = google.spanner.v1.TypeCode; import NullValue = google.protobuf.NullValue; import {SessionFactory} from '../src/session-factory'; -import {X_GOOG_SPANNER_REQUEST_ID_HEADER} from '../src/request_id_header'; const { AlwaysOnSampler, @@ -313,7 +314,6 @@ describe('Spanner with mock server', () => { servicePath: 'localhost', port, sslCreds: grpc.credentials.createInsecure(), - // interceptors: [xGoogReqIDInterceptor.generateLoggingClientInterceptor()], }); // Gets a reference to a Cloud Spanner instance and database instance = spanner.instance('instance'); @@ -2748,7 +2748,7 @@ describe('Spanner with mock server', () => { `${grpc.status.NOT_FOUND} NOT_FOUND: ${fooNotFoundErr.message}` ); assert.deepStrictEqual( - (e as RequestIDError).requestID.match(requestIDRegex) != null, + (e as RequestIDError).requestID.match(requestIDRegex) !== null, true ); } @@ -2796,7 +2796,7 @@ describe('Spanner with mock server', () => { `${grpc.status.NOT_FOUND} NOT_FOUND: ${fooNotFoundErr.message}` ); assert.deepStrictEqual( - (e as RequestIDError).requestID.match(requestIDRegex) != null, + (e as RequestIDError).requestID.match(requestIDRegex) !== null, true ); } @@ -2877,7 +2877,6 @@ describe('Spanner with mock server', () => { (e as ServiceError).message, 'No resources available.' ); - // assert.deepStrictEqual((e as RequestIDError).requestID,`1.${randIdForProcess}.1.1.1.1`); } } finally { if (tx1) { @@ -2952,7 +2951,6 @@ describe('Spanner with mock server', () => { assert.fail('missing expected error'); } catch (err) { assert.strictEqual((err as ServiceError).code, Status.NOT_FOUND); - // assert.deepStrictEqual((err as RequestIDError).requestID,`1.${randIdForProcess}.1.1.1.1`); } finally { await database.close(); } @@ -3014,7 +3012,6 @@ describe('Spanner with mock server', () => { (err as ServiceError).code, Status.PERMISSION_DENIED ); - // assert.deepStrictEqual((err as RequestIDError).requestID,`1.${randIdForProcess}.1.1.1.1`); } finally { await database.close(); } @@ -5440,5 +5437,3 @@ function getRowCountFromStreamingSql( function sleep(ms): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } - -const X_GOOG_REQ_ID_REGEX = /^1\.[0-9A-Fa-f]{8}(\.\d+){3}\.\d+/;