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: Numeric enums in routing headers #2328

Merged
merged 27 commits into from
Jan 16, 2024
Merged

Conversation

ddixit14
Copy link
Contributor

@ddixit14 ddixit14 commented Jan 2, 2024

Solves - #2368 (Numeric enums in implicit routing headers)
FYI, only implicit routing headers can be fixed currently because explicit routing headers are implemented as strings by design. See this doc for more details.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Jan 2, 2024
@ddixit14 ddixit14 changed the title chore: Numeric enums in routing headers feat: Numeric enums in routing headers Jan 2, 2024
@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
@ddixit14
Copy link
Contributor Author

ddixit14 commented Jan 8, 2024

After commit d63e854, the local testing shows this O/P. Getting "getFKingdomValue" in the method name.
91B5B852-662E-4299-9E59-23853BE0DB09

@ddixit14
Copy link
Contributor Author

ddixit14 commented Jan 8, 2024

Code changes description:
createRequestFieldGetterExpr() is being called in both cases (routing_header rule present v/s absent) to map the parameters.

In first case (routingHeaderRule() == null, createRequestParamsExtractorBodyForHttpBindings() is called), createRequestFieldGetterExpr() is modified to accept an extra boolean parameter, isFieldEnum(). And if the field is enum, I am adding an extra “Value” to the fieldMethod name (https://github.com/googleapis/sdk-platform-java/pull/2328/files#diff-13cc1d69966fca5c433b2c243aa4e8414520cf05e295f02ed52f2fe5097cac21R1474) during the last iteration of the descendant fields.

In the 2nd case when routingHeaderRule()!=null, I am sending false in isFieldEnum() because routingHeaderParam does not have anything to check if it is an enum or not (or is there? I am not able to find it).

@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 12, 2024
@ddixit14 ddixit14 marked this pull request as ready for review January 12, 2024 20:26
@ddixit14 ddixit14 requested a review from a team as a code owner January 12, 2024 20:26
@ddixit14
Copy link
Contributor Author

Since this only solves the implicit routing headers, can you please create a separate issue to track it and update the description of this PR accordingly? Leaving a comment at #1966 would be great as well.

Done. Here is the issue created - #2368

@lqiu96
Copy link
Contributor

lqiu96 commented Jan 16, 2024

FYI @ddixit14, we have Showcase ITs for Dynamic Routing Headers at https://github.com/googleapis/sdk-platform-java/blob/762c125abadb5e56682224c9f1587c71e5c6e653/showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITDynamicRoutingHeaders.java

I think the compliance.proto has a enum field that you can possibly test against. It may be possible to add a test to intercept the the enum value is sent as an int value in the headers.

@@ -175,6 +189,24 @@ public void testGrpc_matchesHeaderName() {
assertThat(requestHeaders).containsExactlyElementsIn(expectedHeaders);
}

@Test
public void testGrpc_implicitHeadersEnum() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Rename this to be a bit more descriptive. Something like testGrpc_implicitHeaders_enumsEncodedasInt() to describe that this test covers specifically enums -> int.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, can you add an httpjson test case as well. I think it affects both transports. Ignore this comment if it only affects gRPC.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Rename this to be a bit more descriptive. Something like testGrpc_implicitHeaders_enumsEncodedasInt() to describe that this test covers specifically enums -> int.

+1000 to this. See unit tests naming for details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed the tests and added httpjson case as well. thank you.

@lqiu96
Copy link
Contributor

lqiu96 commented Jan 16, 2024

Also, we talked earlier about possibly enhancing echo.proto to also test for some explicit + implicit dynamic routing enum use cases. I took another look into echo.proto and I think it makes sense since a bulk of the routing header test cases are there: https://github.com/googleapis/gapic-showcase/blob/330a3a25eb8c4d0948860f1898fe7dcc05dc4ea5/schema/google/showcase/v1beta1/echo.proto#L48-L86

I think you can create an issue in the gapic-showcase repo and someone can pick it up in the future.

Copy link
Contributor

@lqiu96 lqiu96 left a comment

Choose a reason for hiding this comment

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

I added a few more nits but overall LGTM to me. Please resolve the nits and let @blakeli0 to take another look before merging. Thanks for the PR!

@blakeli0
Copy link
Collaborator

Also, we talked earlier about possibly enhancing echo.proto to also test for some explicit + implicit dynamic routing enum use cases. I took another look into echo.proto and I think it makes sense since a bulk of the routing header test cases are there: https://github.com/googleapis/gapic-showcase/blob/330a3a25eb8c4d0948860f1898fe7dcc05dc4ea5/schema/google/showcase/v1beta1/echo.proto#L48-L86

I think you can create an issue in the gapic-showcase repo and someone can pick it up in the future.

If we already have a test case in compliance.proto, what is the advantage of adding one to echo.proto? Is it mostly for simplifying our showcase tests, so that we don't have to create a separate ComplianceClient? If it's for latter, I don't think we have to add one.
Ideally the showcase protos should be grouped into features, so that routing header test cases can be in a dedicated proto. Before that happens, I think having implicit routing header test case in a separate proto is OK.

@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 16, 2024
@lqiu96
Copy link
Contributor

lqiu96 commented Jan 16, 2024

Also, we talked earlier about possibly enhancing echo.proto to also test for some explicit + implicit dynamic routing enum use cases. I took another look into echo.proto and I think it makes sense since a bulk of the routing header test cases are there: https://github.com/googleapis/gapic-showcase/blob/330a3a25eb8c4d0948860f1898fe7dcc05dc4ea5/schema/google/showcase/v1beta1/echo.proto#L48-L86
I think you can create an issue in the gapic-showcase repo and someone can pick it up in the future.

If we already have a test case in compliance.proto, what is the advantage of adding one to echo.proto? Is it mostly for simplifying our showcase tests, so that we don't have to create a separate ComplianceClient? If it's for latter, I don't think we have to add one. Ideally the showcase protos should be grouped into features, so that routing header test cases can be in a dedicated proto. Before that happens, I think having implicit routing header test case in a separate proto is OK.

For now, it's mainly for the latter reason. Agreed that ideally we would have a separate showcase proto for routing headers, but it looks like the explicit headers are mostly contained in the echo proto. It's not urgent to add an enum to the echo proto, but a smaller task to enable showcase tests for more routing headers use cases is to add it there (especially for any future explicit enhancements/ improvements). In the future/whenever someone has the time, we can create a new proto specifically for routing headers.

Copy link

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

Kudos, no new issues were introduced!

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

See analysis details on SonarCloud

Copy link

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

@ddixit14 ddixit14 merged commit 4d043de into main Jan 16, 2024
22 of 25 checks passed
@ddixit14 ddixit14 deleted the numeric-enums-routing-headers branch January 16, 2024 22:24
lqiu96 pushed a commit that referenced this pull request Jan 17, 2024
* chore: Numeric enums in routing headers
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.

3 participants