From cbe39bbb8dc25ee5e050551fe0ebd18d32d2cf38 Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Thu, 16 Jun 2022 19:46:31 +0200 Subject: [PATCH] vmselect: limit `end` param max value by 2d in future (#2729) * vmselect: limit `end` param max value by 2d in future The change is applied only to service handlers like `/labels` or `/series` and limits the `end` param by max value <= now() + 2 days. The same limit is applied for the ingested data, so no reason to allow to request data in future far than that. The change is also needed for corner cases like https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2669 where too high `end` value triggers inefficient global index search. Signed-off-by: hagen1778 * docs/CHANGELOG.md: document the bugfix Co-authored-by: Aliaksandr Valialkin --- app/vmselect/prometheus/prometheus.go | 8 ++++++++ docs/CHANGELOG.md | 1 + 2 files changed, 9 insertions(+) diff --git a/app/vmselect/prometheus/prometheus.go b/app/vmselect/prometheus/prometheus.go index 8fc3ec9a4f..b5dda9cdc7 100644 --- a/app/vmselect/prometheus/prometheus.go +++ b/app/vmselect/prometheus/prometheus.go @@ -1174,6 +1174,14 @@ func getCommonParams(r *http.Request, startTime time.Time, requireNonEmptyMatch if err != nil { return nil, err } + // Limit the `end` arg to the current time +2 days in the same way + // as it is limited during data ingestion. + // See https://github.com/VictoriaMetrics/VictoriaMetrics/blob/ea06d2fd3ccbbb6aa4480ab3b04f7b671408be2a/lib/storage/table.go#L378 + // This should fix possible timestamp overflow - see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2669 + maxTS := startTime.UnixNano()/1e6 + 2*24*3600*1000 + if end > maxTS { + end = maxTS + } if end < start { end = start } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 338a97877e..36b921a2c1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -45,6 +45,7 @@ The following tip changes can be tested by building VictoriaMetrics components f * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): properly apply the selected time range when auto-refresh is enabled. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2693). * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): properly update the url with vmui state when new query is entered. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2692). * BUGFIX: [Graphite render API](https://docs.victoriametrics.com/#graphite-render-api-usage): properly calculate sample timestamps when `moving*()` functions such as [movingAverage()](https://graphite.readthedocs.io/en/stable/functions.html#graphite.render.functions.movingAverage) are applied over [summarize()](https://graphite.readthedocs.io/en/stable/functions.html#graphite.render.functions.summarize). +* BUGFIX: limit the `end` query arg value to `+2 days` in the future at `/api/v1/*` endpoints, because VictoriaMetrics doesn't allow storing samples with timestamps bigger than +2 days in the future. This should help resolving [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2669). ## [v1.77.2](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.77.2)