xds: use locality from the connected address for load reporting#7378
xds: use locality from the connected address for load reporting#7378easwars merged 9 commits intogrpc:masterfrom
Conversation
easwars
left a comment
There was a problem hiding this comment.
I still haven't finished reviewing the changes in clientconn.go
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7378 +/- ##
==========================================
- Coverage 81.47% 81.34% -0.13%
==========================================
Files 348 348
Lines 26753 26757 +4
==========================================
- Hits 21796 21765 -31
- Misses 3769 3795 +26
- Partials 1188 1197 +9
|
|
PTAL |
easwars
left a comment
There was a problem hiding this comment.
Looks good. Mostly minor nits this time around.
Also, please don't mark the comments as resolved. We leave that to the reviewer who posted the original comment. That way the reviewer is not required to click "show resolved" on every comment to see if they are satisfactorily addressed. Thanks.
clientconn.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func equalAddress(a, b resolver.Address) bool { |
There was a problem hiding this comment.
Probably makes sense to add a function level comment here saying why we are not using the resolver.Address.Equal and instead defining our own. Something as simple as:
// equalAddress returns true is a and b are considered equal.
// This is different from the Equal method on the resolver.Address type
// which considers all fields to determine equality. Here, we only consider
// fields that are meaningful to the subConn.
func equalAddress(a, b resolver.Address) bool { ... }
There was a problem hiding this comment.
Renaming the function might be an even nicer improvement. equalIgnoringBalAttributes?
There was a problem hiding this comment.
Done. Used equalAddressIgnoringBalAttributes so I could also have equalAddressesIgnoringBalAttributes below.
|
PTAL |
dfawley
left a comment
There was a problem hiding this comment.
Looks good overall, just a few minor style things.
balancer/balancer.go
Outdated
| connectedAddress resolver.Address | ||
| } | ||
|
|
||
| func (lhs SubConnState) Equal(rhs SubConnState) bool { |
There was a problem hiding this comment.
Will we delete this entirely when connectedAddress is removed? If so, ignore. If not, then should this accept pointers instead?
There was a problem hiding this comment.
Removed entirely.
This was only added to get this single check in xds/internal/balancer/outlierdetection/balancer_test.go to pass, but that doesn't work if it uses pointers. I've removed this in favor of adding balancer.SubConnState{} to the cmp.AllowUnexported.
clientconn.go
Outdated
| // This is different from the Equal method on the resolver.Address type which | ||
| // considers all fields to determine equality. Here, we only consider fields | ||
| // that are meaningful to the subConn. | ||
| func equalAddress(a, b resolver.Address) bool { |
There was a problem hiding this comment.
These should probably be pointers to avoid the copy.
clientconn.go
Outdated
| return nil | ||
| } | ||
|
|
||
| func equalAddress(a, b resolver.Address) bool { |
There was a problem hiding this comment.
Renaming the function might be an even nicer improvement. equalIgnoringBalAttributes?
balancer_wrapper.go
Outdated
| acbw.stateListener(balancer.SubConnState{ConnectivityState: s, ConnectionError: err}) | ||
| scs := balancer.SubConnState{ConnectivityState: s, ConnectionError: err} | ||
| if s == connectivity.Ready { | ||
| if sca, ok := internal.SetConnectedAddress.(func(*balancer.SubConnState, resolver.Address)); ok { |
There was a problem hiding this comment.
Please define this as a global instead.
var setConnectedAddress = internal.SetConnectedAddress.(func(*.........))That way we don't have a conditional here and a runtime unknown. Instead it's an init time assertion.
| b.updateSubConnState(sc, state, oldListener) | ||
| // Read connected address and call updateLocalityID() based on the connected | ||
| // address's locality. https://github.com/grpc/grpc-go/issues/7339 | ||
| if gca, ok := internal.ConnectedAddress.(func(balancer.SubConnState) (resolver.Address, bool)); ok { |
There was a problem hiding this comment.
Same comment here -- remove the conditional and make this global, please.
balancer/balancer.go
Outdated
| // The second return value is set to to false if the state is not READY, and the | ||
| // first return value is meaningless in this case. |
There was a problem hiding this comment.
Why is anyone even calling this if the state isn't ready? Can we just say it's only valid if READY to simplify things a bit?
| if addr, ok := gca(state); ok { | ||
| lID := xdsinternal.GetLocalityID(addr) | ||
| if !lID.Empty() { | ||
| scw.updateLocalityID(lID) |
There was a problem hiding this comment.
Go style: let's try to avoid all this nesting:
StateListener = func... {
b.updateSubConnState(...)
if state != Ready {
return
}
locality := xdsinternal.GetLocalityID(getConnectedAddress(state))
if locality.Empty() {
if logger.V(2) { log }
return
}
scw.updateLocalityID(locality)
}
SubConnState.connectedAddressfield.internal.GetConnectedAddressandinternal.SetConnectedAddressaccessor functionvars to get and setSubConnState.connectedAddress.acBalancerWrapper.updateStatewhen connectivity state isReady.StateListenerand callupdateLocalityID()based on that address's locality.addrConnto store the fullresolver.Addressrather than one withBalancerAttributesremoved.Fixes #7339
RELEASE NOTES: