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, "://") {
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,

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).
* 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)

View file

@ -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{

View file

@ -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

View file

@ -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"`

View file

@ -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"`
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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.

View file

@ -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"`
}

View file

@ -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"`

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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,
}
}