Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: Use the universe domain if it is provided by the user #1563

Merged
merged 27 commits into from
Jan 22, 2025

Conversation

danieljbruce
Copy link
Contributor

@danieljbruce danieljbruce commented Jan 8, 2025

Summary:

The user should be able to set the universe domain so that outgoing calls work with a different Google Cloud Universe. Right now, if the user specifies a universe domain then it will not get used and the request will just be sent to the default Bigtable endpoint.

Changes:

src/index.ts: The change here is that when a custom url is not provided, but a universe domain is provided then the servicePath will use the universe domain provided. This is done for each Gapic client and ensures requests will be made to the universe domain instead of the default Bigtable service.

system-test/service-path.ts: Two tests are added to ensure the service path is always set correctly. For instance, when a custom endpoint is provided then the service path will still always be that custom endpoint. When a custom endpoint is NOT provided, but a universe domain is provided then the service path is set to use the universe domain instead of the default endpoint.

Alternatives:

  1. Instead of requiring the user to set the universe domain for each Gapic client, we could expose a universeDomain option that would apply to all clients. While this would make things easier for users, it is an API change so it is not reversible. For now we should not change the API since users already have a way to specify the universe domains for the Gapic clients. We can always add this option later.
  2. When a custom endpoint is not provided then in the handwritten layer we could not provide a service path. The Pros of this option is that we can rely on the code in the Gapic layer for building the service path instead of creating the getDomain function introducing duplicate code and this would reduce technical debt. The main problem with this option is that it means providedCustomServicePath will now be undefined and this value is used in the grpc stub so we don't know how such a change might affect the outgoing API calls. The code to implement this alternative also gets messy if Alternative 1 isn't adopted as well.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigtable Issues related to the googleapis/nodejs-bigtable API. labels Jan 8, 2025
@danieljbruce danieljbruce marked this pull request as ready for review January 8, 2025 21:59
@danieljbruce danieljbruce requested review from a team as code owners January 8, 2025 21:59
src/index.ts Outdated
servicePath: customEndpointBaseUrl || defaultAdminBaseUrl,
servicePath:
customEndpointBaseUrl ||
`bigtableadmin.${getDomain(options.BigtableTableAdminClient)}`,
Copy link
Contributor Author

@danieljbruce danieljbruce Jan 10, 2025

Choose a reason for hiding this comment

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

If no universe domain and custom endpoint is provided then this will still be bigtableadmin.googleapis.com.

src/index.ts Outdated
servicePath: customEndpointBaseUrl || defaultBaseUrl,
servicePath:
customEndpointBaseUrl ||
`bigtable.${getDomain(options.BigtableClient)}`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If no universe domain and custom endpoint is provided then this will still be bigtable.googleapis.com.

Copy link

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, with a few small comments.

I'm not too familiar with the universe domains yet though, so you might also want to assign a reviewer who understands potential complications there

* @returns {string} The universe domain.
*/
function getDomain(opts?: gax.ClientOptions) {
// This code for universe domain was taken from the Gapic Layer.

Choose a reason for hiding this comment

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

can you add a permalink to where this came from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

src/index.ts Outdated
servicePath: customEndpointBaseUrl || defaultBaseUrl,
servicePath:
customEndpointBaseUrl ||
`bigtable.${getDomain(options.BigtableClient)}`,
Copy link

@daniel-sanche daniel-sanche Jan 10, 2025

Choose a reason for hiding this comment

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

What would you think about adding pathPrefix as an argument to getDomain (and maybe renaming the method if needed), instead of manually building the string here? I think that would be a bit easier to read, and seems more natural to me since the returned string isn't useful on its own

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. That would be fine.

@danieljbruce danieljbruce requested a review from bshaffer January 10, 2025 21:20
Copy link

@bshaffer bshaffer left a comment

Choose a reason for hiding this comment

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

This looks good - a few test suggestions and questions, but otherwise LGTM

Comment on lines +121 to +122
opts?.universeDomain ??
opts?.universe_domain ??

Choose a reason for hiding this comment

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

Is this a nodeJS convention to support both casings? AFAIK this is not the case in any other language implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is code is taken from here. I suggest we leave it as is because this is just Gapic code, but if you have an exact suggestion then maybe I could try that as well?

Choose a reason for hiding this comment

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

In the JSON file, it's defined as universe_domain. I don't have a exact suggestion other than to say since the language agnostic spec doesn't require both casings, it must be specific to NodeJS.

According to #1386, that's how support was added for all GAPICs, so LGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Thanks for looking into that.

TestSampleRowKeys_Generic_CloseClient\|
TestSampleRowKeys_Generic_Headers\|
TestSampleRowKeys_NoRetry_NoEmptyKey\|
TestSampleRowKeys_Retry_WithRetryInfo

Choose a reason for hiding this comment

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

Why are these part of this PR? These tests shouldn't be affected as a result of these changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These needed to be added because suddenly conformance tests started failing for sampleRowKeys. This is most likely because new tests were recently added to the test runner.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd pull these out of the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These have been pulled out.

import {BigtableClient, BigtableInstanceAdminClient} from '../src/v2';

describe('Service Path', () => {
it('Setting universe domain should set the service path', async () => {

Choose a reason for hiding this comment

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

I would suggest also

  1. adding a test for when the universe domain ENV VAR is set.
  2. setting the ENV VAR in the other two tests as well, which will ensure that it's not used when the universeDomain and apiEndpoint options are set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I'll do that next.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@danieljbruce danieljbruce added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 22, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jan 22, 2025
@danieljbruce danieljbruce added the automerge Merge the pull request once unit tests and other checks pass. label Jan 22, 2025
@gcf-merge-on-green gcf-merge-on-green bot merged commit d26ecb8 into main Jan 22, 2025
21 of 25 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Jan 22, 2025
@gcf-merge-on-green gcf-merge-on-green bot deleted the universe-domain-2 branch January 22, 2025 19:56
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
api: bigtable Issues related to the googleapis/nodejs-bigtable API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants