Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Add Universe Domain to Java-Core #2329

Merged
merged 24 commits into from Jan 4, 2024
Merged

Conversation

lqiu96
Copy link
Contributor

@lqiu96 lqiu96 commented Jan 2, 2024

Google Auth Library v1.21.0 has been released.

ServiceOptions exposes Getters and Setters for Universe Domain. There is a helper method to resolve the endpoint and to validate the universe domain.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Jan 2, 2024
@@ -767,4 +794,40 @@ public String getClientLibToken() {
public String getQuotaProjectId() {
return quotaProjectId;
}

/** Returns the resolved endpoint for the Service to connect to Google Cloud */
public String getResolvedEndpoint(String serviceName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think host in java-core is basically endpoint in Gax without the port, based on the value of DEFAULT_HOST. So we should either rename this to getResolvedHost and remove the port concatenation in formatEndpoint, or return host:port if host is specified.
Can you please verify the format of host?

Copy link
Contributor Author

@lqiu96 lqiu96 Jan 3, 2024

Choose a reason for hiding this comment

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

I think the format of host is intended to be scheme://host:port. For gRPC, the channel is expecting something in format of domain:port and httpjson is open to anything valid.

I see that the handwritten libraries handle these inside their own codebase:

  1. Storage gRPC (strips the scheme and adds a port if missing): https://github.com/googleapis/java-storage/blob/2b5b27eac3279db815b36b252830d0905ade0665/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java#L163-L170
  2. Storage HttpJson (sets it directly): https://github.com/googleapis/java-storage/blob/2b5b27eac3279db815b36b252830d0905ade0665/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java#L143
  3. Spanner (enforces that a port exists): https://github.com/googleapis/java-spanner/blob/21f5eba7d46c9011803accf0aaf87e6072066419/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java#L1469-L1471
  4. Bigquery (sets it directly): https://github.com/googleapis/java-bigquery/blob/7a1bbd2d33e71644d83c42b71c67bac099882a4a/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/spi/v2/HttpBigQueryRpc.java#L108

I think it should be that the gRPC clients use getResolvedEndpoint() and expect something in the format host:port. Apiary clients (httpjson) will use getResolvedApiaryEndpoint() and that will return the just the host.

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Jan 3, 2024
@lqiu96 lqiu96 marked this pull request as ready for review January 3, 2024 22:31
@lqiu96 lqiu96 requested a review from a team as a code owner January 3, 2024 22:31
@lqiu96 lqiu96 added the owlbot:run Add this label to trigger the Owlbot post processor. label Jan 3, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jan 3, 2024
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Jan 4, 2024
Comment on lines 802 to 803
if (universeDomain != null && universeDomain.isEmpty()) {
throw new IllegalArgumentException("Universe Domain cannot be empty");
Copy link
Member

Choose a reason for hiding this comment

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

I felt it's wrong a method that "Returns the resolved endpoint for the Service to connect to Google Cloud" works only when universeDomain is set.

Copy link
Contributor Author

@lqiu96 lqiu96 Jan 4, 2024

Choose a reason for hiding this comment

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

This is a required check. If universedomain is set as "", we must error out. If universeDomain is null, the resolvedUniverseDomain will be googleapis.com. Otherwise, the resolvedUniverseDomain will be whatever is inputted.

Copy link
Member

Choose a reason for hiding this comment

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

I misunderstood the meaning of the code. Added suggested edits.

Copy link
Member

Choose a reason for hiding this comment

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

Then how about setting the requirement in setUniverseDomain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that makes sense. Guidance for temporary Apiary is to use whatever is passed in as the universe domain. The empty check is for handwritten and gapics. I'll ask about the empty string check, but it shouldn't be blocking for this.


/**
* Temporarily used for BigQuery and Storage Apiary Wrapped Libraries. To be removed in the
* future. Returns the host to be used as the rootUrl.
Copy link
Member

Choose a reason for hiding this comment

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

I believe rootUrl is not a generic term but specific to our code. Can you add a link to rootUrl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, will add.

/**
* Returns the resolved host for the Service to connect to Google Cloud
*
* <p>The resolved host will be in `https://www.{serviceName}.{resolvedUniverseDomain}/` format.
Copy link
Member

@suztomo suztomo Jan 4, 2024

Choose a reason for hiding this comment

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

Would you add a reference about adding "www." (Javadoc's @see annotation)? I checked www.speech.googleapis.com but it (the DNS entry) does not exist.

suztomo@suztomo2:~$ ping www.speech.googleapis.com
ping: www.speech.googleapis.com: Name or service not known

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a link to DEFAULT_HOST

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 works for cloudkms.googleapis.com not sure why there is an issue for speech.googleapis.com

Copy link
Collaborator

@blakeli0 blakeli0 left a comment

Choose a reason for hiding this comment

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

LGTM. Please resolve outstanding comments before merging.

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Jan 4, 2024
@lqiu96 lqiu96 added the owlbot:run Add this label to trigger the Owlbot post processor. label Jan 4, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jan 4, 2024
@lqiu96 lqiu96 added the owlbot:run Add this label to trigger the Owlbot post processor. label Jan 4, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jan 4, 2024
Copy link

sonarcloud bot commented Jan 4, 2024

Quality Gate Passed Quality Gate passed for 'gapic-generator-java-root'

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
96.3% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

sonarcloud bot commented Jan 4, 2024

Quality Gate Failed Quality Gate failed for 'java_showcase_integration_tests'

Failed conditions

0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

* href="https://github.com/googleapis/sdk-platform-java/blob/097964f24fa1989bc74b4807a253f0be4e9dd1ea/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java#L85">DEFAULT_HOST</a>
*/
@InternalApi
public String getResolvedHost(String serviceName) {
Copy link
Member

Choose a reason for hiding this comment

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

Calling it as host is itchy. Fine but ensure to explain this to library owners.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/URL.html#getHost()

@lqiu96 lqiu96 merged commit 586ac9f into main Jan 4, 2024
38 of 39 checks passed
@lqiu96 lqiu96 deleted the java-core-universe_domain branch January 4, 2024 19:59
lqiu96 added a commit that referenced this pull request Jan 5, 2024
* feat: Add Java-Core Universe Domain changes

* chore: Move validate universe domain logic to ServiceOptions

* chore: Add javadocs

* chore: Add tests

* chore: Fix lint issues

* chore: Add project id to tests

* chore: Fix format issues

* chore: Address PR comments

* chore: Update Apiary to return rootHostUrl

* chore: Use Google Auth Library v1.21.0

* chore: Add tests for normalizeEndpoint()

* chore: Address PR comments

* chore: Address PR comments

* chore: Fix comments

* chore: Address PR comments

* chore: Address PR comments

* chore: Add links

* chore: Add format to match DEFAULT_HOST

* chore: Fix failing tests

* chore: Update javadocs

* chore: Remove www. prefix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants