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

fix: Check additional_binding's custom FieldsExtractor #1565

Closed
wants to merge 18 commits into from

Conversation

lqiu96
Copy link
Contributor

@lqiu96 lqiu96 commented Mar 27, 2023

Thank you for opening a Pull Request! For general contributing guidelines, please refer to contributing guide

Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #1440 ☕️

This Part 2 of the fix. Part 1 was resolved here: #1440

@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Mar 27, 2023
Comment on lines 56 to 63
private ProtoMessageRequestFormatter(
FieldsExtractor<RequestT, String> requestBodyExtractor,
FieldsExtractor<RequestT, Map<String, List<String>>> queryParamsExtractor,
String rawPath,
PathTemplate pathTemplate,
FieldsExtractor<RequestT, Map<String, String>> pathVarsExtractor,
List<String> additionalRawPaths,
List<PathTemplate> additionalPathTemplates) {
Map<PathTemplate, FieldsExtractor<RequestT, Map<String, String>>>
additionalPathsExtractorMap) {
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 is a private constructor which should give us some flexibility to update the parameters.

Comment on lines 85 to 117
private final FieldsExtractor<ListOperationsRequest, Map<String, String>>
LRO_LIST_PATH_EXTRACTOR =
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<ListOperationsRequest> serializer = ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
};
private final FieldsExtractor<GetOperationRequest, Map<String, String>> LRO_GET_PATH_EXTRACTOR =
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<GetOperationRequest> serializer = ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
};

private final FieldsExtractor<DeleteOperationRequest, Map<String, String>>
LRO_DELETE_PATH_EXTRACTOR =
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<DeleteOperationRequest> serializer = ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
};

private final FieldsExtractor<CancelOperationRequest, Map<String, String>>
LRO_CANCEL_PATH_EXTRACTOR =
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<CancelOperationRequest> serializer = ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

OperationsStub has a default FieldsExtractor for each RPC (difference being that the request type for each FieldsExtractor is different). Each request type in the proto file has the name field, so we should be able to the default FieldsExtractor even for custom paths: https://github.com/googleapis/googleapis/blob/d5a51f6baba66f5dde236211d41d66efa1e4e7ca/google/longrunning/operations.proto#L171

Comment on lines +77 to +89
.setAdditionalPathsExtractorMap(
ImmutableMap
.<PathTemplate, FieldsExtractor<Field, Map<String, String>>>builder()
.put(
PathTemplate.create("/fake/v1/name/{name=john/*}"),
request -> {
Map<String, String> fields = new HashMap<>();
ProtoRestSerializer<Field> serializer =
ProtoRestSerializer.create();
serializer.putPathParam(fields, "name", request.getName());
return fields;
})
.build())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test cases use john/imTheBestField so they match against the additionalPathExtractor()

@sonarqubecloud
Copy link

