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

Expose deprecated option in interceptor #571

Closed
makasim opened this issue Aug 23, 2023 · 2 comments · Fixed by #629
Closed

Expose deprecated option in interceptor #571

makasim opened this issue Aug 23, 2023 · 2 comments · Fixed by #629
Labels
enhancement New feature or request

Comments

@makasim
Copy link

makasim commented Aug 23, 2023

Is your feature request related to a problem? Please describe.
It would allow us to implement an interceptor that logs the usage of deprecated endpoints.

Describe the solution you'd like

RPC specs provide a deprecated option that could be used on a method. Currently, Connect only added a deprecated comment. Exposing the value to interceptors could help to build more robust solutions.

service CreateService {
  rpc Create(CreateRequest) returns (CreateResponse) {
    option deprecated = true;
  }
}

The solution I see: The option could be added to connect.Spec. That would be enough for this particular case.

WrapUnary(unaryFunc connect.UnaryFunc) connect.UnaryFunc {
	return func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) {
	    if request.Spec().Deprecated {
	       log.Printf("WARNING: %s is deprecated", request.Spec().Procedure)
	    }
            return unaryFunc(ctx, request)
	}
}

A more generic approach is to expose all the options in connect.Spec somehow (map?). In this case, we could add a custom option with a api removal date and set some alerts for it.

Describe alternatives you've considered

Additional context

@makasim makasim added the enhancement New feature or request label Aug 23, 2023
@akshayjshah
Copy link
Member

Hey @makasim! Great suggestion - I've been meaning to expose the RPC's descriptor on Spec, which would give you access to deprecated, any custom options, and a bunch of other info.

In the meantime, you can get the descriptor yourself from the global registry: see this comment on another issue. protoc-gen-connect-go now generates constants for service names, so you shouldn't need a hard-coded string to look up the descriptor.

@makasim
Copy link
Author

makasim commented Aug 27, 2023

Looks like a global registry would solve my issue. Thank you for the hint!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants