-
Notifications
You must be signed in to change notification settings - Fork 4.5k
stats/opentelemetry: record retry attempts from clientStream #8342
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
base: master
Are you sure you want to change the base?
stats/opentelemetry: record retry attempts from clientStream #8342
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
🚀 New features to boost your workflow:
|
stream.go
Outdated
@@ -430,6 +432,7 @@ func (cs *clientStream) newAttemptLocked(isTransparent bool) (*csAttempt, error) | |||
IsServerStream: cs.desc.ServerStreams, | |||
IsTransparentRetryAttempt: isTransparent, | |||
} | |||
ctx = context.WithValue(ctx, clientStreamKey{}, cs.numRetries) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as @dfawley suggested, we should just compute the retry attempts within otel interceptors #8299 (comment). While incrementing in trace.go, we should just skip if transparent retry is true. Re-using cs.numRetries
is not advisable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Updated to compute retry attempts in the otel interceptor (TagRPC) and no longer using cs.numRetries
stats/opentelemetry/trace.go
Outdated
// Note: Go always added Client and FailFast attributes even though they are not | ||
// defined by the OpenCensus gRPC spec. Thus, they are unimportant for | ||
// correctness. | ||
span.SetAttributes( | ||
attribute.Bool("Client", rs.Client), | ||
attribute.Bool("FailFast", rs.FailFast), | ||
attribute.Int64("previous-rpc-attempts", int64(ai.previousRPCAttempts)), | ||
attribute.Int64("retry-attempts", int64(atomic.LoadUint32(&ai.explicitRetryCount))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't be adding a new attribute. previous-rpc-attempts
should be enough to depict retries. If > 0, that means there were retries. You should be doing the increment here if transparent-retry is false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/grpc/proposal/blob/master/A72-open-telemetry-tracing.md#tracing-information. We should be confined to attributes defined here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -121,6 +122,10 @@ func (h *clientTracingHandler) HandleConn(context.Context, stats.ConnStats) {} | |||
// TagRPC implements per RPC attempt context management for traces. | |||
func (h *clientTracingHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context { | |||
ctx, ai := getOrCreateRPCAttemptInfo(ctx) | |||
if ai.previousRPCAttempts > 0 { | |||
atomic.AddUint32(&ai.explicitRetryCount, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retry attempts need to be counted by storing data in the context in a per-call interceptor. If you store it in the attemptInfo, it will get reset every attempt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if ai.previousRPCAttempts > 0 { | ||
atomic.AddUint32(&ai.explicitRetryCount, 1) | ||
} | ||
atomic.AddUint32(&ai.previousRPCAttempts, 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can maintain single attribute. Either previousRPCAttempts or explicitRetryCount. Why do we need both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I've removed explicitRetryCount and now use only previousRPCAttempts to track retries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember we had separate tests for retries. This change should only affect that test. This change shouldn't affect tests which are doing only single attempt.
// TagRPC implements per RPC attempt context management for traces. | ||
func (h *clientTracingHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) context.Context { | ||
ctx, ai := getOrCreateRPCAttemptInfo(ctx) | ||
var counter *int32 | ||
if val := ctx.Value(retryCountKey{}); val != nil { | ||
counter = val.(*int32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this again seems wrong. We should create the retry count key in the interceptor call which is per RPC. TagRPC is for per attempt. Here we should only retrieve the current retry count value (if needed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification. I've updated the code accordingly — the retry count key is now created within the interceptor to ensure it's per-RPC
stats/opentelemetry/trace.go
Outdated
if !rs.IsTransparentRetryAttempt { | ||
if val := ai.ctx.Value(retryCountKey{}); val != nil { | ||
// Atomic increment and get new value | ||
retryCount = uint32(atomic.AddInt32(val.(*int32), 1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this value needs to be set back to context somewhere? otherwise we have lost the count.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
stats/opentelemetry/trace.go
Outdated
// Note: Go always added Client and FailFast attributes even though they are not | ||
// defined by the OpenCensus gRPC spec. Thus, they are unimportant for | ||
// correctness. | ||
span.SetAttributes( | ||
attribute.Bool("Client", rs.Client), | ||
attribute.Bool("FailFast", rs.FailFast), | ||
attribute.Int64("previous-rpc-attempts", int64(ai.previousRPCAttempts)), | ||
attribute.Int64("previous-rpc-attempts", int64(retryCount)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note as per https://github.com/grpc/proposal/blob/master/A72-open-telemetry-tracing.md#tracing-information, previousRPCAttempts is the count of retries before current, so we should set here the existing retryCount value (before incrementing it). However, we should increment retry count after and set back to context for future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
stats/opentelemetry/e2e_test.go
Outdated
@@ -928,7 +928,7 @@ func (s) TestMetricsAndTracesOptionEnabled(t *testing.T) { | |||
}, | |||
{ | |||
Key: "previous-rpc-attempts", | |||
Value: attribute.IntValue(0), | |||
Value: attribute.IntValue(1), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be correctly 0 because it counts previous rpc attempts which means before current so for the first attempt it should be 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Fixes: #8299
RELEASE NOTES:
grpc.previous-rpc-attempts
) are now recorded as span attributes for non-transparent client retries.