From a1548d56e6b11d3cc3dac27b3db38bbbe83402c9 Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Tue, 23 Jan 2024 12:09:14 +0100 Subject: [PATCH] lib/promscrape: respect `0` value for `series_limit` param (#5663) * lib/promscrape: respect `0` value for `series_limit` param Respect `0` value for `series_limit` param in `scrape_config` even if global limit was set via `-promscrape.seriesLimitPerTarget`. Previously, `0` value will be ignored in favor of `-promscrape.seriesLimitPerTarget`. This behavior aligns with possibility to override `series_limit` value via relabeling with `__series_limit__` label. Signed-off-by: hagen1778 * Update docs/CHANGELOG.md --------- Signed-off-by: hagen1778 Co-authored-by: Aliaksandr Valialkin --- docs/CHANGELOG.md | 1 + lib/promscrape/config.go | 6 +++--- lib/promscrape/config_test.go | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ecc2c7789..38f204454 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -16,6 +16,7 @@ The following tip changes can be tested by building VictoriaMetrics components f ## v1.87.x long-time support release (LTS) * BUGFIX: properly return errors from [export APIs](https://docs.victoriametrics.com/#how-to-export-time-series). Previously these errors were silently suppressed. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5649). +* BUGFIX: [vmagent](https://docs.victoriametrics.com/vmagent.html): respect explicitly set `series_limit: 0` in [scrape_config](https://docs.victoriametrics.com/sd_configs.html#scrape_configs). This allows removing [`series_limit` restriction](https://docs.victoriametrics.com/vmagent.html#cardinality-limiter) on a per-`scrape_config` basis when global limit is set via `-promscrape.seriesLimitPerTarget`. Previously, `0` value was ignored in favor of `-promscrape.seriesLimitPerTarget`. * BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly process queries with too big lookbehind window such as `foo[100y]`. Previously, such queries could return empty responses even if `foo` is present in database. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5553). * BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly handle possible negative results caused by float operations precision error in rollup functions like rate() or increase(). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5571). diff --git a/lib/promscrape/config.go b/lib/promscrape/config.go index b30944377..56c276950 100644 --- a/lib/promscrape/config.go +++ b/lib/promscrape/config.go @@ -275,7 +275,7 @@ type ScrapeConfig struct { StreamParse bool `yaml:"stream_parse,omitempty"` ScrapeAlignInterval *promutils.Duration `yaml:"scrape_align_interval,omitempty"` ScrapeOffset *promutils.Duration `yaml:"scrape_offset,omitempty"` - SeriesLimit int `yaml:"series_limit,omitempty"` + SeriesLimit *int `yaml:"series_limit,omitempty"` NoStaleMarkers *bool `yaml:"no_stale_markers,omitempty"` ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"` @@ -960,8 +960,8 @@ func getScrapeWorkConfig(sc *ScrapeConfig, baseDir string, globalCfg *GlobalConf noStaleTracking = *sc.NoStaleMarkers } seriesLimit := *seriesLimitPerTarget - if sc.SeriesLimit > 0 { - seriesLimit = sc.SeriesLimit + if sc.SeriesLimit != nil { + seriesLimit = *sc.SeriesLimit } swc := &scrapeWorkConfig{ scrapeInterval: scrapeInterval, diff --git a/lib/promscrape/config_test.go b/lib/promscrape/config_test.go index 7fe042b5f..a5524b429 100644 --- a/lib/promscrape/config_test.go +++ b/lib/promscrape/config_test.go @@ -1289,6 +1289,29 @@ scrape_configs: jobNameOriginal: "foo", }, }) + + defaultSeriesLimitPerTarget := *seriesLimitPerTarget + *seriesLimitPerTarget = 1e3 + f(` +scrape_configs: +- job_name: foo + series_limit: 0 + static_configs: + - targets: ["foo.bar:1234"] +`, []*ScrapeWork{ + { + ScrapeURL: "http://foo.bar:1234/metrics", + ScrapeInterval: defaultScrapeInterval, + ScrapeTimeout: defaultScrapeTimeout, + jobNameOriginal: "foo", + Labels: promutils.NewLabelsFromMap(map[string]string{ + "instance": "foo.bar:1234", + "job": "foo", + }), + SeriesLimit: 0, + }, + }) + *seriesLimitPerTarget = defaultSeriesLimitPerTarget } func equalStaticConfigForScrapeWorks(a, b []*ScrapeWork) bool {