-
Notifications
You must be signed in to change notification settings - Fork 330
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 support for rest-only services in generator #1849
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In java-compute, newBuilder(), defaultTransportChannelProvider(), and defaultApiClientHeaderProviderBuilder() all default to REST implementation
This is good to know but also surprising, because it means if we change a REST
only client to GRPC+REST
, it would be a breaking change.
.../src/main/java/com/google/cloud/generator/spring/composer/SpringAutoConfigClassComposer.java
Outdated
Show resolved
Hide resolved
...oud-generator/src/test/java/com/google/cloud/generator/spring/utils/RestTestProtoLoader.java
Outdated
Show resolved
Hide resolved
Not part of this PR, I wonder if it makes sense to regenerate the auto configs as part of the CI if we have changes in SpringCodeGen, so that we can see the changes directly in the same PR. |
@blakeli0 This suggestion actually makes me wonder - what would be the preferred timing to push any generated code changes introduced by changes to the generator? Currently I see the possibility for:
The status quo is 3, though this PR has been the first large generator feature change since initial release. Do we have any preference on what approach to take with this PR (which I will do manually), and which (if not the same) approach to follow in general? I think the possible CI/automation enhancements will look slightly different for each option. |
.../src/main/java/com/google/cloud/generator/spring/composer/SpringAutoConfigClassComposer.java
Outdated
Show resolved
Hide resolved
...va/com/google/cloud/generator/spring/composer/goldens/EchoSpringAutoConfigurationRest.golden
Outdated
Show resolved
Hide resolved
if (hasRestOption) { | ||
// For GRPC+REST libraries, provide configuration property to override GRPC default and use REST transport instead | ||
// For GRPC-only and REST-only libraries, this property is not provided | ||
if (ComposerUtils.shouldSupportRestOptionWithGrpcDefault(transport, service)) { | ||
ExprStatement useRestVarStatement = | ||
ComposerUtils.createMemberVarStatement( | ||
"useRest", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered a transport
property with an enum value of "REST" or "GRPC" instead? I feel that would be more natural than useRest
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I can't recall if this was discussed when the useRest
property was initially implemented, but two small complications I can see are:
- This would be a breaking change for any existing users of this property (though now would be the time if it's a change we'd like to eventually make)
- Possibly needing to document or account for case sensitivity in user-provided property strings? (e.g. REST vs. Rest)
If I'm understanding correctly, the user configuration to override would change from something like
<service.prefix>.useRest=true
to
<service.prefix>.transport=REST
This property is only exposed for libraries that support grpc+rest (and default to grpc), and having a property named useRest
as an explicit override makes sense in my head as well, so I don't feel too strongly about either naming choice. Curious to hear any other concerns behind this suggestion though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're able to make this kind of change because we're still in preview. I believe that Spring Boot's relaxed binding should be case-insensitive for enums.
@blakeli0 Do you have an opinion on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think explicitly specify<service.prefix>.transport=REST
might be better in the long term, but there are more things we need to consider for this change.
For example, what would be the default value if this property is not specified? REST
for compute and GRPC
for the others? What's the criteria for us to decide the default value? What if a customer configured GRPC
for compute, are we going to error out on start up?
In addition, are we going to support this property for existing spring-cloud-gcp products as well? Some of the service does not support REST
yet or only support REST
(bigquery), but I think some service like spanner
already support both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spring Boot's relaxed binding should be case-insensitive for enums
Oh that’s good to know! I can give this change a try in a separate PR.
For example, what would be the default value if this property is not specified? REST for compute and GRPC for the others? What's the criteria for us to decide the default value? What if a customer configured GRPC for compute, are we going to error out on start up?
@blakeli0 My understanding of this suggested change is just in name/type (useRest
boolean => transport
enum) rather than the underlying behaviour: the current strategy is to only provide and support this property for libraries that support both GRPC+REST transport options. For GRPC and REST-only libraries where this property is not supported, any user configuration will not do anything (unless they override the transport provider and setting beans themselves), and the client library default builders will be used.
Would there be concern in this strategy itself, or is it more that having a renamed transport property only supported and applicable to some libraries could be confusing to users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @blakeli0 brings up a good point about more things to consider. For instance, we can imagine a global spring.cloud.gcp.transport
property that could switch all integrations to that transport. I almost feel like the property should be a list of desired transports. For instance, GRPC,REST
would be the default and mean that choose REST only if GRPC is unavailable. Users, can still specify something like 'REST', which should fail with an unsupported-transport exception for libraries that only support GRPC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this is a relatively large topic that worth it's own discussion, can we leave it as it is for now? And put all the discussion around the naming together in a separate doc? We can always change it in preview but we should finalize it before GA.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure - I can put together a doc on this topic to further explore/discuss (similar to the other conversation on strategy to enable/disable configuration classes).
We would always need 3 because the libraries bom could include new proto changes. In order for us to easily the generator changes, I think either 1 or 2 makes sense, otherwise all the generator changes and proto changes are in one huge PR before a new release. I would prefer 1 because it's easier to see all the generated changes in one PR, but 2 also has the advantage of seeing the generated changes separately so it's easier to review. This is not urgent, we can discuss it in next project meeting. |
.../test/java/com/google/cloud/generator/spring/composer/SpringAutoConfigClassComposerTest.java
Outdated
Show resolved
Hide resolved
@blakeli0 @meltsufin Thanks for your patience in reviewing this! I’ve run the code generation workflow on this feature branch to now include the generated code changes as well, but please let me know if you have preferences on whether to merge these together or separately. I think this PR is otherwise ready for a re-review at your convenience. Quick summary of three items from discussions above that I will follow-up on, separately from this PR:
|
@@ -0,0 +1,223 @@ | |||
/* | |||
* Copyright 2022 Google LLC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed the copyright year is still 2022, this is probably a bug in the generator though, similar to what I did last year. Can you take a look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah this part is being handled by the gapic-generator-java
composers; I've opened googleapis/sdk-platform-java#1720 for the corresponding fix. Thanks for catching!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License headers (note: for all generated modules) updated in 34495a0.
Reverted changes to generated code, and retriggering to include generator updates above in https://github.com/GoogleCloudPlatform/spring-cloud-gcp/actions/runs/5245239436. |
Kudos, SonarCloud Quality Gate passed! |
Merging this in, with corresponding release note message (through commit override) as |
Generator changes:
generate-library-list.sh
SpringComposer
java-compute
,newBuilder()
,defaultTransportChannelProvider()
, anddefaultApiClientHeaderProviderBuilder()
all default to REST implementation, so spring composer logic is kept the same as handling GRPC-only libraries: do not generate configurableuseRest
property, and use the default builders above in generated auto-configuration.For reviewers:
spring-cloud-previews/google-cloud-compute-spring-starter
google-cloud-compute-spring-starter
TransportChannelProvider
bean to reflect the current default behaviorgapic-generator-java
Memo on outstanding blocking changes:
Memo on non-blocking discussions / open follow-ups:
<service.prefix>.useRest
property (discussion)BEGIN_COMMIT_OVERRIDE
feat: add google-cloud-compute-spring-starter to starter modules available for preview
END_COMMIT_OVERRIDE