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

credentials: add RequestInfo to context passed to GetRequestMetadata #3057

Merged
merged 12 commits into from Oct 4, 2019

Conversation

shanel-at-google
Copy link
Contributor

Add a RequestInfo struct which initially is used for passing the full request method (though could later be expanded to pass more info) so that things like GetRequestMetadata can be used to apply logic based on that data.

This is a fix for #3019

… request method (though could later be expanded to pass more info) so that things like GetRequestMetadata can be used to apply logic based on that data.

This is a fix for grpc#3019
… request method (though could later be expanded to pass more info) so that things like GetRequestMetadata can be used to apply logic based on that data.

This is a fix for grpc#3019
… request method (though could later be expanded to pass more info) so that things like GetRequestMetadata can be used to apply logic based on that data.

This is a fix for grpc#3019
… request method (though could later be expanded to pass more info) so that things like GetRequestMetadata can be used to apply logic based on that data.

This is a fix for grpc#3019
@shanel-at-google
Copy link
Contributor Author

"Continued" from #3032

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.

Mostly nits and one actual change. Otherwise LGTM

ri := credentials.RequestInfo{
Method: callHdr.Method,
}
ctx = internal.NewRequestInfoContext.(func(context.Context, credentials.RequestInfo) context.Context)(ctx, ri)
Copy link
Member

Choose a reason for hiding this comment

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

I didn't consider this initially, but.. This will leave the RequestInfo in the context for the life of the stream. Since RequestInfo is in the credentials package, let's not keep it around except when calling the credentials. If it's needed elsewhere, we might want to move RequestInfo somewhere else. I would say: let's create a new context the same place where createAudience is called, and only pass this to the get*AuthData functions.

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. Though I had to remove the unit test that tested via NewStream. So the only test coverage is via the e2e test. That said it appears that is the case for everything in the method that calls createAudience. ¯_(ツ)_/¯

Copy link
Member

Choose a reason for hiding this comment

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

I prefer API-level tests to unit tests for most things, so that's totally fine by me.

@@ -334,3 +335,27 @@ func cloneTLSConfig(cfg *tls.Config) *tls.Config {

return cfg.Clone()
}

// RequestInfo contains request data to be attached to the context passed along to GetRequestMetadata calls. This API is experimental.
Copy link
Member

Choose a reason for hiding this comment

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

  • s/to be//
  • s/along//

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.

@@ -334,3 +335,27 @@ func cloneTLSConfig(cfg *tls.Config) *tls.Config {

return cfg.Clone()
}

// RequestInfo contains request data to be attached to the context passed along to GetRequestMetadata calls. This API is experimental.
Copy link
Member

Choose a reason for hiding this comment

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

Please put "This API is experimental" on a new line, with a blank comment line between it and the rest of the comments. (And below; see Bundle in this file for an example.)

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.

@@ -334,3 +335,27 @@ func cloneTLSConfig(cfg *tls.Config) *tls.Config {

return cfg.Clone()
}

// RequestInfo contains request data to be attached to the context passed along to GetRequestMetadata calls. This API is experimental.
Copy link
Member

Choose a reason for hiding this comment

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

Let's also document on GetRequestMetadata in the PerRPCCredentials interface that the context will contain a RequestInfo retrievable via RequestInfoFromContext.

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. Let me know if you would like to change the wording.

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.

Mostly nits and one actual change. Otherwise LGTM

@dfawley dfawley self-assigned this Oct 3, 2019
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.

Sorry, one last (hopefully!!) thing.

// RequestInfoFromContext extracts the RequestInfo from the context.
//
// This API is experimental.
func RequestInfoFromContext(ctx context.Context) RequestInfo {
Copy link
Member

Choose a reason for hiding this comment

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

Bah, I missed this before, sorry: it's typical to also return an ok bool here, in case the RequestInfo is not present in ctx. Please add this. The comment can be updated to match peer.FromContext's wording by simply adding "if it exists".

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 added this to the 1.25 Release milestone Oct 3, 2019
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.

Thanks!

@dfawley dfawley merged commit 47d3cfe into grpc:master Oct 4, 2019
@dfawley dfawley changed the title Adding a RequestInfo struct for propagating request data to GetRequestMetadata calls. credentials: add RequestInfo to context passed to GetRequestMetadata Nov 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants