Compare commits

...

2 Commits

Author SHA1 Message Date
Jayice
64d82113f0 ignore non-positive __max_scrape_size__ 2026-07-03 16:49:08 +08:00
Jayice
cf64fea376 support __max_scrape_size__ in target 2026-07-03 15:06:45 +08:00
4 changed files with 67 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ See also [LTS releases](https://docs.victoriametrics.com/victoriametrics/lts-rel
* FEATURE: [vmsingle](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/) and `vmselect` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/victoriametrics/cluster-victoriametrics/): add `optimize_repeated_binary_op_subexprs=1` query arg to [/api/v1/query_range](https://docs.victoriametrics.com/victoriametrics/keyconcepts/#range-query) for executing binary operator sides sequentially when they share the same optimized aggregate rollup result expression. This allows the second side to reuse rollup result cache populated by the first side. See [#10575](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/10575). Thanks to @xhebox for the contribution.
* FEATURE: [vmauth](https://docs.victoriametrics.com/victoriametrics/vmauth/): prevent possible password brute-force attacks with an artificial 2-3 second delay as recommended by [OWASP](https://owasp.org/Top10/2025/A07_2025-Authentication_Failures). See [#11180](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/11180).
* FEATURE: [alerts](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/rules): add `InvalidAuthTokenRequestErrors` alerting rule to [vmauth alerts](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/rules/alerts-vmauth.yml). The new rule notifies when vmauth receives requests with invalid or missing auth tokens, which may indicate a client misconfiguration, expired token use, or brute-force attack. See [#11180](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/11180).
* FEATURE: [vmagent](https://docs.victoriametrics.com/victoriametrics/vmagent/) and [vmsingle](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/): allow overriding `max_scrape_size` on a per-target basis via the `__max_scrape_size__` label during target relabeling. See [#11188](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/11188).
* BUGFIX: all VictoriaMetrics components: cancel in-flight HTTP requests shortly before `-http.maxGracefulShutdownDuration` elapses during graceful shutdown, so they can drain and the shutdown completes cleanly within that window instead of timing out and exiting via `logger.Fatalf` -> `os.Exit`. This prevents skipping the storage flush and losing in-memory data when long-lived requests are in flight (such as VictoriaLogs live tailing). See [#1502](https://github.com/VictoriaMetrics/VictoriaLogs/issues/1502).
* BUGFIX: `vminsert` in [VictoriaMetrics cluster](https://docs.victoriametrics.com/victoriametrics/cluster-victoriametrics/) and [vmsingle](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/): properly check values range for the limits configured with flags `-maxLabelsPerTimeseries`, `-maxLabelNameLen` and `-maxLabelValueLen`. It must be in range `1..65535`. See [#11128](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/11128).

View File

@@ -1923,6 +1923,9 @@ scrape_configs:
# Example values:
# - "10MiB" - 10 * 1024 * 1024 bytes
# - "100MB" - 100 * 1000 * 1000 bytes
# The max_scrape_size can be set on a per-target basis by specifying `__max_scrape_size__`
# label during target relabeling phase.
# See https://docs.victoriametrics.com/victoriametrics/relabeling/
#
# max_scrape_size: <size>

View File

@@ -1271,6 +1271,17 @@ func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabel
}
scrapeTimeout = d
}
// Read max_scrape_size option from __max_scrape_size__ label.
targetMaxScrapeSize := swc.maxScrapeSize
if s := labels.Get("__max_scrape_size__"); len(s) > 0 {
n, err := flagutil.ParseBytes(s)
if err != nil {
return nil, fmt.Errorf("cannot parse __max_scrape_size__=%q: %w", s, err)
}
if n > 0 {
targetMaxScrapeSize = n
}
}
// Read series_limit option from __series_limit__ label.
// See https://docs.victoriametrics.com/victoriametrics/vmagent/#cardinality-limiter
seriesLimit := swc.seriesLimit
@@ -1333,7 +1344,7 @@ func (swc *scrapeWorkConfig) getScrapeWork(target string, extraLabels, metaLabel
ScrapeURL: scrapeURL,
ScrapeInterval: scrapeInterval,
ScrapeTimeout: scrapeTimeout,
MaxScrapeSize: swc.maxScrapeSize,
MaxScrapeSize: targetMaxScrapeSize,
HonorLabels: swc.honorLabels,
HonorTimestamps: swc.honorTimestamps,
DenyRedirects: swc.denyRedirects,

View File

@@ -1153,6 +1153,57 @@ scrape_configs:
})
f(`
scrape_configs:
- job_name: foo
max_scrape_size: 8MiB
relabel_configs:
- source_labels: [__address__]
regex: foo1:.*
target_label: __max_scrape_size__
replacement: 2.5MiB
- source_labels: [__address__]
regex: foo2:.*
target_label: __max_scrape_size__
replacement: -1
static_configs:
- targets: ["foo1:1234", "foo2:1234", "foo3:1234"]
`, []*ScrapeWork{
{
ScrapeURL: "http://foo1:1234/metrics",
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: 2.5 * 1024 * 1024,
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo1:1234",
"job": "foo",
}),
jobNameOriginal: "foo",
},
// invalid __max_scrape_size__ will be ignored
{
ScrapeURL: "http://foo2:1234/metrics",
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: 8 * 1024 * 1024,
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo2:1234",
"job": "foo",
}),
jobNameOriginal: "foo",
},
{
ScrapeURL: "http://foo3:1234/metrics",
ScrapeInterval: defaultScrapeInterval,
ScrapeTimeout: defaultScrapeTimeout,
MaxScrapeSize: 8 * 1024 * 1024,
Labels: promutil.NewLabelsFromMap(map[string]string{
"instance": "foo3:1234",
"job": "foo",
}),
jobNameOriginal: "foo",
},
})
f(`
scrape_configs:
- job_name: foo
static_configs:
- targets: ["foo.bar:1234"]