-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
metadata: move FromOutgoingContextRaw() to internal #6765
metadata: move FromOutgoingContextRaw() to internal #6765
Conversation
hi @dfawley |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #6765 +/- ##
==========================================
+ Coverage 83.51% 83.83% +0.31%
==========================================
Files 287 287
Lines 30920 30837 -83
==========================================
+ Hits 25824 25852 +28
+ Misses 4020 3939 -81
+ Partials 1076 1046 -30
|
I've added comments to the now exported types and an additional check on the iterations over the current changes effectively trade the exposition of I couldn't come up with a cleaner solution than this, since we can't export types/methods from would be happy to implement a cleaner solution if you have any ideas for it |
metadata/metadata.go
Outdated
// MDOutgoingKey is used as the key for outgoing metadata in ctx if it exists. | ||
// For gRPC-internal use ONLY. | ||
type MDOutgoingKey struct{} |
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.
Please move this to internal/metadata
and reference it from there. Ideally users should never see any of our internal symbols at all.
metadata/metadata.go
Outdated
// RawMD stores the original outgoing metadata (MD), | ||
// and the lists of kv Pairs appended to it (Added). | ||
// For gRPC-internal use ONLY. | ||
type RawMD struct { |
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.
Same with this please.
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.
hi @dfawley
moving it to internal/metadata
will create a cyclic-dependency, since RawMD.MD
comes from metadata
shall I move it to the top-level internal
directory instead? this will also require defining an internal.MD
type which will become the type definition of metadata.MD
kindly let me know
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.
MD
is just a map [string][]string
. You can redefine it in the internal/metadata
package and everything should just work.
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.
I don't think redefining metadata.MD
will work because there are functions in internal/metadata
that reference metadata.MD
in their signatures - like func Validate(md metadata.MD) error
and func Get(addr resolver.Address) metadata.MD
modifying these to use a newly defined internal.MD
would require changes from all callers of these functions - is that feasible?
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.
Oh, I see. metadata
should ideally import internal/metadata
and not the other way around. I didn't realize the existing internal/metadata
already imports metadata
.
How about this, instead, to keep things simple:
package internal
var (
// we already have a ton of these.....
FromOutgoingContextRaw any // func(ctx context.Context) (metadata.MD, [][]string, bool)
)
---
package metadata
import "internal"
func init() {
internal.FromOutgoingContextRaw = fromOutgoingContextRaw
}
func fromOutgoingContextRaw(ctx) (...) { /* impl */ }
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
hi @dfawley, could you please clarify on #6765 (comment)? |
Looks like @dfawley has provided clarification. Could you please take a look @Aditya-Sood. Thanks. |
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
6061ea3
to
c7d0145
Compare
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.
sorry I was caught up at work past few days
No worries! Thank you for your effort.
internal/internal.go
Outdated
@@ -188,6 +188,9 @@ var ( | |||
ExitIdleModeForTesting any // func(*grpc.ClientConn) error | |||
|
|||
ChannelzTurnOffForTesting func() | |||
|
|||
// Gets the function definition from metadata package |
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.
Please fix the formatting.
internal/transport/http2_client.go
Outdated
@@ -568,7 +568,8 @@ func (t *http2Client) createHeaderFields(ctx context.Context, callHdr *CallHdr) | |||
headerFields = append(headerFields, hpack.HeaderField{Name: "grpc-trace-bin", Value: encodeBinHeader(b)}) | |||
} | |||
|
|||
if md, added, ok := metadata.FromOutgoingContextRaw(ctx); ok { | |||
fromOutgoingCtxRaw := internal.FromOutgoingContextRaw.(func(context.Context) (metadata.MD, [][]string, bool)) |
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.
Please instead do:
package transport
var metadataFromOutgoingContextRaw = internal.FromOutgoingContextRaw.(func(context.Context) (metadata.MD, [][]string, bool))
and then use metadataFromOutgoingContextRaw
directly. (This way we only do the type assertion once.)
metadata/metadata.go
Outdated
// | ||
// This is intended for gRPC-internal use ONLY. Users should use | ||
// FromOutgoingContext instead. |
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.
This can be removed now.
stream.go
Outdated
@@ -184,7 +184,8 @@ func newClientStream(ctx context.Context, desc *StreamDesc, cc *ClientConn, meth | |||
// when the RPC completes. | |||
opts = append([]CallOption{OnFinish(func(error) { cc.idlenessMgr.OnCallEnd() })}, opts...) | |||
|
|||
if md, added, ok := metadata.FromOutgoingContextRaw(ctx); ok { | |||
fromOutgoingCtxRaw := internal.FromOutgoingContextRaw.(func(context.Context) (metadata.MD, [][]string, bool)) |
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.
Same as above with the transport package.
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
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.
Thanks!
internal/internal.go
Outdated
@@ -188,6 +188,9 @@ var ( | |||
ExitIdleModeForTesting any // func(*grpc.ClientConn) error | |||
|
|||
ChannelzTurnOffForTesting func() | |||
|
|||
// Gets the function definition from metadata package |
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.
Please fix formatting. We want the comment to start with the variable name. Also I feel like the comment doesnt explain what the method does, but instead talks about why this internal variable is being used.
how about something like this?
// Gets the function definition from metadata package | |
// FromOutgoingContextRaw returns the un-merged, intermediary contents of metadata.rawMD. |
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.
thanks @arvindbr8, I've merged your commit suggestion
Co-authored-by: Arvind Bright <arvind.bright100@gmail.com>
@Aditya-Sood Looks like |
@Aditya-Sood - changes looks good to me. I can approve once you push after running |
hi @dfawley @arvindbr8, I've resolved the merge conflict with master also I tried running |
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.
@Aditya-Sood -- all tests are green now. Approved!
Thanks for your contribution @Aditya-Sood! |
Fixes #4487
RELEASE NOTES: none