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

Pass address attributes from balancer to creds handshaker. #3548

Merged
merged 8 commits into from
Apr 23, 2020

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Apr 17, 2020

#effectively-use-attributes

@easwars easwars requested a review from dfawley April 17, 2020 19:00
@easwars easwars added the Type: Feature New features or improvements in behavior label Apr 17, 2020
@easwars easwars added this to the 1.30 Release milestone Apr 17, 2020
balancer/balancer.go Show resolved Hide resolved
@@ -136,6 +138,9 @@ type ClientConn interface {
// NewSubConn is called by balancer to create a new SubConn.
// It doesn't block and wait for the connections to be established.
// Behaviors of the SubConn can be controlled by options.
//
// Attributes field in resolver.Address can be used to pass arbitrary data
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe this needs to be documented specifically. The Attributes should be expected to find their way anywhere the Address is plumbed.

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.

clientconn.go Outdated
Comment on lines 1275 to 1276
// Balancer implementations can specify arbitrary data in the Attributes
// field of resolver.Address, which is shoved into connectCtx that is passed
Copy link
Member

Choose a reason for hiding this comment

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

The resolver also produces attributes.

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
// to the transport layer. The transport layer passes the same context to
// the credential handshaker. This makes is possible for address specific
// arbitrary data from balancers to reach the credential handshaker.
connectCtx = credentials.WithAddressInfo(connectCtx, credentials.AddressInfo{Attr: addr.Attributes})
Copy link
Member

Choose a reason for hiding this comment

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

I can't decide whether this should happen here or in the transport. We give the transport the address already, so this is somewhat redundant here. Credentials are partially a grpc concept but also are transport dependent. I.e. with custom transports, an in-process implementation won't support transport credentials (it's not a byte transport so doesn't make sense).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we have the transport layer do it, then every transport implementation would have to do it, right. And for transports that don't support transportCredentials, this should still work (although it would be wasted effort here). But it should not affect correctness, right. Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah this is not about "functional correctness", but "design correctness" - making the right component responsible for doing the work.

If the API for ClientHandshake was to pass resolver.Address, which is how we'd design it now if we could, then we wouldn't do this at all. So then the question is, which component "owns" the ClientHandshake API? gRPC or Transport(s)? Another consideration: we already pass some information to the per-RPC credentials via context, and that is done in the transport. So putting this here and that there is a little inconsistent as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to the transport layer. So, there are no diffs now in clientconn.go

@@ -193,6 +194,31 @@ func RequestInfoFromContext(ctx context.Context) (ri RequestInfo, ok bool) {
return
}

// AddressInfo contains address related data attached to the context passed to
// ClientHandshake. This makes it possible for balancer implementations to pass
Copy link
Member

Choose a reason for hiding this comment

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

As before, "balancer, resolver, grpc, etc". There's a flow of data here that the balancer and handshaker are only parts of.

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.

credentials/credentials.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@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.

Also added a test in transport_test.go. The other test in balancer_test.go does very similar things to this one, but the former is more like a unit test with the latter being an e2e test.

@easwars
Copy link
Contributor Author

easwars commented Apr 21, 2020

Ping ...

// ClientHandshakeInfo in a context.
type clientHandshakeInfoKey struct{}

// WithClientHandshakeInfo returns a copy of parent with chi stored as a value.
Copy link
Member

Choose a reason for hiding this comment

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

//
// This API is EXPERIMENTAL.

And below please.

Actually, this one is for internal use only, correct? Let's follow the same pattern as RequestInfo if so:

https://github.com/grpc/grpc-go/blob/master/internal/internal.go#L42:1

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.

credentials/credentials.go Show resolved Hide resolved
@dfawley dfawley assigned easwars and unassigned dfawley Apr 22, 2020
@easwars easwars assigned dfawley and unassigned easwars Apr 22, 2020
credentials/credentials.go Outdated Show resolved Hide resolved
credentials/credentials.go Outdated Show resolved Hide resolved

const attrBalancerName = "attribute-balancer"

// attrBalancerBuilder builds a balancer and passes the attribute key and value
Copy link
Member

Choose a reason for hiding this comment

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

Do you think you would be able to use the stub balancer instead:
https://github.com/grpc/grpc-go/pull/3431/files#diff-ef2472da4a075e04e3580d038b3e14aa

If so, please use it (and add it to this PR, since the other PR will take another week or so to submit).

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.

I had to embed the balancer.Balancer interface though to get it to compile. But I added a TODO there to remove it once the above mentioned PR goes in.

Copy link
Member

Choose a reason for hiding this comment

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

Cool, I'm glad it worked out, thanks.

}
return nil
}
func (b *bal) ResolverError(e error) {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a blank line between these functions, and below.

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.


const attrBalancerName = "attribute-balancer"

// attrBalancerBuilder builds a balancer and passes the attribute key and value
Copy link
Member

Choose a reason for hiding this comment

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

Cool, I'm glad it worked out, thanks.

@dfawley dfawley assigned easwars and unassigned dfawley Apr 23, 2020
@easwars easwars merged commit 6a3c038 into grpc:master Apr 23, 2020
@easwars easwars deleted the creds_in_attributes branch April 23, 2020 18:03
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants