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: Parse Host Service Name #2300

Merged
merged 14 commits into from Dec 18, 2023
Merged

feat: Parse Host Service Name #2300

merged 14 commits into from Dec 18, 2023

Conversation

lqiu96
Copy link
Contributor

@lqiu96 lqiu96 commented Dec 11, 2023

Changes:
Generator parses the Default Host value to get the Host Service Name. The parsed value is passed to the {Service}StubSettings and then passed to the EndpointContext.

HostServiceName is either set to be package-private scope or marked with @InternalApi as it's meant for usage by GAPIC clients.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Dec 11, 2023
@lqiu96 lqiu96 added the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 11, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 11, 2023
@lqiu96 lqiu96 requested a review from blakeli0 December 11, 2023 22:46
@lqiu96 lqiu96 marked this pull request as ready for review December 11, 2023 22:46
@lqiu96 lqiu96 requested a review from a team as a code owner December 11, 2023 22:46
@@ -100,6 +100,10 @@ public abstract class ClientContext {
@Nonnull
public abstract Duration getStreamWatchdogCheckInterval();

// Package-Private scope for internal use only. Shared between StubSettings and ClientContext
@Nullable
abstract String getHostServiceName();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we call this field serviceName in Gax and generated stubs? It makes sense to call ithostServiceName in the generator as serviceName could be confused with Service.name(), but in Gax I think it makes more sense to just call it serviceName.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll rename to serviceName.

@@ -52,6 +52,12 @@ public boolean hasDescription() {
return !Strings.isNullOrEmpty(description());
}

public String hostServiceName() {
// Default Host is guaranteed to exist and be non-null and non-empty
Copy link
Collaborator

Choose a reason for hiding this comment

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

I remember we discussed that the service name could come from the proto or service yaml, is that still true? Or service name will always come from defaultHost in the proto?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, comment is misleading. I meant to write that the hostServiceName is guaranteed as the generator won't generate a library if it doesn't exist.

I remember we discussed that the service name could come from the proto or service yaml, is that still true?

It is still true. Checks the proto's default_host value first, then the service yaml file, and fails otherwise

// This meant to be used internally by GAPIC clients to configure an endpoint.
// Users should avoid settings this as it could change their endpoint.
@InternalApi
public B setHostServiceName(String hostServiceName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have to expose a setter for it? Since the host service name is a fixed String, I think we should implement it in a similar way as the to-be-deprecated default endpoint, that we generate a getter that returns the default host service name.

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 see, I think that makes sense. I'll update it.

Comment on lines +143 to +148
// Intended for Internal Use and Overriden by generated ServiceStubSettings classes.
// Meant to be shared between StubSettings and ClientContext.
@InternalApi
public String getServiceName() {
return "";
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ClientContext.create() takes in the root StubSettings (not the subclasses). Create a default method that generated subclasses can override.

// or service yaml file. For Google Cloud Services, the default host value
// is expected to contain `.googleapis.com`. Exceptions may exist (i.e. localhost),
// in which case we will return an empty string.
private static String parseHostServiceName(String defaultHost) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know we are already testing this method indirectly through golden tests. Since this is in Service not composers, and we can easily mock the input, it would be great if we can have unit tests testing it directly as well.

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 some tests for parsing, thanks!

Copy link

sonarcloud bot commented Dec 18, 2023

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions

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

See analysis details on SonarCloud

Copy link

sonarcloud bot commented Dec 18, 2023

Quality Gate Passed Quality Gate passed for 'java_showcase_integration_tests'

Kudos, no new issues were introduced!

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

See analysis details on SonarCloud

@lqiu96 lqiu96 merged commit 8822f3b into main Dec 18, 2023
34 of 37 checks passed
@lqiu96 lqiu96 deleted the parse-hostServiceName branch December 18, 2023 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants