diff --git a/app/vmagent/remotewrite/client.go b/app/vmagent/remotewrite/client.go index 171cb896e..fc67835d8 100644 --- a/app/vmagent/remotewrite/client.go +++ b/app/vmagent/remotewrite/client.go @@ -105,11 +105,11 @@ func newHTTPClient(argIdx int, remoteWriteURL, sanitizedURL string, fq *persiste if !strings.Contains(pURL, "://") { logger.Fatalf("cannot parse -remoteWrite.proxyURL=%q: it must start with `http://`, `https://` or `socks5://`", pURL) } - urlProxy, err := url.Parse(pURL) + pu, err := url.Parse(pURL) if err != nil { logger.Fatalf("cannot parse -remoteWrite.proxyURL=%q: %s", pURL, err) } - tr.Proxy = http.ProxyURL(urlProxy) + tr.Proxy = http.ProxyURL(pu) } c := &client{ sanitizedURL: sanitizedURL, diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 637049d46..53e3614f4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,8 @@ sort: 15 * FEATURE: vmalert: allow groups with empty rules list like Prometheus does. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/1742). +* BUGFIX: vmagent: properly display `proxy_url` config option at `http://vmagent:8429/config` page. + ## [v1.68.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.68.0) diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index 40fcf6be5..31c13456b 100644 --- a/lib/promscrape/client.go +++ b/lib/promscrape/client.go @@ -77,10 +77,11 @@ func newClient(sw *ScrapeWork) *client { if isTLS { tlsCfg = sw.ProxyAuthConfig.NewTLSConfig() } + proxyURLOrig := proxyURL getProxyAuthHeader = func() string { - return proxyURL.GetAuthHeader(sw.ProxyAuthConfig) + return proxyURLOrig.GetAuthHeader(sw.ProxyAuthConfig) } - proxyURL = proxy.URL{} + proxyURL = &proxy.URL{} } if !strings.Contains(host, ":") { if !isTLS { @@ -107,8 +108,8 @@ func newClient(sw *ScrapeWork) *client { } var sc *http.Client var proxyURLFunc func(*http.Request) (*url.URL, error) - if proxyURL := sw.ProxyURL.URL(); proxyURL != nil { - proxyURLFunc = http.ProxyURL(proxyURL) + if pu := sw.ProxyURL.URL(); pu != nil { + proxyURLFunc = http.ProxyURL(pu) } sc = &http.Client{ Transport: &http.Transport{ diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index 39da2536b..ea8f92e84 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -125,7 +125,7 @@ type ScrapeConfig struct { Scheme string `yaml:"scheme,omitempty"` Params map[string][]string `yaml:"params,omitempty"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` - ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` + ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"` RelabelConfigs []promrelabel.RelabelConfig `yaml:"relabel_configs,omitempty"` MetricRelabelConfigs []promrelabel.RelabelConfig `yaml:"metric_relabel_configs,omitempty"` SampleLimit int `yaml:"sample_limit,omitempty"` @@ -796,7 +796,7 @@ type scrapeWorkConfig struct { metricsPath string scheme string params map[string][]string - proxyURL proxy.URL + proxyURL *proxy.URL proxyAuthConfig *promauth.Config authConfig *promauth.Config honorLabels bool diff --git a/lib/promscrape/discovery/consul/consul.go b/lib/promscrape/discovery/consul/consul.go index 3d8ac4a9f..671540f8c 100644 --- a/lib/promscrape/discovery/consul/consul.go +++ b/lib/promscrape/discovery/consul/consul.go @@ -21,7 +21,7 @@ type SDConfig struct { Username string `yaml:"username"` Password string `yaml:"password"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` - ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` + ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` Services []string `yaml:"services,omitempty"` Tags []string `yaml:"tags,omitempty"` diff --git a/lib/promscrape/discovery/digitalocean/digitalocean.go b/lib/promscrape/discovery/digitalocean/digitalocean.go index 1d9dd9bca..cd756fa6f 100644 --- a/lib/promscrape/discovery/digitalocean/digitalocean.go +++ b/lib/promscrape/discovery/digitalocean/digitalocean.go @@ -24,7 +24,7 @@ var SDCheckInterval = flag.Duration("promscrape.digitaloceanSDCheckInterval", ti type SDConfig struct { Server string `yaml:"server,omitempty"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` - ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` + ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` Port int `yaml:"port,omitempty"` } diff --git a/lib/promscrape/discovery/docker/docker.go b/lib/promscrape/discovery/docker/docker.go index 70fe913be..3ad1bd61c 100644 --- a/lib/promscrape/discovery/docker/docker.go +++ b/lib/promscrape/discovery/docker/docker.go @@ -24,7 +24,7 @@ type SDConfig struct { HostNetworkingHost string `yaml:"host_networking_host,omitempty"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` - ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` + ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` // refresh_interval is obtained from `-promscrape.dockerSDCheckInterval` command-line option } diff --git a/lib/promscrape/discovery/dockerswarm/dockerswarm.go b/lib/promscrape/discovery/dockerswarm/dockerswarm.go index 8da549e65..133d9b2e0 100644 --- a/lib/promscrape/discovery/dockerswarm/dockerswarm.go +++ b/lib/promscrape/discovery/dockerswarm/dockerswarm.go @@ -24,7 +24,7 @@ type SDConfig struct { Filters []Filter `yaml:"filters,omitempty"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` - ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` + ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` // refresh_interval is obtained from `-promscrape.dockerswarmSDCheckInterval` command-line option } diff --git a/lib/promscrape/discovery/eureka/eureka.go b/lib/promscrape/discovery/eureka/eureka.go index 492ae8752..eacf51af2 100644 --- a/lib/promscrape/discovery/eureka/eureka.go +++ b/lib/promscrape/discovery/eureka/eureka.go @@ -23,7 +23,7 @@ var SDCheckInterval = flag.Duration("promscrape.eurekaSDCheckInterval", 30*time. type SDConfig struct { Server string `yaml:"server,omitempty"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` - ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` + ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` // RefreshInterval time.Duration `yaml:"refresh_interval"` // refresh_interval is obtained from `-promscrape.ec2SDCheckInterval` command-line option. diff --git a/lib/promscrape/discovery/http/http.go b/lib/promscrape/discovery/http/http.go index beb85c1a7..fb55f66d1 100644 --- a/lib/promscrape/discovery/http/http.go +++ b/lib/promscrape/discovery/http/http.go @@ -20,7 +20,7 @@ var SDCheckInterval = flag.Duration("promscrape.httpSDCheckInterval", time.Minut type SDConfig struct { URL string `yaml:"url"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` - ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` + ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` } diff --git a/lib/promscrape/discovery/kubernetes/kubernetes.go b/lib/promscrape/discovery/kubernetes/kubernetes.go index c8e9c3175..d5d96a711 100644 --- a/lib/promscrape/discovery/kubernetes/kubernetes.go +++ b/lib/promscrape/discovery/kubernetes/kubernetes.go @@ -24,7 +24,7 @@ type SDConfig struct { Role string `yaml:"role"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` - ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` + ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"` Namespaces Namespaces `yaml:"namespaces,omitempty"` Selectors []Selector `yaml:"selectors,omitempty"` diff --git a/lib/promscrape/discoveryutils/client.go b/lib/promscrape/discoveryutils/client.go index 92b2b4b9b..cbd84aaf3 100644 --- a/lib/promscrape/discoveryutils/client.go +++ b/lib/promscrape/discoveryutils/client.go @@ -49,7 +49,7 @@ type Client struct { } // NewClient returns new Client for the given args. -func NewClient(apiServer string, ac *promauth.Config, proxyURL proxy.URL, proxyAC *promauth.Config) (*Client, error) { +func NewClient(apiServer string, ac *promauth.Config, proxyURL *proxy.URL, proxyAC *promauth.Config) (*Client, error) { var u fasthttp.URI u.Update(apiServer) @@ -81,10 +81,11 @@ func NewClient(apiServer string, ac *promauth.Config, proxyURL proxy.URL, proxyA if isTLS { tlsCfg = proxyAC.NewTLSConfig() } + proxyURLOrig := proxyURL getProxyAuthHeader = func() string { - return proxyURL.GetAuthHeader(proxyAC) + return proxyURLOrig.GetAuthHeader(proxyAC) } - proxyURL = proxy.URL{} + proxyURL = &proxy.URL{} } if !strings.Contains(hostPort, ":") { port := "80" diff --git a/lib/promscrape/scrapework.go b/lib/promscrape/scrapework.go index 0563cc228..bdb038d4c 100644 --- a/lib/promscrape/scrapework.go +++ b/lib/promscrape/scrapework.go @@ -82,7 +82,7 @@ type ScrapeWork struct { Labels []prompbmarshal.Label // ProxyURL HTTP proxy url - ProxyURL proxy.URL + ProxyURL *proxy.URL // Auth config for ProxyUR: ProxyAuthConfig *promauth.Config diff --git a/lib/promscrape/statconn.go b/lib/promscrape/statconn.go index 787250bb2..96a38fe15 100644 --- a/lib/promscrape/statconn.go +++ b/lib/promscrape/statconn.go @@ -50,7 +50,7 @@ var ( stdDialerOnce sync.Once ) -func newStatDialFunc(proxyURL proxy.URL, ac *promauth.Config) (fasthttp.DialFunc, error) { +func newStatDialFunc(proxyURL *proxy.URL, ac *promauth.Config) (fasthttp.DialFunc, error) { dialFunc, err := proxyURL.NewDialFunc(ac) if err != nil { return nil, err diff --git a/lib/proxy/proxy.go b/lib/proxy/proxy.go index 30800b200..449a5aad1 100644 --- a/lib/proxy/proxy.go +++ b/lib/proxy/proxy.go @@ -23,12 +23,12 @@ type URL struct { } // MustNewURL returns new URL for the given u. -func MustNewURL(u string) URL { +func MustNewURL(u string) *URL { pu, err := url.Parse(u) if err != nil { logger.Panicf("BUG: cannot parse u=%q: %s", u, err) } - return URL{ + return &URL{ url: pu, } }