-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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: add trace event for name resolution delay #8074
base: master
Are you sure you want to change the base?
stats/opentelemetry: add trace event for name resolution delay #8074
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8074 +/- ##
==========================================
- Coverage 82.29% 82.24% -0.06%
==========================================
Files 387 387
Lines 39065 38948 -117
==========================================
- Hits 32150 32033 -117
- Misses 5584 5594 +10
+ Partials 1331 1321 -10
|
clientconn.go
Outdated
func (cc *ClientConn) waitForResolvedAddrs(ctx context.Context) error { | ||
// context expires, whichever happens first. | ||
// | ||
// If the name resolution took longer than expected (indicating a delay before |
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.
nit: If the name resolution did not succeed in first attempt, it returns true indicating delay in name resolution completion. In all other cases, including name resolution failure and name resolution succeeding in first attempt, it returns 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.
Done
stats/handlers.go
Outdated
@@ -38,6 +38,8 @@ type RPCTagInfo struct { | |||
// FailFast indicates if this RPC is failfast. | |||
// This field is only valid on client side, it's always false on server side. | |||
FailFast bool | |||
// NameResolutionDelay indicates if the RPC was delayed due to address resolution. |
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.
// NameResolutionDelay indicates if there was a delay in the name resolution.
// This field is only valid on client side, it's always false on server side.
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/opentelemetry.go
Outdated
@@ -211,6 +211,8 @@ type attemptInfo struct { | |||
countSentMsg uint32 | |||
countRecvMsg uint32 | |||
previousRPCAttempts uint32 | |||
// nameResolutionDelayed indicates if the RPC was delayed by address resolution. |
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.
same comment as above about docstring
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
stream.go
Outdated
@@ -212,9 +216,13 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth | |||
} | |||
// Provide an opportunity for the first RPC to see the first service config | |||
// provided by the resolver. | |||
if err := cc.waitForResolvedAddrs(ctx); err != nil { | |||
isDelayed, err := cc.waitForResolvedAddrs(ctx) |
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.
nit: isDelayed -> nameResDelayed/nameResolutionDelayed
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
stream.go
Outdated
return nil, err | ||
} | ||
if isDelayed { |
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 think its fine to always add the nameResolutionDelay key. It will be either true/false. That we don't have to check again and again.
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
stream.go
Outdated
@@ -416,8 +424,9 @@ func (cs *clientStream) newAttemptLocked(isTransparent bool) (*csAttempt, error) | |||
method := cs.callHdr.Method | |||
var beginTime time.Time | |||
shs := cs.cc.dopts.copts.StatsHandlers | |||
isDelayed, _ := ctx.Value(nameResolutionDelayKey).(bool) |
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.
same comment about naming the variable as above
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
stream.go
Outdated
return nil, err | ||
} | ||
if isDelayed { | ||
ctx = context.WithValue(ctx, nameResolutionDelayKey, isDelayed) |
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.
instead of adding it to context, can't we add to the rpcInfo below at line 233? and then we can pass that rpcInfo to newClientStreamWithParams. We can also just pass the bool value
Adding something less scoped like this to context has several downsides like context pollution, ambiguity, potential for misuse. It is because context is passed to different parts of application or even beyond current application
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.
Thank you for the suggestion. I’ve updated the code to move nameResolutionDelay to rpcInfo as recommended. rpcInfo is now passed to newClientStreamWithParams,
stream.go
Outdated
@@ -212,9 +216,13 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth | |||
} | |||
// Provide an opportunity for the first RPC to see the first service config | |||
// provided by the resolver. | |||
if err := cc.waitForResolvedAddrs(ctx); err != nil { | |||
isDelayed, err := cc.waitForResolvedAddrs(ctx) |
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.
returning a bool and error is not good practice for go. It breaks the established pattern of error handling in Go because returned bool indicates success/failure in general. Can we do something better? It might be fine if we can't but we can try to look for better ways.
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 have an approach as follows:
Add a nameResolutionDelay field: Add a new nameResolutionDelay field to the ClientConn struct to store the delay state.
Modify waitForResolvedAddrs: Set the nameResolutionDelay field directly in ClientConn instead of returning a boolean.
Access in newAttemptLocked: Use the nameResolutionDelay field from ClientConn within newAttemptLocked.
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 don't think we want to add the field to clientconn because clientconn is not restricted to only single rpc. Returning a struct sounds better but we don't have any other field apart from boolean field. Let's keep bool, err for now. But make sure docstring is updated to indicate the bool correctly.
t.Log("Created a ClientConn...") | ||
|
||
// First RPC should fail because there are no addresses yet. | ||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) |
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.
can you point out if there is any existing test which is enforcing the name resolution delay in this way by failing first rpc?
just to give you more context
|
Test Case 1: Fast Path (Line 699) Setup: Test Case 2: Waiting Path (Line 703) Setup: |
stats/opentelemetry: add trace event for name resolution delay.
RELEASE NOTES: None