-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
stats/opentelemetry: record retry attempts from clientStream #8342
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8342 +/- ##
==========================================
- Coverage 81.64% 81.50% -0.15%
==========================================
Files 413 413
Lines 40621 40693 +72
==========================================
- Hits 33167 33166 -1
- Misses 5991 6000 +9
- Partials 1463 1527 +64
🚀 New features to boost your workflow:
|
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.
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.
@vinothkumarr227 have you tested this to ensure its working correctly? I was under impression that TestTraceSpan_WithRetriesAndNameResolutionDelay will need changes for expected values. I think its not working as expected because you are not setting the count back to ctx after incrementing.
|
|
||
| // Client-specific Begin attributes. | ||
| var previousRPCAttempts int64 | ||
| if ri.ai.previousRPCAttempts != nil { |
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.
Is it possible for this to be false?
And is there any reason this is a pointer instead of just a value? Then we wouldn't need nil checks, or to construct it explicitly.
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’s not possible for it to be nil — we always initialize it in getOrCreateCallInfo with ci.previousRPCAttempts = new(atomic.Uint32). I’ve removed the nil check as well. The pointer is used so that updates in ai are automatically reflected in ci.
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.
Oh this is in the attemptInfo. Why are we keeping it here instead of just loading it out of the callInfo?
Also I realized that with hedging, the previous attempts accounting is racy:
- Attempt 1 starts
- Attempt 2 starts
- Attempt 3 starts
- All attempts do
Beginsimultaneously
It's possible for any of them to have any value now. You need to instead increment and read together:
previousAttempts := previousRPCAttempts.Add(1) - 1 // Add returns the new value; we need the old valueThen they will all see unique values.
(We don't implement hedging yet, but we need to keep in mind that we will one day.)
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.
previousRPCAttempts represents the number of retries before the current attempt. We should record the existing retry count in attemptInfo before incrementing it. After that, we increment the retry 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.
Also I realized that with hedging, the previous attempts accounting is racy:
- Attempt 1 starts
- Attempt 2 starts
- Attempt 3 starts
- All attempts do
BeginsimultaneouslyIt's possible for any of them to have any value now. You need to instead increment and read together:
previousAttempts := previousRPCAttempts.Add(1) - 1 // Add returns the new value; we need the old valueThen they will all see unique values.
(We don't implement hedging yet, but we need to keep in mind that we will one day.)
Sure, I’ll keep that in mind; we’ll do it in a future update.
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.
previousRPCAttempts represents the number of retries before the current attempt. We should record the existing retry count in attemptInfo before incrementing it. After that, we increment the retry count.
No, we need to atomically read and increment it, as I explained.
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.
Hi Doug, I’m a bit confused. Initially, I had the increment here — https://github.com/grpc/grpc-go/blob/master/stats/opentelemetry/client_metrics.go#L78 — but after the review comments, I’m moved to trace. Could you clarify what exactly you’d like to change 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.
If we do the load and add separately, there is a race if multiple attempts are happening at once, with hedging. So we need to do the add and use the value it returns. It returns the incremented value, so we need to subtract 1 from it to get the original value. This way if multiple attempts are happening at the same time, then each one will get a unique value.
I think we should also see about removing the previousRPCAttempts pointer from the attemptInfo, and instead read it out of the callInfo, which is stored in the context too, right?
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 suggestion! I'll update the code accordingly. I'll also double-check how it's stored in the context.
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.
If we do the load and add separately, there is a race if multiple attempts are happening at once, with hedging. So we need to do the add and use the value it returns. It returns the incremented value, so we need to subtract 1 from it to get the original value. This way if multiple attempts are happening at the same time, then each one will get a unique value.
I think we should also see about removing the previousRPCAttempts pointer from the attemptInfo, and instead read it out of the callInfo, which is stored in the context too, right?
Thanks for the feedback! I've updated the code.
| // Client-specific Begin attributes. | ||
| var previousRPCAttempts int64 | ||
| if ri.ai.previousRPCAttempts != nil { | ||
| previousRPCAttempts = int64(ri.ai.previousRPCAttempts.Load()) |
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.
Why are we loading this here but only using it inside the if below? Why not load only when 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.
No need for the condition — I’ve removed the nil check as well.
| attribute.Bool("Client", begin.Client), | ||
| attribute.Bool("FailFast", begin.FailFast), |
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.
Let's remove these now since they are not part of the spec
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
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.
Sorry for the delays in review here. LGTM after this one small change.
| method: determineMethod(method, opts...), | ||
| target: cc.CanonicalTarget(), | ||
| method: determineMethod(method, opts...), | ||
| previousRPCAttempts: new(atomic.Uint32), |
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.
Let's make this a non-pointer type and then we don't need the new here or the chance to get nil panics.
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
| target: cc.CanonicalTarget(), | ||
| method: determineMethod(method, opts...), | ||
| previousRPCAttempts: new(atomic.Uint32), | ||
| previousRPCAttempts: atomic.Uint32{}, |
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 delete this line. This is the zero value so it doesn't need explicit initialization.
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
…8342)" (#8571) This introduced flakiness in a test - Test/TraceSpan_WithRetriesAndNameResolutionDelay Failure: https://github.com/grpc/grpc-go/actions/runs/17614152882/job/50042942932?pr=8547 Related issue: #8299 RELEASE NOTES: None
Fixes: #8299
RELEASE NOTES:
grpc.previous-rpc-attempts) are now recorded as span attributes for non-transparent client retries.