-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from 1 commit
08ebd15
32d869b
5070034
8709e78
18bce36
69acfcf
66478fb
c5a4ade
64ae662
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |
"fmt" | ||
"math" | ||
"net/url" | ||
"slices" | ||
"strings" | ||
"sync" | ||
"sync/atomic" | ||
|
@@ -918,22 +919,18 @@ func (ac *addrConn) connect() error { | |
return nil | ||
} | ||
|
||
// 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 commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Renaming the function might be an even nicer improvement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Used There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
return a.Addr == b.Addr && a.ServerName == b.ServerName && | ||
a.Attributes.Equal(b.Attributes) && | ||
a.Metadata == b.Metadata | ||
} | ||
|
||
func equalAddresses(a, b []resolver.Address) bool { | ||
if len(a) != len(b) { | ||
return false | ||
} | ||
for i, v := range a { | ||
if !equalAddress(v, b[i]) { | ||
return false | ||
} | ||
} | ||
return true | ||
return slices.EqualFunc(a, b, func(a, b resolver.Address) bool { return equalAddress(a, b) }) | ||
} | ||
|
||
// updateAddrs updates ac.addrs with the new addresses list and handles active | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,13 +371,13 @@ | |
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.GetConnectedAddress.(func(balancer.SubConnState) (resolver.Address, bool)); ok { | ||
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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} else if b.logger.V(2) { | ||
b.logger.Infof("Locality ID for %v unexpectedly empty", addr) | ||
b.logger.Infof("Locality ID for %s unexpectedly empty", addr) | ||
} | ||
} | ||
} | ||
|
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.