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

CDF-20260: allow customizing shouldRetry in RetryingBackend #708

Merged
merged 1 commit into from
Nov 14, 2023

Conversation

dmivankov
Copy link
Contributor

@dmivankov dmivankov commented Nov 9, 2023

Predicate takes request and response code and it can
be used in consuming projects by tagging request with extra settings
if needed and applying custom policy. Default policy is also exposed
for reuse.

There's already GenericClient.RESOURCE_TYPE_TAG applied by default on
sdk side, so customization by resource type + response code should be
fairly easy to implement.

Not giving it full response (and response headers) for now because
in current setup response can be shadowed by exceptions that don't
keep track of full response context. Later on if the need for response
header-based logic arises we could extend this part in some way.

TBD: it may make sense that customization for resource + code
is put in the sdk default policy if that will be a fairly certain rule.
But first let's open up for customizations

Relates to #706
Needed for #709

CDF-20260

Predicate takes `request` and `response code` and it can
be used in consuming projects by tagging request with extra settings
if needed and applying custom policy. Default policy is also exposed
for reuse.

There's already `GenericClient.RESOURCE_TYPE_TAG` applied by default on
sdk side, so customization by resource type + response code should be
fairly easy to implement.

Not giving it full response (and response headers) for now because
in current setup response can be shadowed by exceptions that don't
keep track of full response context. Later on if the need for response
header-based logic arises we could extend this part in some way.

TBD: it may make sense that customization for resource + code
     is put in the sdk default policy if that will be a fairly certain rule.
     But first let's open up for customizations
@dmivankov dmivankov requested a review from a team as a code owner November 9, 2023 13:48
@dmivankov dmivankov self-assigned this Nov 9, 2023
Copy link

codecov bot commented Nov 9, 2023

Codecov Report

Merging #708 (fad3e76) into master (d41c986) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #708      +/-   ##
==========================================
+ Coverage   73.95%   73.97%   +0.01%     
==========================================
  Files          95       95              
  Lines        2880     2882       +2     
  Branches       33       36       +3     
==========================================
+ Hits         2130     2132       +2     
  Misses        750      750              
Files Coverage Δ
...a/com/cognite/sdk/scala/sttp/RetryingBackend.scala 95.65% <100.00%> (+0.41%) ⬆️

@dmivankov dmivankov enabled auto-merge (squash) November 13, 2023 11:10
@dmivankov dmivankov changed the title Allow customizing shouldRetry in RetryingBackend CDF-20260: allow customizing shouldRetry in RetryingBackend Nov 14, 2023
Copy link

@amorken amorken left a comment

Choose a reason for hiding this comment

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

LGTM, modulo me not knowing what I'm talking about

val maybeRetry: (Option[Int], Throwable) => F[Response[T]] =
(code: Option[Int], exception: Throwable) =>
if (retriesRemaining > 0 && code.forall(shouldRetry)) {
val maybeRetry: (Option[StatusCode], Throwable) => F[Response[T]] =
Copy link

Choose a reason for hiding this comment

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

💯 proper types are key to making lambda function signatures readable.

@dmivankov dmivankov merged commit edc64ce into master Nov 14, 2023
5 checks passed
@dmivankov dmivankov deleted the customize_retry_policy branch November 14, 2023 09:22
@amorken
Copy link

amorken commented Nov 14, 2023

Uh I didn't realize my +1 would cause an automerge 😅

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.

2 participants