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

metadata: move FromOutgoingContextRaw() to internal #6765

Merged
merged 5 commits into from Jan 18, 2024

Conversation

Aditya-Sood
Copy link
Contributor

Fixes #4487

RELEASE NOTES: none

@Aditya-Sood
Copy link
Contributor Author

hi @dfawley
so I've moved the method to internal/metadata and exported the required types from the top-level metadata package
kindly let me know if any further changes are required
thanks

Copy link

codecov bot commented Nov 4, 2023

Codecov Report

Merging #6765 (26a8b06) into master (ddd377f) will increase coverage by 0.31%.
The diff coverage is 100.00%.

❗ Current head 26a8b06 differs from pull request most recent head 4494626. Consider uploading reports for the commit 4494626 to get more accurate results

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     
Files Coverage Δ
internal/transport/http2_client.go 90.92% <100.00%> (+0.30%) ⬆️
metadata/metadata.go 89.55% <100.00%> (+0.15%) ⬆️
stream.go 81.39% <100.00%> (ø)

... and 29 files with indirect coverage changes

@Aditya-Sood
Copy link
Contributor Author

I've added comments to the now exported types and an additional check on the iterations over RawMD.Added slice (on top of the "length is even" check)

the current changes effectively trade the exposition of FromOutgoingContextRaw() for two internal types becoming exported

I couldn't come up with a cleaner solution than this, since we can't export types/methods from internal/metadata; and trying to share anything from the top-level metadata package will automatically make it public

would be happy to implement a cleaner solution if you have any ideas for it

@dfawley dfawley self-requested a review November 7, 2023 18:14
@dfawley dfawley self-assigned this Nov 7, 2023
Comment on lines 155 to 157
// MDOutgoingKey is used as the key for outgoing metadata in ctx if it exists.
// For gRPC-internal use ONLY.
type MDOutgoingKey struct{}
Copy link
Member

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.

Comment on lines 279 to 282
// 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 {
Copy link
Member

Choose a reason for hiding this comment

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

Same with this 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.

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

Copy link
Member

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.

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 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?

Copy link
Member

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 */ }

Copy link

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.

@github-actions github-actions bot added the stale label Nov 22, 2023
@Aditya-Sood
Copy link
Contributor Author

hi @dfawley, could you please clarify on #6765 (comment)?

@easwars
Copy link
Contributor

easwars commented Dec 6, 2023

hi @dfawley, could you please clarify on #6765 (comment)?

Looks like @dfawley has provided clarification. Could you please take a look @Aditya-Sood. Thanks.

Copy link

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.

@github-actions github-actions bot added stale and removed stale labels Dec 12, 2023
@Aditya-Sood
Copy link
Contributor Author

hi @easwars @dfawley, sorry I was caught up at work past few days
have force-pushed a commit with the rework

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 I was caught up at work past few days

No worries! Thank you for your effort.

@@ -188,6 +188,9 @@ var (
ExitIdleModeForTesting any // func(*grpc.ClientConn) error

ChannelzTurnOffForTesting func()

// Gets the function definition from metadata package
Copy link
Member

Choose a reason for hiding this comment

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

Please fix the formatting.

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

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

Comment on lines 253 to 255
//
// This is intended for gRPC-internal use ONLY. Users should use
// FromOutgoingContext instead.
Copy link
Member

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

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.

Copy link

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.

@github-actions github-actions bot added stale and removed stale labels Dec 20, 2023
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 assigned arvindbr8 and unassigned dfawley Jan 9, 2024
@dfawley dfawley changed the title metadata: moves FromOutgoingContextRaw() to internal/metadata metadata: move FromOutgoingContextRaw() to internal Jan 9, 2024
@@ -188,6 +188,9 @@ var (
ExitIdleModeForTesting any // func(*grpc.ClientConn) error

ChannelzTurnOffForTesting func()

// Gets the function definition from metadata package
Copy link
Member

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?

Suggested change
// Gets the function definition from metadata package
// FromOutgoingContextRaw returns the un-merged, intermediary contents of metadata.rawMD.

Copy link
Contributor Author

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

@arvindbr8 arvindbr8 assigned Aditya-Sood and unassigned arvindbr8 Jan 9, 2024
Co-authored-by: Arvind Bright <arvind.bright100@gmail.com>
@dfawley dfawley assigned arvindbr8 and unassigned Aditya-Sood Jan 16, 2024
@dfawley
Copy link
Member

dfawley commented Jan 16, 2024

@Aditya-Sood Looks like gofmt needs to be run again.

@arvindbr8
Copy link
Member

@Aditya-Sood - changes looks good to me. I can approve once you push after running gofmt

@Aditya-Sood
Copy link
Contributor Author

hi @dfawley @arvindbr8, I've resolved the merge conflict with master

also I tried running go fmt . and gofmt internal/internal.go -e, but neither had any effect on any of the files - is there any other gofmt command you would like me to run?

Copy link
Member

@arvindbr8 arvindbr8 left a 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!

@arvindbr8
Copy link
Member

Thanks for your contribution @Aditya-Sood!

@arvindbr8 arvindbr8 merged commit 987df13 into grpc:master Jan 18, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

metadata: move FromOutgoingContextRaw to an internal package
4 participants