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

add onRetryCallback callback function #405

Merged
merged 4 commits into from
Apr 3, 2021
Merged

add onRetryCallback callback function #405

merged 4 commits into from
Apr 3, 2021

Conversation

shamil
Copy link
Contributor

@shamil shamil commented Apr 2, 2021

Implements the suggested solutoin in #356

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on! A few suggestions.

Comment on lines 51 to 53
// OnRetryCallback called in retry attempts flow, which can be used to add additiional logic when retry occurs
//
type OnRetryCallback func(attempt uint, err error)
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for both this and OnRetryCallbackContext, just merge both into OnRetryCallback with a context.Context parameter first.

Comment on lines 90 to 104
// WithOnRetryCallback sets the `OnRetryCallback` used to add additional logic when retry occurs.
func WithOnRetryCallback(fn OnRetryCallback) CallOption {
return CallOption{applyFunc: func(o *options) {
o.onRetryCallback = OnRetryCallbackContext(func(ctx context.Context, attempt uint, err error) {
fn(attempt, err)
})
}}
}

// WithOnRetryCallbackContext sets the `OnRetryCallbackContext` used to add additional logic when retry occurs.
func WithOnRetryCallbackContext(fn OnRetryCallbackContext) CallOption {
return CallOption{applyFunc: func(o *options) {
o.onRetryCallback = fn
}}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Re: merge these into one

@@ -48,6 +48,7 @@ func UnaryClientInterceptor(optFuncs ...CallOption) grpc.UnaryClientInterceptor
if lastErr == nil {
return nil
}
callOpts.onRetryCallback(callCtx, attempt, lastErr)
logTrace(parentCtx, "grpc_retry attempt: %d, got err: %v", attempt, lastErr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can make this log here the default retry callback behaviour while we're here?

Copy link
Contributor Author

@shamil shamil Apr 3, 2021

Choose a reason for hiding this comment

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

I can do it, but If we do this, we will lose this trace log once the custom callback will be set by the user.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll document that as the default behaviour so that the user knows that it will disappear if they override the callback. They can always manually add it back again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can also put this in the WithOnRetryCallback before invoking the user's logic, if this makes sense.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No I think one of the things I want to do here is allow the user to disable this log behaviour too.

Copy link
Contributor Author

@shamil shamil Apr 3, 2021

Choose a reason for hiding this comment

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

Allright. Done

Comment on lines 55 to 57
// OnRetryCallback called in retry attempts flow, which can be used to add additiional logic when retry occurs
//
// The context can be used to extract request scoped metadata and context values.
Copy link
Collaborator

Choose a reason for hiding this comment

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

After merging these, lets simplify this comment a bit too.

Suggested change
// OnRetryCallback called in retry attempts flow, which can be used to add additiional logic when retry occurs
//
// The context can be used to extract request scoped metadata and context values.
// OnRetryCallback is the type of function called when a retry occurs.

@@ -75,6 +87,22 @@ func WithBackoffContext(bf BackoffFuncContext) CallOption {
}}
}

// WithOnRetryCallback sets the `OnRetryCallback` used to add additional logic when retry occurs.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// WithOnRetryCallback sets the `OnRetryCallback` used to add additional logic when retry occurs.
// WithOnRetryCallback sets the callback to use when a retry occurs.
//
// By default, no action is performed on retry.

@codecov-io
Copy link

codecov-io commented Apr 3, 2021

Codecov Report

Merging #405 (b8a9cbc) into v2 (a79558a) will decrease coverage by 27.43%.
The diff coverage is 38.61%.

Impacted file tree graph

@@             Coverage Diff             @@
##               v2     #405       +/-   ##
===========================================
- Coverage   83.58%   56.14%   -27.44%     
===========================================
  Files          30       38        +8     
  Lines         932     1334      +402     
===========================================
- Hits          779      749       -30     
- Misses        114      514      +400     
- Partials       39       71       +32     
Impacted Files Coverage Δ
chain.go 0.00% <ø> (-90.91%) ⬇️
interceptors/auth/auth.go 100.00% <ø> (ø)
interceptors/auth/metadata.go 100.00% <ø> (ø)
interceptors/ratelimit/ratelimit.go 50.00% <0.00%> (-50.00%) ⬇️
interceptors/tags/fieldextractor.go 13.79% <0.00%> (-71.51%) ⬇️
testing/testpb/interceptor_suite.go 0.00% <0.00%> (ø)
testing/testpb/test.manual_extractfields.pb.go 0.00% <0.00%> (ø)
testing/testpb/test.manual_validator.pb.go 0.00% <0.00%> (ø)
testing/testpb/test.pb.go 36.92% <36.92%> (ø)
interceptors/logging/payload.go 67.18% <42.30%> (-15.43%) ⬇️
... and 48 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 524ce8f...b8a9cbc. Read the comment docs.

@shamil
Copy link
Contributor Author

shamil commented Apr 3, 2021

Thanks for review @johanbrandhorst
Addressed all the comments, had only one concern about making the trace log the default callback behaviour. Let me know how you want to proceed and I will make the require changes.

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

LGTM

@johanbrandhorst johanbrandhorst merged commit 0df73fc into grpc-ecosystem:v2 Apr 3, 2021
@johanbrandhorst
Copy link
Collaborator

Thanks for your contribution!

@shamil shamil deleted the retry_callback branch April 3, 2021 15:08
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