Skip to content
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

Merged
merged 9 commits into from
Jul 10, 2024

Conversation

townba
Copy link
Contributor

@townba townba commented Jul 2, 2024

  • Add SubConnState.connectedAddress field.
  • Add internal.GetConnectedAddress and internal.SetConnectedAddress accessor function vars to get and set SubConnState.connectedAddress.
  • Set the connected address in acBalancerWrapper.updateState when connectivity state is Ready.
  • Read the connected address in the subconn StateListener and call updateLocalityID() based on that address's locality.
  • Modify addrConn to store the full resolver.Address rather than one with BalancerAttributes removed.
  • Modify a test to check for the new correct behavior.

Fixes #7339

RELEASE NOTES:

  • TBD

balancer_wrapper.go Outdated Show resolved Hide resolved
xds/internal/balancer/clusterimpl/clusterimpl.go Outdated Show resolved Hide resolved
xds/internal/balancer/clusterimpl/clusterimpl.go Outdated Show resolved Hide resolved
xds/internal/balancer/clusterimpl/clusterimpl.go Outdated Show resolved Hide resolved
balancer/balancer.go Outdated Show resolved Hide resolved
xds/internal/balancer/clusterimpl/clusterimpl.go Outdated Show resolved Hide resolved
@arjan-bal arjan-bal assigned townba and unassigned arjan-bal Jul 2, 2024
@easwars easwars changed the title xds: Use the connected address for locality xds: use locality from the connected address for load reporting Jul 2, 2024
Copy link
Contributor

@easwars easwars left a 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

balancer/balancer.go Outdated Show resolved Hide resolved
balancer/balancer.go Outdated Show resolved Hide resolved
balancer_wrapper.go Outdated Show resolved Hide resolved
balancer_wrapper.go Outdated Show resolved Hide resolved
balancer_wrapper.go Outdated Show resolved Hide resolved
xds/internal/balancer/clusterimpl/clusterimpl.go Outdated Show resolved Hide resolved
xds/internal/balancer/clusterimpl/clusterimpl.go Outdated Show resolved Hide resolved
xds/internal/balancer/clusterimpl/clusterimpl.go Outdated Show resolved Hide resolved
xds/internal/balancer/clusterimpl/clusterimpl.go Outdated Show resolved Hide resolved
xds/internal/balancer/clusterimpl/clusterimpl.go Outdated Show resolved Hide resolved
clientconn.go Outdated Show resolved Hide resolved
clientconn.go Outdated Show resolved Hide resolved
clientconn.go Outdated Show resolved Hide resolved
clientconn.go Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jul 2, 2024

Codecov Report

Attention: Patch coverage is 94.73684% with 2 lines in your changes missing coverage. Please review.

Project coverage is 81.34%. Comparing base (c9caa9e) to head (64ae662).
Report is 9 commits behind head on master.

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     
Files Coverage Δ
balancer/balancer.go 95.45% <100.00%> (+1.70%) ⬆️
balancer_wrapper.go 88.74% <100.00%> (+2.25%) ⬆️
clientconn.go 93.34% <100.00%> (+0.19%) ⬆️
xds/internal/internal.go 73.91% <100.00%> (+2.48%) ⬆️
xds/internal/balancer/clusterimpl/clusterimpl.go 86.40% <85.71%> (-1.33%) ⬇️

... and 28 files with indirect coverage changes

@townba
Copy link
Contributor Author

townba commented Jul 2, 2024

PTAL

Copy link
Contributor

@easwars easwars left a 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.

balancer/balancer.go Outdated Show resolved Hide resolved
balancer/balancer.go Outdated Show resolved Hide resolved
clientconn.go Outdated Show resolved Hide resolved
clientconn.go Outdated
@@ -924,12 +918,18 @@ func (ac *addrConn) connect() error {
return nil
}

func equalAddress(a, b resolver.Address) bool {
Copy link
Contributor

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 { ... }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

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?

Copy link
Contributor Author

@townba townba Jul 10, 2024

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.

internal/internal.go Outdated Show resolved Hide resolved
internal/internal.go Outdated Show resolved Hide resolved
xds/internal/internal.go Outdated Show resolved Hide resolved
internal/testutils/balancer.go Outdated Show resolved Hide resolved
xds/internal/balancer/clusterimpl/clusterimpl.go Outdated Show resolved Hide resolved
@easwars easwars added this to the 1.66 Release milestone Jul 8, 2024
@easwars easwars removed their assignment Jul 8, 2024
@townba
Copy link
Contributor Author

townba commented Jul 8, 2024

PTAL

@easwars easwars self-assigned this Jul 9, 2024
@easwars easwars assigned dfawley and unassigned townba Jul 9, 2024
Copy link
Member

@dfawley dfawley left a 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.

connectedAddress resolver.Address
}

func (lhs SubConnState) Equal(rhs SubConnState) bool {
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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?

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 {
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 76 to 77
// 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.
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Member

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)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dfawley dfawley removed their assignment Jul 10, 2024
@easwars easwars merged commit 9c5b31d into grpc:master Jul 10, 2024
12 of 13 checks passed
@townba townba deleted the connectedaddr branch July 10, 2024 23:24
printchard pushed a commit to printchard/grpc-go that referenced this pull request Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If a priority contains multiple localities with pick_first, load is reported incorrectly
5 participants