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 hostname parameter #823

Merged
merged 3 commits into from
Nov 11, 2021

Conversation

anemyte
Copy link
Contributor

@anemyte anemyte commented Sep 11, 2021

This is refactoring of #816
As per the design doc, the exporter now accept hostname parameter, which sets Host header for HTTP probes. It also sets TLS server name (if it is not already defined by module configuration) to avoid TLS handshake problems when target is an IP address. Setting Host with both module configuration and hostname parameter results in 400 Bad Request.

Signed-off-by: anemyte <[email protected]>
@anemyte
Copy link
Contributor Author

anemyte commented Sep 11, 2021

@roidelapluie please look

@roidelapluie
Copy link
Member

Yes sorry, I am a bit behind but will followup shortly.

@imneov
Copy link

imneov commented Oct 13, 2021

My suggestion is to use the following method:

  • Expose as HTTP query param as well:
http://127.0.0.1:9115/probe?target=214.32.12.4&module=http_2xx&HTTP.hostname=prometheus.io
http://127.0.0.1:9115/probe?target=214.32.12.4&module=http_2xx&HTTP.header.field_a=value_a&HTTP.header.field_b=value_b
  • Expose DNS domain as HTTP query param.
http://127.0.0.1:9115/probe?target=8.8.8.8&module=dns&DNS.query_name=prometheus.io

In this way, the consistency of the use mode, avoid parameter conflicts, misoperation, and expandability.

@anemyte
Copy link
Contributor Author

anemyte commented Oct 13, 2021

@imneov I did it so initially for HTTP headers (see the associated PR #816). The only difference is that I used _ instead of dots: ?http_header_foo=bar.

Copy link
Member

@roidelapluie roidelapluie left a comment

Choose a reason for hiding this comment

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

Thanks, I have tested this and added my comments.

prober/http.go Outdated
}
if !changed {
// Otherwise use the hostname of the target.
httpClientConfig.TLSConfig.ServerName = targetHost
Copy link
Member

Choose a reason for hiding this comment

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

We could set it first so we do not need !changed

main.go Outdated
@@ -120,6 +120,23 @@ func probeHandler(w http.ResponseWriter, r *http.Request, c *config.Config, logg
return
}

if module.Prober == "http" {
paramHost := params.Get("hostname")
if paramHost != "" {
Copy link
Member

Choose a reason for hiding this comment

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

I do not really find this code elegant, maybe moving it to a dedicated function could help making it nicer.

main.go Outdated
}
}
}
module.HTTP.Headers["Host"] = paramHost
Copy link
Member

Choose a reason for hiding this comment

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

This is mutating the actual module, so all subsequent calls will get the same host header, if the hostname parameter is not set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review! I agree with the comments and I'll push a fix soon. However this one puzzles me because I cannot achieve the described behavior. I'll look into this anyway but it will be nice if you help me to fall into the problem. I tried myself but my tests failed to prove that parameter mutated the module. Here is a pastebin with the requests that I made; the exporter was not restarted during those tests and both debug output and server responses show that the module has not been changed.

Copy link
Member

Choose a reason for hiding this comment

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

To reproduce, please add an unrelated HTTP header to the config

Signed-off-by: anemyte <[email protected]>
@anemyte anemyte force-pushed the http_hostname_parameter branch from 9df2326 to 0d9bfa3 Compare October 30, 2021 08:06
@anemyte anemyte requested a review from roidelapluie October 30, 2021 08:14
@anemyte
Copy link
Contributor Author

anemyte commented Oct 30, 2021

@roidelapluie I've added fixes, hope it looks better now. Can you please look again?

main.go Outdated
@@ -150,6 +159,23 @@ func probeHandler(w http.ResponseWriter, r *http.Request, c *config.Config, logg
h.ServeHTTP(w, r)
}

func setHttpHost(hostname string, module *config.Module) error {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func setHttpHost(hostname string, module *config.Module) error {
func setHTTPHost(hostname string, module *config.Module) error {

@roidelapluie
Copy link
Member

Thanks! Just one nit.

Signed-off-by: anemyte <[email protected]>
@roidelapluie
Copy link
Member

Thanks!

@anemyte
Copy link
Contributor Author

anemyte commented Nov 10, 2021

Thanks!

Thank you for the review :)

@roidelapluie roidelapluie merged commit 6fcd142 into prometheus:master Nov 11, 2021
electron0zero pushed a commit that referenced this pull request Feb 1, 2023
This adds the ability to set the TLS server name for TCP probes using the hostname parameter, 
just like #823 did for HTTP probes

* add hostname parameter for tcp probe
* only add servername if TLS is true
* add even if TLS isn't true in case of STARTTLS
* added test hostname parameter with TCP probe
* remove unnecessary function and inline assignment

---------

Signed-off-by: Lyas Spiehler <[email protected]>
Co-authored-by: Lyas Spiehler <[email protected]>
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.

3 participants