go-grpc-middleware icon indicating copy to clipboard operation
go-grpc-middleware copied to clipboard

FR: retry should pass the grpc.Status from err to BackoffFuncContext

Open evantorrie opened this issue 4 years ago • 6 comments

Retry interceptor (and possibly others) should pass status.Convert(err) to the client-supplied callback function, i.e. BackoffFuncContext(). Grpc services often return information in Status.Details which may affect the decision as to how long to wait until the next retry.

Currently the API does not supply the error returned from invocation to the callback function, so there is no way for the callback function to inspect the error and Status.

evantorrie avatar Jun 15 '20 05:06 evantorrie

Could you give an example of how you'd like to see this work? Maybe a use case?

johanbrandhorst avatar Jun 15 '20 09:06 johanbrandhorst

A use case is the OpenTelemetry Collector protocol, which specifies that clients should throttle themselves based on the status returned from a failed GRPC call.

See https://github.com/open-telemetry/oteps/blob/master/text/0035-opentelemetry-protocol.md#throttling

Without having access to the Status, a client-provided backoff function is unable to conform to the throttling protocol, even though in all other respects such as backoff, the grpc_retry middleware can be configured to work as desired.

evantorrie avatar Jun 15 '20 15:06 evantorrie

I think maybe in this specific case we should just add a way to automatically support this, as it's a generic gRPC status error detail. Regardless, sorry if I was being unclear, I'm asking what kind of API changes you expect here? Should we add an err parameter, or magically hide in the context or something?

johanbrandhorst avatar Jun 16 '20 08:06 johanbrandhorst

I was expecting it may be useful for the backoff function to get the err parameter from the last unsuccessful call passed to it.

evantorrie avatar Jun 16 '20 15:06 evantorrie

This seems a reasonable ask for v2, WDYT @bwplotka?

johanbrandhorst avatar Jun 16 '20 21:06 johanbrandhorst

Definitely. Help wanted to improve it on v2 branch.

bwplotka avatar Jun 18 '20 17:06 bwplotka