enable optional use of an HTTP proxy#237
Conversation
24526c9 to
942070e
Compare
|
This is a breaking change and not how we usually do things in the Prometheus ecosystem. I think it would be preferable to add a proxy URL to the URL parameters, or to a specific file (to avoid leaking secrets). |
It is a breaking change for someone who runs
This PR simply restores what would otherwise be the default behaviour of
I disagree, I don't like having every single binary invent its own way to get proxy settings. I like the standardized env-based way golang promotes in the ==== On a side note, I realize that my PR could be much shorter: diff --git a/haproxy_exporter.go b/haproxy_exporter.go
index 54b4cbb..7b44548 100644
--- a/haproxy_exporter.go
+++ b/haproxy_exporter.go
@@ -332,7 +332,10 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
}
func fetchHTTP(uri string, sslVerify bool, timeout time.Duration) func() (io.ReadCloser, error) {
- tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: !sslVerify}}
+ tr := &http.Transport{
+ Proxy: http.ProxyFromEnvironment,
+ TLSClientConfig: &tls.Config{InsecureSkipVerify: !sslVerify},
+ }
client := http.Client{
Timeout: timeout,
Transport: tr,I didn't want to push-force anything now that you've already viewed the initial version, but I'm happy to do it if you don't mind. |
|
Wheter or not it is a breaking change is not really subject of question. Someone could have a global proxy set but targetting haproxy locally which should not be proxied. In the whole Prometheus ecosystem, we do not set proxy based on environment variables. I would avoid having one exporter behaving differently than others, but I do recognize that users should be able to set proxies. What about a boolean flag --http.proxy-from-env maybe? |
942070e to
c7835da
Compare
Yes, it sounds good. I've pushed a new version with this flag. |
grobie
left a comment
There was a problem hiding this comment.
Thanks for the review @roidelapluie and the quick turnaround @thomasgl-orange. The proposed solution looks good to me, I'll leave the final review to @roidelapluie.
|
Thanks! There are linting issues. Can we keep it http.proxy-from-env? that way we could reuse it for other exporters that might need this. It also clarifies that it does not concern HAProxy when used with unix sockets. |
|
Oops, sorry for |
|
The CLI flag is now renamed Regarding linting error, I don't get any with |
roidelapluie
left a comment
There was a problem hiding this comment.
Thanks. golint will be updated by our bot, after which you will be able to rebase your PR on top of main.
|
For what it's worth (just scratching an itch), a |
|
Thanks for the review and suggestions; I've applied them all, but forgot |
|
done :) |
Signed-off-by: Thomas de Grenier de Latour <thomas.degrenierdelatour@orange.com>
Signed-off-by: Thomas de Grenier de Latour <thomas.degrenierdelatour@orange.com>
Co-authored-by: Julien Pivotto <roidelapluie@gmail.com> Signed-off-by: Thomas de Grenier de Latour <thomas.degrenierdelatour@orange.com>
62e5161 to
bfcaa67
Compare
|
Thanks, rebased :) |
|
Thanks! |
I need to run the
haproxy_exporterfrom an environment which can only reach the target haproxy stats API by going through an HTTP proxy. The wayhaproxy_exportercurrently executes its GET requests (with a customizedhttp.Transportto allow disabling TLS validation) ignores the proxy settings defined in the traditional environment variables ($HTTP(S)_PROXY,$NO_PROXY). This PR fixes that, by adding the proxy fromhttp.ProxyFromEnvironmentto thehttp.Transport. If there is no proxy env vars, or the target haproxy domain is in$NO_PROXY, the proxy will benil, and nothing changes in the way requests are executed.It can be tested, for instance, by running a local mitmproxy service, and running
haproxy_exporterwith aHTTP_PROXY=http://localhost:8080(or$HTTPS_PROXY) env var.CC @grobie, @roidelapluie