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

Include request headers in client.Info #4547

Merged
merged 21 commits into from
Jan 13, 2022

Conversation

disq
Copy link
Contributor

@disq disq commented Dec 13, 2021

Description: Exposes HTTP headers from the originating request in the client.Info struct, to be passed on to processors.

This was suggested in the contrib issue open-telemetry/opentelemetry-collector-contrib#6700
I tried to keep it in-line with the Header field in http.Request (and grpc metadata.MD) as possible (so I just used map[string][]string in an immutable struct with a getter)

Closes #2401

@disq disq requested review from a team and codeboten December 13, 2021 18:55
@jpkrohling jpkrohling self-requested a review December 14, 2021 08:30
@jpkrohling jpkrohling self-assigned this Dec 14, 2021
Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

This looks like a good start, but we are missing:

@disq disq requested a review from jpkrohling December 14, 2021 11:47
Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

LGTM

@codecov
Copy link

codecov bot commented Dec 14, 2021

Codecov Report

Merging #4547 (8fb3a30) into main (2317957) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4547      +/-   ##
==========================================
+ Coverage   90.52%   90.54%   +0.02%     
==========================================
  Files         179      179              
  Lines       10638    10663      +25     
==========================================
+ Hits         9630     9655      +25     
  Misses        785      785              
  Partials      223      223              
Impacted Files Coverage Δ
client/client.go 100.00% <100.00%> (ø)
config/configgrpc/configgrpc.go 92.57% <100.00%> (+0.30%) ⬆️
config/confighttp/clientinfohandler.go 100.00% <100.00%> (ø)
config/confighttp/confighttp.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2317957...8fb3a30. Read the comment docs.

@bogdandrutu
Copy link
Member

@disq @jpkrohling can we document better the motivation of this?

@disq
Copy link
Contributor Author

disq commented Dec 19, 2021

@bogdandrutu Since I'm running the collector behind a load balancer, my motivation is actually same one as having the net.Addr in the client.Info: having access to the "real" client IP in the processor.

There are other motivations such as running a multi-tenant infra to distinguish between tenants without having to inject something in the actual OTLP data, which is documented in #2401

@jpkrohling
Copy link
Member

@disq @jpkrohling can we document better the motivation of this?

I linked #2401 to this, which should provide enough background on the request.

@disq disq force-pushed the feat/cxn-metadata branch from 4a03aaa to 0979e5e Compare December 20, 2021 11:05
Copy link
Member

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

Apart from a typo and improved godoc for the new property, this looks good to me.

config/confighttp/clientinfohandler.go Outdated Show resolved Hide resolved
config/confighttp/confighttp.go Outdated Show resolved Hide resolved
config/configgrpc/configgrpc.go Outdated Show resolved Hide resolved
disq and others added 3 commits January 3, 2022 13:29
Co-authored-by: Juraci Paixão Kröhling <[email protected]>
Co-authored-by: Juraci Paixão Kröhling <[email protected]>
Co-authored-by: Juraci Paixão Kröhling <[email protected]>
@jpkrohling
Copy link
Member

There's a test failure here:

=== RUN   TestContextWithClient/existing_client_with_metadata,_no_metadata_processing
    configgrpc_test.go:660: 
        	Error Trace:	configgrpc_test.go:660
        	Error:      	Not equal: 
        	            	expected: client.Info{Addr:net.Addr(nil), Auth:client.AuthData(nil), Metadata:map[string][]string(nil)}
        	            	actual  : client.Info{Addr:net.Addr(nil), Auth:client.AuthData(nil), Metadata:map[string][]string{"test-metadata-key":[]string{"test-value"}}}
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -3,3 +3,7 @@
        	            	  Auth: (client.AuthData) <nil>,
        	            	- Metadata: (map[string][]string) <nil>
        	            	+ Metadata: (map[string][]string) (len=1) {
        	            	+  (string) (len=17) "test-metadata-key": ([]string) (len=1) {
        	            	+   (string) (len=10) "test-value"
        	            	+  }
        	            	+ }
        	            	 }
        	Test:       	TestContextWithClient/existing_client_with_metadata,_no_metadata_processing

@jpkrohling
Copy link
Member

@disq, you have enough approvals :-) Could you fix the changelog conflict? Once this is done, this PR will be merged.

@disq
Copy link
Contributor Author

disq commented Jan 5, 2022

@disq, you have enough approvals :-) Could you fix the changelog conflict? Once this is done, this PR will be merged.

Another conflict? Fixed

@jpkrohling
Copy link
Member

Another conflict? Fixed

Sorry about that, we do need to find a better solution for the frequent conflicts involving the changelog.

Copy link
Member

@bogdandrutu bogdandrutu 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 have to blocked this again, but I missed it. We cannot make Info (a.k.a an object in the context) mutable unless is thread-safe because the context is shared between multiple gorutines potentially.

client/client.go Outdated Show resolved Hide resolved
@disq disq requested a review from bogdandrutu January 5, 2022 20:55
client/client.go Outdated Show resolved Hide resolved
client/client.go Outdated Show resolved Hide resolved
client/client.go Outdated Show resolved Hide resolved
Comment on lines 156 to 157
// Include propagates the incoming connection's metadata to downstream consumers.
IncludeMetadata bool `mapstructure:"include_metadata,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Do we want users to be able to select which "metadata" to copy from the request? Maybe not now, but we can be safe and mark this experimental for the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Certainly doable, blindly copying all of it could be bad for memory if the request is decorated with large metadata? But that would also mean we'd have to roll our own md.Copy() or header.Clone() routines, as copying-first-then-filtering would be pointless in terms of memory.

Copy link
Member

Choose a reason for hiding this comment

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

That's why I recommend just adding a comment that this is experimental, and we should look a bit into how/if we want this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bogdandrutu added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access headers in processor
6 participants