From 3ab3902f17a1d35437177d00a8278036139e901e Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 22 Jun 2021 13:17:42 +0300 Subject: [PATCH] lib/promscrape/discovery: support generic auth configs in Consul service discovery in the same way as Prometheus 2.28 does --- docs/CHANGELOG.md | 1 + lib/promscrape/discovery/consul/api.go | 16 ++++++++++++---- lib/promscrape/discovery/consul/consul.go | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4b99bb2e42..dcf6b1d93e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -11,6 +11,7 @@ sort: 15 * FEATURE: vmagent: show the number of samples the target returned during the last scrape on `/targets` and `/api/v1/targets` pages. This should simplify debugging targets, which may return too big or too low number of samples. See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1377). * FEATURE: vmagent: show jobs with zero discovered targets on `/targets` page. This should help debugging improperly configured scrape configs. * FEATURE: vmagent: support namespace in Consul serive discovery in the same way as Prometheus 2.28 does. See [this issue](https://github.com/prometheus/prometheus/issues/8894) for details. +* FEATURE: vmagent: support generic auth configs in `consul_sd_configs` in the same way as Prometheus 2.28 does. See [this issue](https://github.com/prometheus/prometheus/issues/8924) for details. * FEATURE: [vmctl](https://docs.victoriametrics.com/vmctl.html): limit the number of samples per each imported JSON line. This should limit the memory usage at VictoriaMetrics side when importing time series with big number of samples. * FEATURE: vmselect: log slow queries across all the `/api/v1/*` handlers (aka [Prometheus query API](https://prometheus.io/docs/prometheus/latest/querying/api)) if their execution duration exceeds `-search.logSlowQueryDuration`. This should simplify debugging slow requests to such handlers as `/api/v1/labels` or `/api/v1/series` additionally to `/api/v1/query` and `/api/v1/query_range`, which were logged in the previous releases. diff --git a/lib/promscrape/discovery/consul/api.go b/lib/promscrape/discovery/consul/api.go index 937b19f7ec..a1eda9034d 100644 --- a/lib/promscrape/discovery/consul/api.go +++ b/lib/promscrape/discovery/consul/api.go @@ -38,19 +38,27 @@ func getAPIConfig(sdc *SDConfig, baseDir string) (*apiConfig, error) { } func newAPIConfig(sdc *SDConfig, baseDir string) (*apiConfig, error) { + hcc := sdc.HTTPClientConfig token, err := getToken(sdc.Token) if err != nil { return nil, err } - var ba *promauth.BasicAuthConfig + if token != "" { + if hcc.BearerToken != "" { + return nil, fmt.Errorf("cannot set both token and bearer_token configs") + } + hcc.BearerToken = token + } if len(sdc.Username) > 0 { - ba = &promauth.BasicAuthConfig{ + if hcc.BasicAuth != nil { + return nil, fmt.Errorf("cannot set both username and basic_auth configs") + } + hcc.BasicAuth = &promauth.BasicAuthConfig{ Username: sdc.Username, Password: sdc.Password, } - token = "" } - ac, err := promauth.NewConfig(baseDir, nil, ba, token, "", nil, sdc.TLSConfig) + ac, err := hcc.NewConfig(baseDir) if err != nil { return nil, fmt.Errorf("cannot parse auth config: %w", err) } diff --git a/lib/promscrape/discovery/consul/consul.go b/lib/promscrape/discovery/consul/consul.go index f1ee777ad4..3d8ac4a9f3 100644 --- a/lib/promscrape/discovery/consul/consul.go +++ b/lib/promscrape/discovery/consul/consul.go @@ -20,9 +20,9 @@ type SDConfig struct { Scheme string `yaml:"scheme,omitempty"` Username string `yaml:"username"` Password string `yaml:"password"` + HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"` ProxyURL proxy.URL `yaml:"proxy_url,omitempty"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` - TLSConfig *promauth.TLSConfig `yaml:"tls_config,omitempty"` Services []string `yaml:"services,omitempty"` Tags []string `yaml:"tags,omitempty"` NodeMeta map[string]string `yaml:"node_meta,omitempty"`