-
Notifications
You must be signed in to change notification settings - Fork 45
feat(v2): update Invoke to add retry count to context #462
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
Changes from 4 commits
c3ab7d3
38aae16
6165b00
d8b0b8f
3eba94e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,15 +31,26 @@ package gax | |
|
|
||
| import ( | ||
| "context" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/googleapis/gax-go/v2/apierror" | ||
| "google.golang.org/grpc/metadata" | ||
| ) | ||
|
|
||
| // APICall is a user defined call stub. | ||
| type APICall func(context.Context, CallSettings) error | ||
|
|
||
| // withRetryCount returns a new context with the retry count appended to | ||
| // gRPC metadata. The retry count is the number of retries that have been | ||
| // attempted. Immediately after the initial request, retry count is 0. | ||
| // Immediately after a second request (the first retry), retry count is 1. | ||
| func withRetryCount(ctx context.Context, retryCount int) context.Context { | ||
| // Add to gRPC metadata so it's visible to StatsHandlers | ||
| return metadata.AppendToOutgoingContext(ctx, "gcp.grpc.resend_count", strconv.Itoa(retryCount)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not super clear on the transport agnosticism here, as the key and comments indicate this is gRPC only. If we're going to have a different function per transport, it might be worth naming them based on the transport type. Then again this is not an exported func so this is a decision that can be punted to future PRs.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're using gRPC metadata for both transports. I can clarify that here if you like. It's also discussed somewhat in the design doc. |
||
| } | ||
|
|
||
| // Invoke calls the given APICall, performing retries as specified by opts, if | ||
| // any. | ||
| func Invoke(ctx context.Context, call APICall, opts ...CallOption) error { | ||
|
|
@@ -78,8 +89,15 @@ func invoke(ctx context.Context, call APICall, settings CallSettings, sp sleeper | |
| ctx = c | ||
| } | ||
|
|
||
| retryCount := 0 | ||
| // Feature gate: GOOGLE_SDK_GO_EXPERIMENTAL_TRACING=true | ||
| tracingEnabled := IsFeatureEnabled("TRACING") | ||
| for { | ||
| err := call(ctx, settings) | ||
| ctxToUse := ctx | ||
| if tracingEnabled { | ||
| ctxToUse = withRetryCount(ctx, retryCount) | ||
| } | ||
| err := call(ctxToUse, settings) | ||
| if err == nil { | ||
| return nil | ||
| } | ||
|
|
@@ -110,5 +128,6 @@ func invoke(ctx context.Context, call APICall, settings CallSettings, sp sleeper | |
| } else if err = sp(ctx, d); err != nil { | ||
| return err | ||
| } | ||
| retryCount++ | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.