Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions handwritten/spanner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
>;
observabilityOptions?: ObservabilityOptions;
disableBuiltInMetrics?: boolean;
interceptors?: any[];

Check warning on line 184 in handwritten/spanner/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
sessionLabels?: {[key: string]: string};
/**
* The Trusted Cloud Domain (TPC) DNS of the service used to make requests.
Expand Down Expand Up @@ -524,10 +524,7 @@

this._isInSecureCredentials = options.sslCreds?._isSecure() === false;
this.options = options;
this.auth =
options.auth instanceof GoogleAuth
? options.auth
: new GoogleAuth(this.options);
this.auth = new GoogleAuth(this.options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for splitting this out, but after reviewing this alongside #9981 and #10000, I don't think we should merge #9995:

  1. Reverting this.auth back to new GoogleAuth(this.options) restores the pre-9.1.1 split-brain situation: SpannerOptions (via GrpcClientOptions) still exposes options.auth and the underlying v1 GAPIC clients (SpannerClient, InstanceAdminClient, DatabaseAdminClient) still use it, while Spanner.auth (getProjectId()) and built-in metrics silently ignore options.auth and fall back to ambient ADC. Also, if the goal of fix(spanner): revert sharing caller-provided GoogleAuth from #9957 #9995 was to make a behavior change from 9.1.1 clear in the release notes, the current PR title/description does not clearly communicate what changed for callers or what to use instead.
  2. More importantly, fix(spanner): revert sharing caller-provided GoogleAuth from #9957 #9995 is not needed at all. Instead, we should close fix(spanner): revert sharing caller-provided GoogleAuth from #9957 #9995 and handle this in fix(spanner): scope metrics auth to monitoring.write and isolate authClient #9981 along the lines of my review comment: keep options.auth working on Spanner.auth (ideally with a structural check rather than instanceof GoogleAuth), and have _createMetricsAuth() derive a fresh, monitoring.write-scoped GoogleAuth from options.auth's credential source (jsonContent, keyFilename, cloned JWT authClient, and clientOptions) without sharing or mutating the caller's GoogleAuth instance, backed by an unmocked test in test/metrics/spanner-metrics-exporter.ts.
  3. Combining fix(spanner): fix universeDomain validation and default endpoint metrics #10000 with that update to fix(spanner): scope metrics auth to monitoring.write and isolate authClient #9981 will ensure there is no regression for anyone using 9.1.1, prevents built-in metrics from falling back to ambient ADC, and ensures options.auth is used by the Spanner client in a way that is consistent with google-auth-library (where credentials and keyFilename are now deprecated in favor of options.auth).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes total sense — closing #9995 and updated #9981 to keep options.auth on Spanner.auth (with a structural check) and derive a fresh monitoring.write-scoped GoogleAuth from its credential source in _createMetricsAuth() with unmocked RSA tests.

this.clients_ = new Map();
this.instances_ = new Map();
this.instanceConfigs_ = new Map();
Expand Down Expand Up @@ -653,8 +650,8 @@
if (callback) {
// process.nextTick prevents Unhandled Promise Rejections if callback throws
res
.then(() => process.nextTick(() => callback(null)))

Check warning on line 653 in handwritten/spanner/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
.catch(err => process.nextTick(() => callback(err)));

Check warning on line 654 in handwritten/spanner/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid calling back inside of a promise
return;
}
return res;
Expand Down Expand Up @@ -1926,7 +1923,7 @@
if (!this.clients_.has(clientName)) {
this.clients_.set(
clientName,
new (v1 as Record<string, any>)[clientName](this.options),

Check warning on line 1926 in handwritten/spanner/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
);
}
const gaxClient = this.clients_.get(clientName)!;
Expand Down Expand Up @@ -2224,7 +2221,7 @@
try {
const result = requestFn();
if (result && typeof result.then === 'function') {
result

Check warning on line 2224 in handwritten/spanner/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid using promises inside of callbacks

Check warning on line 2224 in handwritten/spanner/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Avoid using promises inside of callbacks
.then(val => {
metricsTracer?.recordOperationCompletion();
resolve(val);
Expand Down
10 changes: 7 additions & 3 deletions handwritten/spanner/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
it('should disable channelz by default and allow overriding it', () => {
const spannerDefault = new Spanner(OPTIONS);
assert.strictEqual(
(spannerDefault.options as any)['grpc.enable_channelz'],

Check warning on line 351 in handwritten/spanner/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
0,
);

Expand All @@ -356,7 +356,7 @@
Object.assign({}, OPTIONS, {'grpc.enable_channelz': 1}),
);
assert.strictEqual(
(spannerEnabled.options as any)['grpc.enable_channelz'],

Check warning on line 359 in handwritten/spanner/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
1,
);
});
Expand Down Expand Up @@ -399,7 +399,7 @@

it('should configure metrics if project Id is not passed', async () => {
await enableMetrics(sandbox);
const spanner = new Spanner();

Check warning on line 402 in handwritten/spanner/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

'spanner' is assigned a value but never used
assert.strictEqual(MetricsTracerFactory.enabled, true);
await disableMetrics(sandbox);
});
Expand Down Expand Up @@ -624,7 +624,7 @@
);

try {
const spanner = new Spanner(fakeOption);

Check warning on line 627 in handwritten/spanner/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

'spanner' is assigned a value but never used
// this line should never reach client must throw an error.
throw new Error('should never reach this line');
} catch (err) {
Expand Down Expand Up @@ -678,11 +678,15 @@
}
});

it('should reuse a caller-provided GoogleAuth instance', () => {
it('should not share a caller-provided GoogleAuth instance with Spanner.auth or metrics exporter', () => {
const callerAuth = Object.create(fakeGoogleAuth.prototype);
callerAuth.getProjectId = cb => cb && cb(null, 'caller-project');
const clientWithCallerAuth = new Spanner(asAny({auth: callerAuth}));
assert.strictEqual(clientWithCallerAuth.auth, callerAuth);
const clientWithCallerAuth = new Spanner(
asAny({projectId: 'caller-project', auth: callerAuth}),
);
assert.notStrictEqual(clientWithCallerAuth.auth, callerAuth);
assert.strictEqual(recordedExporterCalls.length, 1);
assert.notStrictEqual(recordedExporterCalls[0].options.auth, callerAuth);
assert.notStrictEqual(new Spanner().auth, callerAuth);
});

Expand Down
Loading