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

RetryingHttpRequesterFilter: add on request retry callback #2916

Merged
merged 3 commits into from
May 14, 2024

Conversation

idelpivnitskiy
Copy link
Member

Motivation:

There are use-cases when users need to perform an action before the retry, like updating meta-data or logging/metrics. Because all retry functions return BackoffPolicy, it's still not known inside the function of BackoffPolicy will retry or not because of the retry counts limit.

Modifications:

  • Add RetryingHttpRequesterFilter.Builder.onRequestRetry(BiConsumer) that users can use to intercept every retry attempt;
  • Test that the new callback works for request retries;

Result:

Users can see when the retry actually happens, after backoff time.

If there will be a similar use-case for reserveConnection in the future, we will add a separate callback.

Motivation:

There are use-cases when users need to perform an action before the
retry, like updating meta-data or logging/metrics. Because all retry
functions return `BackoffPolicy`, it's still not known inside the
function of `BackoffPolicy` will retry or not because of the retry
counts limit.

Modifications:
- Add `RetryingHttpRequesterFilter.Builder.onRequestRetry(BiConsumer)`
that users can use to intercept every retry attempt;
- Test that the new callback works for request retries;

Result:

Users can see when the retry actually happens, after backoff time.

If there will be a similar use-case for `reserveConnection` in the
future, we will add a separate callback.
@idelpivnitskiy idelpivnitskiy requested review from daschl and tkountis May 9, 2024 22:29
@idelpivnitskiy idelpivnitskiy self-assigned this May 9, 2024
* {@link StreamingHttpClient#request(StreamingHttpRequest) request} retry attempt
* @return {@code this}
*/
public Builder onRequestRetry(final BiConsumer<HttpRequestMetaData, Throwable> onRequestRetry) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be useful if the number of retries on the current attempt are also made available to the consumer somehow? I know one can do this manually by setting it on the context and tracking it on their own, but I would assume that the number of attempts is something a lot of people need, if only for logging.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I will have to come up with a new interface. Will do that, thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Any suggestion for the name? Assuming we may need a similar feature for reserveConnection retries

Copy link
Contributor

Choose a reason for hiding this comment

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

Its not very apparent from the name at which stage the flow runs other than the javadoc. WDYT about including such information as part of the name? Something like onBeforeRequestRetry

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding the interface my 2c would be BeforeRetryConsumer or BeforeRetryInfluencer to highlight the ability to change things in the flow.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will probably go with beforeRequestRetry(BeforeRetryCallback) if no objections

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up keeping the builder name as-is, but clarifying "before" as part of the RetryCallbacks contract.

Naming is hard, open to other suggestions in the context of a new interface.

Copy link
Contributor

@tkountis tkountis left a comment

Choose a reason for hiding this comment

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

lgtm - consider altering the examples to include a case where you alter a header of the request with the retry attempt count. Often useful.

@idelpivnitskiy idelpivnitskiy requested review from tkountis and daschl May 11, 2024 00:45
@idelpivnitskiy idelpivnitskiy requested a review from daschl May 13, 2024 18:06
@idelpivnitskiy idelpivnitskiy merged commit 7919d3a into apple:main May 14, 2024
15 checks passed
@idelpivnitskiy idelpivnitskiy deleted the onRequestRetry branch May 14, 2024 18:01
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

3 participants