[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@sonarqubecloud
Copy link

[java_showcase_integration_tests] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

25.6% 25.6% Coverage
0.0% 0.0% Duplication

@sonarqubecloud
Copy link

[java_showcase_unit_tests] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

43.4% 43.4% Coverage
0.0% 0.0% Duplication

Comment on lines +118 to +121
.setAdditionalBindings(
httpRule.getAdditionalBindingsList().stream()
.map(x -> parseHttpRuleHelper(x, inputMessageOpt, messageTypes))
.collect(Collectors.toList()))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

setAdditionalPatterns above just gets the HttpVerb associated with the additional_bindings list. setAdditionalBindings recursively calls this function to get the nested additional_bindings.

@lqiu96 lqiu96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 28, 2023
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 28, 2023
@lqiu96
Copy link
Contributor Author

lqiu96 commented Mar 28, 2023

Error:

16:29:34:562 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project google-cloud-kms: Compilation failure: Compilation failure:
16:29:34:563 [ERROR] /tmpfs/src/github/gapic-generator-java/google-cloud-java/java-kms/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonEkmServiceStub.java:[380,23] cannot find symbol
16:29:34:563 [ERROR]   symbol:   method setAdditionalPaths(java.lang.String,java.lang.String,java.lang.String,java.lang.String)
16:29:34:563 [ERROR]   location: class com.google.api.gax.httpjson.ProtoMessageRequestFormatter.Builder<com.google.iam.v1.SetIamPolicyRequest>
16:29:34:563 [ERROR] /tmpfs/src/github/gapic-generator-java/google-cloud-java/java-kms/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonEkmServiceStub.java:[422,23] cannot find symbol
16:29:34:564 [ERROR]   symbol:   method setAdditionalPaths(java.lang.String,java.lang.String,java.lang.String,java.lang.String)
16:29:34:564 [ERROR]   location: class com.google.api.gax.httpjson.ProtoMessageRequestFormatter.Builder<com.google.iam.v1.GetIamPolicyRequest>
16:29:34:564 [ERROR] /tmpfs/src/github/gapic-generator-java/google-cloud-java/java-kms/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonEkmServiceStub.java:[461,23] cannot find symbol
16:29:34:565 [ERROR]   symbol:   method setAdditionalPaths(java.lang.String,java.lang.String,java.lang.String,java.lang.String)
16:29:34:565 [ERROR]   location: class com.google.api.gax.httpjson.ProtoMessageRequestFormatter.Builder<com.google.iam.v1.TestIamPermissionsRequest>
16:29:34:565 [ERROR] /tmpfs/src/github/gapic-generator-java/google-cloud-java/java-kms/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonKeyManagementServiceStub.java:[1164,23] cannot find symbol
16:29:34:565 [ERROR]   symbol:   method setAdditionalPaths(java.lang.String,java.lang.String,java.lang.String,java.lang.String)
16:29:34:566 [ERROR]   location: class com.google.api.gax.httpjson.ProtoMessageRequestFormatter.Builder<com.google.iam.v1.SetIamPolicyRequest>
16:29:34:566 [ERROR] /tmpfs/src/github/gapic-generator-java/google-cloud-java/java-kms/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonKeyManagementServiceStub.java:[1206,23] cannot find symbol
16:29:34:566 [ERROR]   symbol:   method setAdditionalPaths(java.lang.String,java.lang.String,java.lang.String,java.lang.String)
16:29:34:566 [ERROR]   location: class com.google.api.gax.httpjson.ProtoMessageRequestFormatter.Builder<com.google.iam.v1.GetIamPolicyRequest>
16:29:34:567 [ERROR] /tmpfs/src/github/gapic-generator-java/google-cloud-java/java-kms/google-cloud-kms/src/main/java/com/google/cloud/kms/v1/stub/HttpJsonKeyManagementServiceStub.java:[1245,23] cannot find symbol
16:29:34:567 [ERROR]   symbol:   method setAdditionalPaths(java.lang.String,java.lang.String,java.lang.String,java.lang.String)
16:29:34:567 [ERROR]   location: class com.google.api.gax.httpjson.ProtoMessageRequestFormatter.Builder<com.google.iam.v1.TestIamPermissionsRequest>
16:29:34:568 [ERROR] -> [Help 1]

Seems to be due to the breaking changes from this PR (updating setAdditionalPaths to setAdditionalPathsExtractorMap.

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 9, 2023

[gapic-generator-java-root] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

59.4% 59.4% Coverage
0.0% 0.0% Duplication

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 9, 2023

[java_showcase_integration_tests] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

40.0% 40.0% Coverage
0.0% 0.0% Duplication

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 9, 2023

[java_showcase_unit_tests] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

43.8% 43.8% Coverage
0.0% 0.0% Duplication

@lqiu96
Copy link
Contributor Author

lqiu96 commented May 10, 2023

Closing this issue for now. Will re-open if there is a need for this fix.

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.

GAPIC HttpJson additional_bindings annotation is not being used
2 participants