Skip to content

credentials: expose NewRequestInfoContext publicly #8198

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

Merged
merged 4 commits into from
Apr 21, 2025

Conversation

vadimsht
Copy link
Contributor

@vadimsht vadimsht commented Mar 24, 2025

The primary use case is to allow testing PerRPCCredentials implementations that live outside of google.golang.org/grpc.

The secondary (somewhat weirder) use case is to allow reusing existing PerRPCCredentials implementations (as long as they don't depend on handshake details) outside of the standard gRPC client environment (i.e. with alternative implementations of grpc.ClientConnInterface that reuse gRPC code generator machinery and APIs, but don't use the actual implementations).

Fixes #8080.

RELEASE NOTES:

  • credentials: add NewContextWithRequestInfo to allow testing PerRPCCredentials implementations.

The primary use case is to allow testing PerRPCCredentials
implementations that live outside of google.golang.org/grpc.

The secondary (somewhat weirded) use case is to allow reusing
existing PerRPCCredentials implementations (as long as they
don't depend on handshake details) outside of the standard
gRPC client environment (i.e. with alternative implementations
of grpc.ClientConnInterface that reuse gRPC code generator
machinery and APIs, but don't use the actual implementations).
Copy link

linux-foundation-easycla bot commented Mar 24, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

codecov bot commented Mar 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.01%. Comparing base (a51009d) to head (0114207).
Report is 29 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8198      +/-   ##
==========================================
+ Coverage   81.91%   82.01%   +0.10%     
==========================================
  Files         410      412       +2     
  Lines       40216    40475     +259     
==========================================
+ Hits        32942    33195     +253     
- Misses       5894     5905      +11     
+ Partials     1380     1375       -5     
Files with missing lines Coverage Δ
credentials/credentials.go 88.57% <100.00%> (+0.69%) ⬆️
internal/credentials/credentials.go 100.00% <ø> (ø)
internal/transport/http2_client.go 92.07% <100.00%> (+0.22%) ⬆️

... and 70 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eshitachandwani eshitachandwani added this to the 1.72 Release milestone Apr 1, 2025
@vadimsht
Copy link
Contributor Author

vadimsht commented Apr 1, 2025

Updated. PTAL. Let me know if you want to me to revert other changes to icredentials.NewRequestInfoContext

@eshitachandwani
Copy link
Member

looks good to me , adding @dfawley for another review.

@eshitachandwani eshitachandwani requested a review from dfawley April 2, 2025 09:49
@eshitachandwani eshitachandwani assigned dfawley and unassigned vadimsht Apr 2, 2025
@vadimsht
Copy link
Contributor Author

vadimsht commented Apr 2, 2025

Looks like the presubmit check wants "RELEASE NOTES". Please review/modify the line I've added to the description. Not sure how prominently this change should be highlighted in the notes (if at all).

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.

LGTM except for these comments

//
// This API is experimental.
func NewRequestInfoContext(ctx context.Context, ri RequestInfo) context.Context {
return icredentials.NewRequestInfoContext(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.

Can we move the internal functions here instead of passing calls through?

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, but internal/credentials/credentials.go still remains since it still has ClientHandshakeInfoFromContext and NewClientHandshakeInfoContext. Removing it will require making NewClientHandshakeInfoContext public as well.

Do you want me to do this?

Strictly speaking it may also be useful for testing PerRPCCredentials.

Copy link
Member

Choose a reason for hiding this comment

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

I would be fine with this, too, if you are interested in doing it. The same caveats would apply: it should only be used for testing. But if you don't need it, then nobody else has asked, so I'm fine with waiting until someone needs it, 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.

I looked into how ClientHandshakeInfoFromContext is used (by actual prod code) and it is only used by xDS credentials implementation. I think for xds-related tests outside of grpc package (if any) to be useful, they will need access to other xDS internal parts (internal/xds package). For that reason I think it makes little sense to make it public now (also no one really needs it public).

Comment on lines 218 to 219
// NewRequestInfoContext creates a new context with the given RequestInfo
// attached to it.
Copy link
Member

Choose a reason for hiding this comment

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

NewContextWithRequestInfo attaches the RequestInfo to ctx?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose "creates a new context with ... attached" because many other existing functions are documented that way:

// NewIncomingContext creates a new context with incoming md attached.
// NewOutgoingContext creates a new context with outgoing md attached.
// NewContext creates a new context with peer information attached.
// NewContextWithServerTransportStream creates a new context from ctx and attaches stream to it.

Copy link
Member

Choose a reason for hiding this comment

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

Of these, the last one is most accurate. I'm also fine with creates a new context from ctx and attaches ri to it, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to NewContextWithRequestInfo creates a new context from ctx and attaches ri to it.

@dfawley dfawley assigned vadimsht and unassigned dfawley Apr 3, 2025
@vadimsht vadimsht requested a review from dfawley April 8, 2025 21:51
@arjan-bal arjan-bal assigned dfawley and unassigned vadimsht Apr 14, 2025
@dfawley dfawley assigned vadimsht and unassigned dfawley Apr 16, 2025
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.

Thank you!

@dfawley dfawley merged commit f7d488d into grpc:master Apr 21, 2025
15 checks passed
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.

Expose credentials.NewRequestInfoContext as a public (experimental) API
3 participants