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

chore: expose request func signatures #3728

Closed

Conversation

leungster
Copy link
Contributor

@leungster leungster commented Nov 7, 2023

Have you read the Contributing Guidelines?

yes

Brief description of what is fixed or changed

Assign request-func-signatures to unexported fields to allow overriding of the logic.

Other comments

I have a use case where I want to push additional info into the ctx prior to calling my RPC method. At the moment I can only set grpc Metadata which only allows string types.
The request function is already a separate func in the generated code and I'd like to override it to inject additional info into my ctx prior to calling the predefined request-func.

Summary by CodeRabbit

  • Refactor
    • Improved the code structure for better handling of client and server streaming scenarios, and in-process request handling.
  • Tests
    • Updated tests to align with the refactored code structure.

Assign request-func-signatures to unexported fields to allow overriding of the logic.
Copy link

coderabbitai bot commented Nov 7, 2023

Walkthrough

The changes primarily involve a shift in the structure of the codebase from using exported functions to variable assignments with anonymous functions. This affects the function signatures, return values, and parameter types. The modifications also impact the templates used for code generation and the handling of client and server streaming scenarios.

Changes

File Path Change Summary
.../gengateway/template.go Function signatures replaced with variable assignments containing anonymous functions. Modifications to the templates used for code generation.
.../gengateway/template_test.go Changes to function signatures related to request handling. Impact on client and server streaming scenarios and in-process request handling.

Poem

🍂 As the leaves fall this November day, 🍁

In the world of code, we've found a new way. 🌐

From functions exported, to variables assigned, 🔄

A shift in structure, a new design. 🏗️

Streaming scenarios, now handled with care, 📡

In-process requests, no longer a scare. 👻

So let's celebrate these changes, so neat, 🎉

With a carrot cake, and a well-deserved treat! 🥕🍰


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 552a019 and 7b42200.
Files ignored due to filter (17)
  • examples/internal/helloworld/helloworld.pb.gw.go
  • examples/internal/proto/examplepb/a_bit_of_everything.pb.gw.go
  • examples/internal/proto/examplepb/echo_service.pb.gw.go
  • examples/internal/proto/examplepb/flow_combination.pb.gw.go
  • examples/internal/proto/examplepb/generate_unbound_methods.pb.gw.go
  • examples/internal/proto/examplepb/ignore_comment.pb.gw.go
  • examples/internal/proto/examplepb/non_standard_names.pb.gw.go
  • examples/internal/proto/examplepb/openapi_merge_a.pb.gw.go
  • examples/internal/proto/examplepb/openapi_merge_b.pb.gw.go
  • examples/internal/proto/examplepb/remove_internal_comment.pb.gw.go
  • examples/internal/proto/examplepb/response_body_service.pb.gw.go
  • examples/internal/proto/examplepb/stream.pb.gw.go
  • examples/internal/proto/examplepb/unannotated_echo_service.pb.gw.go
  • examples/internal/proto/examplepb/use_go_template.pb.gw.go
  • examples/internal/proto/examplepb/visibility_rule_echo_service.pb.gw.go
  • examples/internal/proto/examplepb/wrappers.pb.gw.go
  • examples/internal/proto/standalone/unannotated_echo_service.pb.gw.go
Files selected for processing (2)
  • protoc-gen-grpc-gateway/internal/gengateway/template.go (2 hunks)
  • protoc-gen-grpc-gateway/internal/gengateway/template_test.go (3 hunks)
Additional comments: 5
protoc-gen-grpc-gateway/internal/gengateway/template_test.go (3)
  • 144-148: The function signature has been changed to a variable assignment containing an anonymous function. Ensure that all references to this function have been updated accordingly.

  • 309-313: Similar to the previous comment, the function signature has been changed to a variable assignment containing an anonymous function. Ensure that all references to this function have been updated accordingly.

  • 464-464: The function signature has been changed to a variable assignment containing an anonymous function. Ensure that all references to this function have been updated accordingly.

protoc-gen-grpc-gateway/internal/gengateway/template.go (2)
  • 268-270: The function signature has been changed to a variable assignment containing an anonymous function. Ensure that all references to this function have been updated accordingly. Also, verify that the new function signature is compatible with all its usages.

  • 496-496: Similar to the previous comment, the function signature has been changed to a variable assignment containing an anonymous function. Ensure that all references to this function have been updated accordingly. Also, verify that the new function signature is compatible with all its usages.

@johanbrandhorst
Copy link
Collaborator

Hi, thanks for the PR. I think I'd like to understand the use case better before approving this. Are you saying that you'd like to add some non-string metadata into the context in the gRPC gateway request path? Is this similar to the request in #3700? Can you do what you want on the http.Handler level, or the gRPC interceptor level? In the future I'd appreciate if you open an issue to discuss any changes before going to create a PR as well. Thanks!

@leungster
Copy link
Contributor Author

@johanbrandhorst apologies for not creating an issue. I patched this for my own purposes via bazel and wanted to port over the patch to see if it is a reasonable change.

The concrete use case is more convoluted than what the PR says and I think for most use cases, someone can inject things into the request ctx via a handler wrapper.

We're trying to bypass the default decoder logic and manually unmarshal in our service RPC. We're not using the proto request message and instead directly unmarshaling into our internal datastructure to avoid duplicative memory allocations.
Our incoming request JSON is large and while we want to stop supporting this API, there are legacy clients that prevent us removing it entirely. This is a stop-gap until all users are switched over.

#3700 isn't quite the same because it sounds like they want to extract the HTTP pattern outside of the generated handler. Coincidentally we use runtime.WithMetadata to do what they're trying to do with opentelemetry.

@johanbrandhorst
Copy link
Collaborator

If you already have a way to patch this such that we don't need to make any changes to the gateway, I'd prefer not to merge this as is. It seems a very niche use case to me, and in general I'd recommend avoiding making any changes to the contents of generated packages as it may lead to breakages down the road. We certainly don't consider changing unexported variables in generated packages a breaking change. Please close this PR if you're happy to keep it as a private patch.

@leungster
Copy link
Contributor Author

Sure, we'll keep it as a private patch then.

@leungster leungster closed this Nov 10, 2023
@leungster leungster deleted the el-expose-rpc-func-signature branch November 10, 2023 01:17
@leungster leungster restored the el-expose-rpc-func-signature branch November 10, 2023 01:17
@leungster leungster deleted the el-expose-rpc-func-signature branch November 10, 2023 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants