lib/promscrape/discovery/kubernetes: return back support role: endpointslices, since it is used by VictoriaMetrics operator

This is a follow up commit after 31b42b30b6
This commit is contained in:
Aliaksandr Valialkin 2021-08-29 12:34:55 +03:00
parent 3788d4f4eb
commit 146c14d879
4 changed files with 21 additions and 7 deletions

View File

@ -17,7 +17,7 @@ sort: 15
* FEATURE: add `quantiles("quantileLabel", phi1, ..., phiN, q)` aggregate function to [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html), which calculates the given `phi*` quantiles over time series returned by `q`. See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1573). * FEATURE: add `quantiles("quantileLabel", phi1, ..., phiN, q)` aggregate function to [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html), which calculates the given `phi*` quantiles over time series returned by `q`. See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1573).
* BUGFIX: rename `sign` function to `sgn` in order to be consistent with PromQL. See [this pull request from Prometheus](https://github.com/prometheus/prometheus/pull/8457). * BUGFIX: rename `sign` function to `sgn` in order to be consistent with PromQL. See [this pull request from Prometheus](https://github.com/prometheus/prometheus/pull/8457).
* BUGFIX: vmagent: rename `role: endpointslices` to `role: endpointslice` in [kubernetes_sd_config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config) in order to be consistent with Prometheus. See [the corresponding code in Prometheus](https://github.com/prometheus/prometheus/blob/2ec6c7dbb82b72834021e01f1773eb90a67a371f/discovery/kubernetes/kubernetes.go#L99). * BUGFIX: vmagent: add `role: endpointslice` in [kubernetes_sd_config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config) in order to be consistent with Prometheus. Previously this role was supported with incorrect name: `role: endpointslices`. Now both `endpointslice` and `endpointslices` are supported. See [the corresponding code in Prometheus](https://github.com/prometheus/prometheus/blob/2ec6c7dbb82b72834021e01f1773eb90a67a371f/discovery/kubernetes/kubernetes.go#L99).
* BUGFIX: improve the detection of the needed free space for background merge operation. This should prevent from possible out of disk space crashes during big merges. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1560). * BUGFIX: improve the detection of the needed free space for background merge operation. This should prevent from possible out of disk space crashes during big merges. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1560).
* BUGFIX: vmauth: remove trailing slash from the full url before requesting it from the backend. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/1554). * BUGFIX: vmauth: remove trailing slash from the full url before requesting it from the backend. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/1554).
* BUGFIX: [vmbackupmanager](https://docs.victoriametrics.com/vmbackupmanager.html): fix timeout error when snapshot takes longer than 10 seconds. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1571). * BUGFIX: [vmbackupmanager](https://docs.victoriametrics.com/vmbackupmanager.html): fix timeout error when snapshot takes longer than 10 seconds. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1571).

View File

@ -15,10 +15,11 @@ type apiConfig struct {
} }
func newAPIConfig(sdc *SDConfig, baseDir string, swcFunc ScrapeWorkConstructorFunc) (*apiConfig, error) { func newAPIConfig(sdc *SDConfig, baseDir string, swcFunc ScrapeWorkConstructorFunc) (*apiConfig, error) {
switch sdc.Role { role := sdc.role()
switch role {
case "node", "pod", "service", "endpoints", "endpointslice", "ingress": case "node", "pod", "service", "endpoints", "endpointslice", "ingress":
default: default:
return nil, fmt.Errorf("unexpected `role`: %q; must be one of `node`, `pod`, `service`, `endpoints`, `endpointslice` or `ingress`", sdc.Role) return nil, fmt.Errorf("unexpected `role`: %q; must be one of `node`, `pod`, `service`, `endpoints`, `endpointslice` or `ingress`", role)
} }
ac, err := sdc.HTTPClientConfig.NewConfig(baseDir) ac, err := sdc.HTTPClientConfig.NewConfig(baseDir)
if err != nil { if err != nil {

View File

@ -66,12 +66,13 @@ func newAPIWatcher(apiServer string, ac *promauth.Config, sdc *SDConfig, swcFunc
selectors := sdc.Selectors selectors := sdc.Selectors
proxyURL := sdc.ProxyURL.URL() proxyURL := sdc.ProxyURL.URL()
gw := getGroupWatcher(apiServer, ac, namespaces, selectors, proxyURL) gw := getGroupWatcher(apiServer, ac, namespaces, selectors, proxyURL)
role := sdc.role()
return &apiWatcher{ return &apiWatcher{
role: sdc.Role, role: role,
swcFunc: swcFunc, swcFunc: swcFunc,
gw: gw, gw: gw,
swosByURLWatcher: make(map[*urlWatcher]map[string][]interface{}), swosByURLWatcher: make(map[*urlWatcher]map[string][]interface{}),
swosCount: metrics.GetOrCreateCounter(fmt.Sprintf(`vm_promscrape_discovery_kubernetes_scrape_works{role=%q}`, sdc.Role)), swosCount: metrics.GetOrCreateCounter(fmt.Sprintf(`vm_promscrape_discovery_kubernetes_scrape_works{role=%q}`, role)),
} }
} }

View File

@ -18,8 +18,11 @@ var SDCheckInterval = flag.Duration("promscrape.kubernetesSDCheckInterval", 30*t
// //
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config // See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config
type SDConfig struct { type SDConfig struct {
APIServer string `yaml:"api_server,omitempty"` APIServer string `yaml:"api_server,omitempty"`
Role string `yaml:"role"`
// Use role() function for accessing the Role field
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"`
@ -29,6 +32,15 @@ type SDConfig struct {
startErr error startErr error
} }
func (sdc *SDConfig) role() string {
if sdc.Role == "endpointslices" {
// The endpointslices role isn't supported by Prometheus, but it is used by VictoriaMetrics operator.
// Support it for backwards compatibility.
return "endpointslice"
}
return sdc.Role
}
// Namespaces represents namespaces for SDConfig // Namespaces represents namespaces for SDConfig
type Namespaces struct { type Namespaces struct {
Names []string `yaml:"names"` Names []string `yaml:"names"`