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

Add support of Host header #9411

Merged
merged 6 commits into from
Feb 6, 2024

Conversation

enuret
Copy link
Contributor

@enuret enuret commented Jan 29, 2024

Closes #9395

@enuret enuret requested review from a team and jpkrohling January 29, 2024 12:29
Copy link

codecov bot commented Jan 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f5a7315) 0.00% compared to head (6ee6c08) 90.40%.

Additional details and impacted files
@@            Coverage Diff            @@
##           main    #9411       +/-   ##
=========================================
+ Coverage      0   90.40%   +90.40%     
=========================================
  Files         0      346      +346     
  Lines         0    18112    +18112     
=========================================
+ Hits          0    16374    +16374     
- Misses        0     1405     +1405     
- Partials      0      333      +333     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

I believe this needs some visible user documentation as well (readme, likely).

if found && hostHeader != "" {
// `Host` field should be set to override default `Host` header value which is Endpoint
req.Host = string(hostHeader)
}
for k, v := range interceptor.headers {
req.Header.Set(k, string(v))
Copy link
Member

Choose a reason for hiding this comment

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

would Host still be available at this point?

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, yes! It works in test that I wrote and test is broken without this change. I also just tested in my environment and it works.

Copy link
Member

Choose a reason for hiding this comment

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

I took a closer look at Go's documentation, and there's one mismatch here compared to that. Go's stdlib precedence is:

  • req.Host
  • req.URL.Host (from HTTPServerConfig.Endpoint.Host)
  • req.Headers["Host"] (from HTTPServerConfig.Headers["Host"])

Right now, we don't have an equivalent to req.Host in confighttp, so this PR introduces the following precedence order:

  • HTTPServerConfig.Headers["Host"]
  • HTTPServerConfig.Endpoint.Host

While I don't expect this to be a breaking change affecting any users at all given that this header must be explicitly set as part of the headers field, I would prefer if we'd introduce a HostHeader field, to be consistent with Go ("path of least surprise" type of thing).

But I'm not 100% convinced myself. I'd appreciate other approvers to give their opinions.

cc @open-telemetry/collector-approvers

Copy link

@MadVikingGod MadVikingGod Feb 1, 2024

Choose a reason for hiding this comment

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

The http.Request doesn't use the Headers["Host"].

// For client requests, Host optionally overrides the Host
// header to send. If empty, the Request.Write method uses
// the value of URL.Host. Host may contain an international
// domain name.
Host string

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.

I'm not 100% sure this is the way to move with this PR. Go tries to be smart by promoting the Host header to req.Host field, but at the HTTP level, it's all headers...

I'm fine with both the approach this PR takes and with adding a new field to the config specifically for the host (like Go does with the Request object).

if found && hostHeader != "" {
// `Host` field should be set to override default `Host` header value which is Endpoint
req.Host = string(hostHeader)
}
for k, v := range interceptor.headers {
req.Header.Set(k, string(v))
Copy link
Member

Choose a reason for hiding this comment

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

I took a closer look at Go's documentation, and there's one mismatch here compared to that. Go's stdlib precedence is:

  • req.Host
  • req.URL.Host (from HTTPServerConfig.Endpoint.Host)
  • req.Headers["Host"] (from HTTPServerConfig.Headers["Host"])

Right now, we don't have an equivalent to req.Host in confighttp, so this PR introduces the following precedence order:

  • HTTPServerConfig.Headers["Host"]
  • HTTPServerConfig.Endpoint.Host

While I don't expect this to be a breaking change affecting any users at all given that this header must be explicitly set as part of the headers field, I would prefer if we'd introduce a HostHeader field, to be consistent with Go ("path of least surprise" type of thing).

But I'm not 100% convinced myself. I'd appreciate other approvers to give their opinions.

cc @open-telemetry/collector-approvers

@enuret
Copy link
Contributor Author

enuret commented Jan 30, 2024

I don't mind adding a separate config, whatever community decides

@jpkrohling
Copy link
Member

I added a topic to discuss today during the SIG meeting. Feel free to join us!

https://docs.google.com/document/d/1r2JC5MB7GupCE7N32EwGEXs9V_YIsPgoFiLP4VWVMkE/edit

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.

As discussed during today's SIG meeting, we have consensus that the approach this PR originally took is the desired one.

@codeboten codeboten merged commit 0ba282a into open-telemetry:main Feb 6, 2024
46 checks passed
@github-actions github-actions bot added this to the next release milestone Feb 6, 2024
@enuret enuret deleted the otlphttpexporter_hostheader branch February 7, 2024 10:16
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.

Add support of Host header in otlphttpexporter
4 participants