-
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
balancer/pickfirst: Add pick first metrics #7839
Conversation
1cca48a
to
e214b5f
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7839 +/- ##
=======================================
Coverage 81.92% 81.93%
=======================================
Files 375 375
Lines 37979 38007 +28
=======================================
+ Hits 31114 31140 +26
- Misses 5572 5575 +3
+ Partials 1293 1292 -1
|
Would you mind reviewing this @arjan-bal? |
Thanks for the pass Easwar, I did this work with Doug who knows a lot more about the state transitions so I want to hear your input on Easwar's concerns @dfawley. |
I think it would be better for you to reply to them first @zasweq. |
} | ||
|
||
ss.Stop() | ||
if err = pollForDisconnectedMetrics(ctx, tmr); err != 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.
There is a single caller for this. Prefer getting rid of the function and inlining it 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.
The reason I had this in a separate function is I would have to do a bool local.
Switched to that. Let me know what you think.
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 don't need a boolean. If you change the body of the for
to return
when you see grpc.lb.pick_first.disconnections
(instead of breaking), then the only case where you will execute code below the for
would be when the context expires. And therefore you can check for ctx.Err() != nil
instead of checking for the boolean.
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 I return early I don't even need the ctx.Err check right? The only reason it would hit that would be for the ctx to expire without having found disconnection/returned 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.
So my failure mode is an uncondtional t.Fatalf("timeout waiting for grpc.lb.pick_first.disconnections metric").
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.
Actually, with Arjan's point about await state I can use that to poll/sync and then the metrics test can be deterministic one time check. Thanks Arjan for suggestion.
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 we should have tests for happy eyeballs cases. Did you consider enhancing existing tests to check for metric values at the end of the test? Going down that path would cover a lot of scenarios instead of very simple ones being tested 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.
I never considered that. Would you rather me write my own happy eyeballs or scale up the existing? I know there was lots of previous contention about adding too many assertions to tests.
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.
That's a good idea. I would suggest adding assertions to the same test because asserting both behaviours in the same test would give a better indication that the features work together. If this severely hampers readability, we can have separate tests.
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.
Agree with @arjan-bal.
I'm OK with it being a separate PR as well.
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.
Scaled up two basic happy eyeballs tests (in a separate commit).
Note that there is a limitation in our test metrics recorder that it only persist the most recently emitted metric value for a given metric name. The reason for this is vast non determinism in other unit tests that use this component, where the most recent was deterministic but not the total metric. It's too far down the rabbit hole now to change I think, but let me know if y'all feel strongly about trying to add a summation assertion/if you want me to add metrics assertions to more happy eyeballs tests/what you think about the additional assertions in general.
I'll be happy to add more, remove the commit, leave as is, etc.
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 added a test to the other test that test with a ClientConn, so I think that should be good enough outside the summation thing, which I don't think should be addressed in this PR if at all unless found assertions inadequate.
I saw other tests test interleaving addresses by sending TF, but figured this coverage should be good enough. Thanks for suggestion.
Thanks for the comments y'all. Got to all comments (split out implementation and testing changes in separate commits). |
@@ -57,7 +58,28 @@ var ( | |||
// Name is the name of the pick_first_leaf balancer. | |||
// It is changed to "pick_first" in init() if this balancer is to be | |||
// registered as the default pickfirst. | |||
Name = "pick_first_leaf" | |||
Name = "pick_first_leaf" | |||
disconnectionsMetric = estats.RegisterInt64Count(estats.MetricDescriptor{ |
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 one is suffixed with Metric
and the others are not. Let's be consistent.
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.
Good point. Done. The RLS/WRR metrics are also suffixed with Metric, just checked.
cc: cc, | ||
cc: cc, | ||
target: bo.Target.String(), | ||
metricsRecorder: bo.MetricsRecorder, // ClientConn will always create a Metrics Recorder so guaranteed to be non 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.
This comment seems like it's unnecessary or in the wrong place? It's not being dereferenced 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.
This was Easwar's suggestion after our back and forth: #7839 (comment). What do you think about this. I'll drop "so guaranteed to be non nil" from this one because it's documented on the field.
@@ -575,6 +607,12 @@ func (b *pickfirstBalancer) updateSubConnState(sd *scData, newState balancer.Sub | |||
// the first address when the picker is used. | |||
b.shutdownRemainingLocked(sd) | |||
b.state = connectivity.Idle | |||
// READY SubConn interspliced in between CONNECTING and IDLE, need to | |||
// account for that. | |||
if oldState == connectivity.Connecting && newState.ConnectivityState == connectivity.Idle { |
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.
+1 to something like:
if oldState == Connecting {
// A known issue causes a race that prevents the READY state change notification. This works around it.
Also it would be great if we could create an issue for that problem and link it here so we know to come back and delete this one it's resolved.
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.
Removed second conditional. Created a Github issue and linked to it.
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.
That's a good idea. I would suggest adding assertions to the same test because asserting both behaviours in the same test would give a better indication that the features work together. If this severely hampers readability, we can have separate tests.
Thanks for the passes. Got to all comments and scaled up two very basic happy eyeballs tests. Let me know what you think. |
Thanks for the comments. Great suggestions. |
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.
LGTM
This PR adds pick first metrics according to A78, and tests as well.
RELEASE NOTES: