From 1f1b6be78ba0a0d55a3340d61113a3150a581a18 Mon Sep 17 00:00:00 2001 From: Markus Opolka Date: Thu, 24 Aug 2023 14:16:27 +0200 Subject: [PATCH] Update default roundtripper - Add ProxyFromEnvironment configuration to enable env variables for proxy config --- README.md | 2 ++ cmd/config.go | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0ed6475..0fae6cf 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,8 @@ Flags: -v, --version version for check_prometheus ``` +The check plugin respects the environment variables `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY`. + ### Health Checks the health or readiness status of the Prometheus server. diff --git a/cmd/config.go b/cmd/config.go index 72b2397..2008b36 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -3,14 +3,16 @@ package cmd import ( "context" "fmt" - "github.com/NETWAYS/check_prometheus/internal/client" - "github.com/NETWAYS/go-check" - "github.com/prometheus/common/config" + "net" "net/http" "net/url" "strconv" "strings" "time" + + "github.com/NETWAYS/check_prometheus/internal/client" + "github.com/NETWAYS/go-check" + "github.com/prometheus/common/config" ) type AlertConfig struct { @@ -82,10 +84,13 @@ func (c *Config) NewClient() *client.Client { } var rt http.RoundTripper = &http.Transport{ - TLSClientConfig: tlsConfig, - IdleConnTimeout: 10 * time.Second, - TLSHandshakeTimeout: 10 * time.Second, - ExpectContinueTimeout: 10 * time.Second, + Proxy: http.ProxyFromEnvironment, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).DialContext, + TLSHandshakeTimeout: 10 * time.Second, + TLSClientConfig: tlsConfig, } // Using a Bearer Token for authentication