Skip to content

Pass RetryToken value to interceptor hooks #1124

@timocov

Description

@timocov

The use case is the following: you're making a call to the service behind a load balancer, and when the service is overloaded (or cannot satisfy your request for whatever reason) it throws a specific error that you can handle on the client side and retry but in order to avoid hitting the same already overloaded service you can pass a header with something like "excluded instances" values so that when load balancer gets the request it can navigate it to a service instance that isn't yet overloaded.

(it is just one of the examples, but you get the gist of it)

In order to do this, I was thinking to do the following on the client side to utilize java client's retry mechanism:

  1. Implement a custom RetryStrategy that based on the error can return a custom RetryToken instance with required information in it (e.g. "instances to avoid next time") (because interceptor doesn't have access to "previous response" data)
  2. Implement an interceptor and overload modifyBeforeRetryLoop method to add required headers with values defined in RetryToken instance

The problem with this approach is that it seems retryToken isn't exposed to any interceptor's methods via hooks nor even via context (and a call context isn't provided to RetryStrategy).

So I was thinking that adding a retryToken to interceptors hooks might be a good solution for this? If you agree, I'm happy to make provide a PR. If not, please share your thoughts on how to approach it differently (basically modify request based on previous responses and utilize client's retry mechanism) 🙂
Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions