-
Notifications
You must be signed in to change notification settings - Fork 53
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: Parser to consume the api-versioning value from proto #2630
Conversation
I know you wrote that it's not actually used inside Spring codegen, but for sample region tags. Would this break any functionality for the generated samples in Spring (and/or any other generated samples)? It sounds like it probably won't, but can double check this to confirm? |
gapic-generator-java/src/main/java/com/google/api/generator/gapic/model/Service.java
Show resolved
Hide resolved
gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
Outdated
Show resolved
Hide resolved
gapic-generator-java/src/test/java/com/google/api/generator/gapic/model/ServiceTest.java
Show resolved
Hide resolved
Thanks @zhumin8! I think it look good! I left a few nits and a few open questions that popped in while I reviewing. I think we can just double check with the team to confirm. |
For non-Spring samples, it's not breaking anything after the renaming. I should also clarify that the change is only on the method names, which are internal, not actual behaviors. |
if (serviceOptions.hasExtension(ClientProto.apiVersion)) { | ||
String apiVersion = serviceOptions.getExtension(ClientProto.apiVersion); | ||
serviceBuilder.setApiVersion(apiVersion); | ||
} |
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.
nit:
String apiVersion = null;
if (serviceOptions.hasExtension(ClientProto.apiVersion)) {
apiVersion = serviceOptions.getExtension(ClientProto.apiVersion);
}
...
return serviceBuilder
.setName(serviceName)
....
.setApiVersion(apiVersion)
I believe the Service class can take a null or empty ApiVersion
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 had similar concerns at first. But I believe both null and empty are covered. (I'll create additional test cases in ParserTest for it).
Note that If value is not set for serviceBuilder, it is null by default.
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.
LGTM. I added a few nits if you could resolve before merging.
Can you also update the description: |
Quality Gate passed for 'gapic-generator-java-root'Issues Measures |
Quality Gate passed for 'java_showcase_integration_tests'Issues Measures |
@lqiu96 Moved testing to a dedicated new proto as you suggested. This |
Thanks, LGTM. |
#2671) This is part 2, following changes in #2630 Changes in this pr: - ApiClientHeaderProvider: add key and token setter for api version. - AbstractServiceStubSettingsClassComposer: add logic to set this header when api-version is present (not null or empty) - Unit and golden tests to reflect above changes. (This includeds a few new golden files created for tests based on the dedicated proto created in #2630) This pr does not include gapic-showcased testing for now. --- manual tested with [gapic-showcase](https://github.com/googleapis/gapic-showcase) v0.33.0 steps: - Use gapic-showcase v0.33.0 (which includes update in 1484) - use `gapic-showcase run -v` which prints the request header - From showcase folder, run `mvn verify -P enable-integration-tests -Dit.test=ITAutoPopulatedFields.java -pl=gapic-showcase` Printed header in manual testing Grpc ``` 2024/04/16 10:26:41 Received Unary Request for Method: /google.showcase.v1beta1.Echo/Echo 2024/04/16 10:26:41 Request headers: 2024/04/16 10:26:41 grpc-accept-encoding: gzip 2024/04/16 10:26:41 content-type: application/grpc 2024/04/16 10:26:41 x-goog-api-version: v1_20240408 2024/04/16 10:26:41 :authority: localhost:7469 2024/04/16 10:26:41 user-agent: grpc-java-netty/1.62.2 2024/04/16 10:26:41 x-goog-api-client: gl-java/17.0.7__Eclipse-Adoptium__Temurin-17.0.7-7 gapic/0.0.1-SNAPSHOT gax/2.46.2-SNAPSHOT grpc/1.62.2 2024/04/16 10:26:41 Request: error:{code:2} request_id:"1e26ee16-ed07-4eeb-be0e-49b769678779" other_request_id:"40883e5d-3b20-4add-854c-9808bd009260" 2024/04/16 10:26:41 Returning Error: rpc error: code = Unknown desc = ``` Httpjson ``` 2024/04/16 10:26:41 Received POST request matching '/v1beta1/echo:echo': "/v1beta1/echo:echo" 2024/04/16 10:26:41 urlPathParams (expect 0, have 0): map[] 2024/04/16 10:26:41 urlRequestHeaders: User-Agent: "Google-HTTP-Java-Client/1.44.1 (gzip)" Content-Type: "application/json; charset=utf-8" Connection: "keep-alive" Accept-Encoding: "gzip" X-Goog-Api-Client: "gl-java/17.0.7__Eclipse-Adoptium__Temurin-17.0.7-7 gapic/0.0.1-SNAPSHOT gax/2.46.2-SNAPSHOT rest/" X-Goog-Api-Version: "v1_20240408" Accept: "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" Content-Length: "129" 2024/04/16 10:26:41 request: { "error": { "code": 500, "message": "", "details": [] }, "severity": "UNNECESSARY", "header": "", "otherHeader": "", "requestId": "e690a84b-176d-421e-9e5d-ba752f68fec8", "otherRequestId": "47e0fbde-056a-43ae-bba6-8b6770d861f7" } ```
🤖 I have created a release *beep* *boop* --- <details><summary>2.40.0</summary> ## [2.40.0](v2.39.0...v2.40.0) (2024-05-02) ### Features * [common-protos] add `Weight` to common types for Shopping APIs to be used for accounts bundle ([#2699](#2699)) ([5bb9770](5bb9770)) * add a CLI tool to validate generation configuration ([#2691](#2691)) ([f2ce524](f2ce524)) * Parser to consume the api-versioning value from proto ([#2630](#2630)) ([40711fd](40711fd)) * Update Gapic generator and Gax to emit api-versioning via header ([#2671](#2671)) ([e63d1b4](e63d1b4)) ### Bug Fixes * change folder prefix for adding headers ([#2688](#2688)) ([4e92be8](4e92be8)) * Log HttpJson's async thread pool core size ([#2697](#2697)) ([34b4bc3](34b4bc3)) * replace `cfg = "host"` with `cfg = "exec"` ([#2637](#2637)) ([6d673f3](6d673f3)) * Return resolved endpoint from StubSettings' Builder ([#2715](#2715)) ([32c9995](32c9995)) ### Dependencies * Make opentelemetry-api an optional dependency. ([#2681](#2681)) ([3967a19](3967a19)) * update dependency absl-py to v2.1.0 ([#2659](#2659)) ([cae6d79](cae6d79)) * update dependency gitpython to v3.1.43 ([#2656](#2656)) ([208bef4](208bef4)) * update dependency lxml to v5.2.1 ([#2661](#2661)) ([b95ad49](b95ad49)) * update dependency net.bytebuddy:byte-buddy to v1.14.14 ([#2703](#2703)) ([87069bc](87069bc)) * update dependency typing to v3.10.0.0 ([#2663](#2663)) ([7fb5653](7fb5653)) * update gapic-showcase to v0.33.0 ([#2653](#2653)) ([0a71cbf](0a71cbf)) ### Documentation * Add contributing guidelines to PR and issue templates ([#2682](#2682)) ([42526dc](42526dc)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
This is part one to resolve b/330980553, this pr allows read and parse api versioning from proto to service model. Changes included in this pr: - rename current apiVersion to packageVersion. This packageVersion is parsed from package name and exposed in #1075. It was intended to be used in Spring codegen, but not actually used. It is used in generating sample region tags (see details [9ec3531](9ec3531)) - exposing apiVersion from Service model. - Parser.java to parse apiVersion from `ClientProto.apiVersion` to service.
#2671) This is part 2, following changes in #2630 Changes in this pr: - ApiClientHeaderProvider: add key and token setter for api version. - AbstractServiceStubSettingsClassComposer: add logic to set this header when api-version is present (not null or empty) - Unit and golden tests to reflect above changes. (This includeds a few new golden files created for tests based on the dedicated proto created in #2630) This pr does not include gapic-showcased testing for now. --- manual tested with [gapic-showcase](https://github.com/googleapis/gapic-showcase) v0.33.0 steps: - Use gapic-showcase v0.33.0 (which includes update in 1484) - use `gapic-showcase run -v` which prints the request header - From showcase folder, run `mvn verify -P enable-integration-tests -Dit.test=ITAutoPopulatedFields.java -pl=gapic-showcase` Printed header in manual testing Grpc ``` 2024/04/16 10:26:41 Received Unary Request for Method: /google.showcase.v1beta1.Echo/Echo 2024/04/16 10:26:41 Request headers: 2024/04/16 10:26:41 grpc-accept-encoding: gzip 2024/04/16 10:26:41 content-type: application/grpc 2024/04/16 10:26:41 x-goog-api-version: v1_20240408 2024/04/16 10:26:41 :authority: localhost:7469 2024/04/16 10:26:41 user-agent: grpc-java-netty/1.62.2 2024/04/16 10:26:41 x-goog-api-client: gl-java/17.0.7__Eclipse-Adoptium__Temurin-17.0.7-7 gapic/0.0.1-SNAPSHOT gax/2.46.2-SNAPSHOT grpc/1.62.2 2024/04/16 10:26:41 Request: error:{code:2} request_id:"1e26ee16-ed07-4eeb-be0e-49b769678779" other_request_id:"40883e5d-3b20-4add-854c-9808bd009260" 2024/04/16 10:26:41 Returning Error: rpc error: code = Unknown desc = ``` Httpjson ``` 2024/04/16 10:26:41 Received POST request matching '/v1beta1/echo:echo': "/v1beta1/echo:echo" 2024/04/16 10:26:41 urlPathParams (expect 0, have 0): map[] 2024/04/16 10:26:41 urlRequestHeaders: User-Agent: "Google-HTTP-Java-Client/1.44.1 (gzip)" Content-Type: "application/json; charset=utf-8" Connection: "keep-alive" Accept-Encoding: "gzip" X-Goog-Api-Client: "gl-java/17.0.7__Eclipse-Adoptium__Temurin-17.0.7-7 gapic/0.0.1-SNAPSHOT gax/2.46.2-SNAPSHOT rest/" X-Goog-Api-Version: "v1_20240408" Accept: "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" Content-Length: "129" 2024/04/16 10:26:41 request: { "error": { "code": 500, "message": "", "details": [] }, "severity": "UNNECESSARY", "header": "", "otherHeader": "", "requestId": "e690a84b-176d-421e-9e5d-ba752f68fec8", "otherRequestId": "47e0fbde-056a-43ae-bba6-8b6770d861f7" } ```
🤖 I have created a release *beep* *boop* --- <details><summary>2.40.0</summary> ## [2.40.0](v2.39.0...v2.40.0) (2024-05-02) ### Features * [common-protos] add `Weight` to common types for Shopping APIs to be used for accounts bundle ([#2699](#2699)) ([5bb9770](5bb9770)) * add a CLI tool to validate generation configuration ([#2691](#2691)) ([f2ce524](f2ce524)) * Parser to consume the api-versioning value from proto ([#2630](#2630)) ([40711fd](40711fd)) * Update Gapic generator and Gax to emit api-versioning via header ([#2671](#2671)) ([e63d1b4](e63d1b4)) ### Bug Fixes * change folder prefix for adding headers ([#2688](#2688)) ([4e92be8](4e92be8)) * Log HttpJson's async thread pool core size ([#2697](#2697)) ([34b4bc3](34b4bc3)) * replace `cfg = "host"` with `cfg = "exec"` ([#2637](#2637)) ([6d673f3](6d673f3)) * Return resolved endpoint from StubSettings' Builder ([#2715](#2715)) ([32c9995](32c9995)) ### Dependencies * Make opentelemetry-api an optional dependency. ([#2681](#2681)) ([3967a19](3967a19)) * update dependency absl-py to v2.1.0 ([#2659](#2659)) ([cae6d79](cae6d79)) * update dependency gitpython to v3.1.43 ([#2656](#2656)) ([208bef4](208bef4)) * update dependency lxml to v5.2.1 ([#2661](#2661)) ([b95ad49](b95ad49)) * update dependency net.bytebuddy:byte-buddy to v1.14.14 ([#2703](#2703)) ([87069bc](87069bc)) * update dependency typing to v3.10.0.0 ([#2663](#2663)) ([7fb5653](7fb5653)) * update gapic-showcase to v0.33.0 ([#2653](#2653)) ([0a71cbf](0a71cbf)) ### Documentation * Add contributing guidelines to PR and issue templates ([#2682](#2682)) ([42526dc](42526dc)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
This is part one to resolve b/330980553, this pr allows read and parse api versioning from proto to service model.
Changes included in this pr:
ClientProto.apiVersion
to service.