lib/promscrape: properly show proxy_url option value at /config page

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1755
This commit is contained in:
Aliaksandr Valialkin 2021-10-26 21:21:08 +03:00
parent 51641c0840
commit 4821adfd95
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
15 changed files with 26 additions and 22 deletions

View file

@ -105,11 +105,11 @@ func newHTTPClient(argIdx int, remoteWriteURL, sanitizedURL string, fq *persiste
if !strings.Contains(pURL, "://") { if !strings.Contains(pURL, "://") {
logger.Fatalf("cannot parse -remoteWrite.proxyURL=%q: it must start with `http://`, `https://` or `socks5://`", 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 { if err != nil {
logger.Fatalf("cannot parse -remoteWrite.proxyURL=%q: %s", pURL, err) logger.Fatalf("cannot parse -remoteWrite.proxyURL=%q: %s", pURL, err)
} }
tr.Proxy = http.ProxyURL(urlProxy) tr.Proxy = http.ProxyURL(pu)
} }
c := &client{ c := &client{
sanitizedURL: sanitizedURL, sanitizedURL: sanitizedURL,

View file

@ -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). * 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) ## [v1.68.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.68.0)

View file

@ -77,10 +77,11 @@ func newClient(sw *ScrapeWork) *client {
if isTLS { if isTLS {
tlsCfg = sw.ProxyAuthConfig.NewTLSConfig() tlsCfg = sw.ProxyAuthConfig.NewTLSConfig()
} }
proxyURLOrig := proxyURL
getProxyAuthHeader = func() string { getProxyAuthHeader = func() string {
return proxyURL.GetAuthHeader(sw.ProxyAuthConfig) return proxyURLOrig.GetAuthHeader(sw.ProxyAuthConfig)
} }
proxyURL = proxy.URL{} proxyURL = &proxy.URL{}
} }
if !strings.Contains(host, ":") { if !strings.Contains(host, ":") {
if !isTLS { if !isTLS {
@ -107,8 +108,8 @@ func newClient(sw *ScrapeWork) *client {
} }
var sc *http.Client var sc *http.Client
var proxyURLFunc func(*http.Request) (*url.URL, error) var proxyURLFunc func(*http.Request) (*url.URL, error)
if proxyURL := sw.ProxyURL.URL(); proxyURL != nil { if pu := sw.ProxyURL.URL(); pu != nil {
proxyURLFunc = http.ProxyURL(proxyURL) proxyURLFunc = http.ProxyURL(pu)
} }
sc = &http.Client{ sc = &http.Client{
Transport: &http.Transport{ Transport: &http.Transport{

View file

@ -125,7 +125,7 @@ type ScrapeConfig struct {
Scheme string `yaml:"scheme,omitempty"` Scheme string `yaml:"scheme,omitempty"`
Params map[string][]string `yaml:"params,omitempty"` Params map[string][]string `yaml:"params,omitempty"`
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` 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"` RelabelConfigs []promrelabel.RelabelConfig `yaml:"relabel_configs,omitempty"`
MetricRelabelConfigs []promrelabel.RelabelConfig `yaml:"metric_relabel_configs,omitempty"` MetricRelabelConfigs []promrelabel.RelabelConfig `yaml:"metric_relabel_configs,omitempty"`
SampleLimit int `yaml:"sample_limit,omitempty"` SampleLimit int `yaml:"sample_limit,omitempty"`
@ -796,7 +796,7 @@ type scrapeWorkConfig struct {
metricsPath string metricsPath string
scheme string scheme string
params map[string][]string params map[string][]string
proxyURL proxy.URL proxyURL *proxy.URL
proxyAuthConfig *promauth.Config proxyAuthConfig *promauth.Config
authConfig *promauth.Config authConfig *promauth.Config
honorLabels bool honorLabels bool

View file

@ -21,7 +21,7 @@ type SDConfig struct {
Username string `yaml:"username"` Username string `yaml:"username"`
Password string `yaml:"password"` Password string `yaml:"password"`
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
Services []string `yaml:"services,omitempty"` Services []string `yaml:"services,omitempty"`
Tags []string `yaml:"tags,omitempty"` Tags []string `yaml:"tags,omitempty"`

View file

@ -24,7 +24,7 @@ var SDCheckInterval = flag.Duration("promscrape.digitaloceanSDCheckInterval", ti
type SDConfig struct { type SDConfig struct {
Server string `yaml:"server,omitempty"` Server string `yaml:"server,omitempty"`
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
Port int `yaml:"port,omitempty"` Port int `yaml:"port,omitempty"`
} }

View file

@ -24,7 +24,7 @@ type SDConfig struct {
HostNetworkingHost string `yaml:"host_networking_host,omitempty"` HostNetworkingHost string `yaml:"host_networking_host,omitempty"`
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
// refresh_interval is obtained from `-promscrape.dockerSDCheckInterval` command-line option // refresh_interval is obtained from `-promscrape.dockerSDCheckInterval` command-line option
} }

View file

@ -24,7 +24,7 @@ type SDConfig struct {
Filters []Filter `yaml:"filters,omitempty"` Filters []Filter `yaml:"filters,omitempty"`
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
// refresh_interval is obtained from `-promscrape.dockerswarmSDCheckInterval` command-line option // refresh_interval is obtained from `-promscrape.dockerswarmSDCheckInterval` command-line option
} }

View file

@ -23,7 +23,7 @@ var SDCheckInterval = flag.Duration("promscrape.eurekaSDCheckInterval", 30*time.
type SDConfig struct { type SDConfig struct {
Server string `yaml:"server,omitempty"` Server string `yaml:"server,omitempty"`
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
// RefreshInterval time.Duration `yaml:"refresh_interval"` // RefreshInterval time.Duration `yaml:"refresh_interval"`
// refresh_interval is obtained from `-promscrape.ec2SDCheckInterval` command-line option. // refresh_interval is obtained from `-promscrape.ec2SDCheckInterval` command-line option.

View file

@ -20,7 +20,7 @@ var SDCheckInterval = flag.Duration("promscrape.httpSDCheckInterval", time.Minut
type SDConfig struct { type SDConfig struct {
URL string `yaml:"url"` URL string `yaml:"url"`
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
} }

View file

@ -24,7 +24,7 @@ type SDConfig struct {
Role string `yaml:"role"` Role string `yaml:"role"`
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` ProxyURL *proxy.URL `yaml:"proxy_url,omitempty"`
Namespaces Namespaces `yaml:"namespaces,omitempty"` Namespaces Namespaces `yaml:"namespaces,omitempty"`
Selectors []Selector `yaml:"selectors,omitempty"` Selectors []Selector `yaml:"selectors,omitempty"`

View file

@ -49,7 +49,7 @@ type Client struct {
} }
// NewClient returns new Client for the given args. // 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 var u fasthttp.URI
u.Update(apiServer) u.Update(apiServer)
@ -81,10 +81,11 @@ func NewClient(apiServer string, ac *promauth.Config, proxyURL proxy.URL, proxyA
if isTLS { if isTLS {
tlsCfg = proxyAC.NewTLSConfig() tlsCfg = proxyAC.NewTLSConfig()
} }
proxyURLOrig := proxyURL
getProxyAuthHeader = func() string { getProxyAuthHeader = func() string {
return proxyURL.GetAuthHeader(proxyAC) return proxyURLOrig.GetAuthHeader(proxyAC)
} }
proxyURL = proxy.URL{} proxyURL = &proxy.URL{}
} }
if !strings.Contains(hostPort, ":") { if !strings.Contains(hostPort, ":") {
port := "80" port := "80"

View file

@ -82,7 +82,7 @@ type ScrapeWork struct {
Labels []prompbmarshal.Label Labels []prompbmarshal.Label
// ProxyURL HTTP proxy url // ProxyURL HTTP proxy url
ProxyURL proxy.URL ProxyURL *proxy.URL
// Auth config for ProxyUR: // Auth config for ProxyUR:
ProxyAuthConfig *promauth.Config ProxyAuthConfig *promauth.Config

View file

@ -50,7 +50,7 @@ var (
stdDialerOnce sync.Once 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) dialFunc, err := proxyURL.NewDialFunc(ac)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -23,12 +23,12 @@ type URL struct {
} }
// MustNewURL returns new URL for the given u. // MustNewURL returns new URL for the given u.
func MustNewURL(u string) URL { func MustNewURL(u string) *URL {
pu, err := url.Parse(u) pu, err := url.Parse(u)
if err != nil { if err != nil {
logger.Panicf("BUG: cannot parse u=%q: %s", u, err) logger.Panicf("BUG: cannot parse u=%q: %s", u, err)
} }
return URL{ return &URL{
url: pu, url: pu,
} }
} }