-
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
xds: use locality from the connected address for load reporting #7378
Conversation
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 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 |
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.
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
@@ -924,12 +918,18 @@ func (ac *addrConn) connect() error { | |||
return nil | |||
} | |||
|
|||
func equalAddress(a, b resolver.Address) 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.
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.
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.
Renaming the function might be an even nicer improvement. equalIgnoringBalAttributes
?
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. Used equalAddressIgnoringBalAttributes
so I could also have equalAddressesIgnoringBalAttributes
below.
PTAL |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should probably be pointers to avoid the copy.
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.
clientconn.go
Outdated
@@ -924,12 +918,18 @@ func (ac *addrConn) connect() error { | |||
return nil | |||
} | |||
|
|||
func equalAddress(a, b resolver.Address) 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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here -- remove the conditional and make this global, please.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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 addr, ok := gca(state); ok { | ||
lID := xdsinternal.GetLocalityID(addr) | ||
if !lID.Empty() { | ||
scw.updateLocalityID(lID) |
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.
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)
}
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.
SubConnState.connectedAddress
field.internal.GetConnectedAddress
andinternal.SetConnectedAddress
accessor functionvar
s to get and setSubConnState.connectedAddress
.acBalancerWrapper.updateState
when connectivity state isReady
.StateListener
and callupdateLocalityID()
based on that address's locality.addrConn
to store the fullresolver.Address
rather than one withBalancerAttributes
removed.Fixes #7339
RELEASE NOTES: