fix(observability-proxy): count the latency offset in instant lookback

vmselect moves an instant query evaluated near the current time back by
-search.latencyOffset (30s). With a tiny explicit step the lookback
bound did not cover that shift, so a window ending at the retention
edge could still be sent to the short-term store.

Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
ZverGuy committed 2026-11-10 03:56:18 +07:00
1 parent 560e4d7ba5
commit 2fad05b01f
3 files changed
+9 -2

No files matched your search

@@ -33,6 +33,12 @@ const instantDefaultStep = 5 * time.Minute
// -search.minStalenessInterval, 5m when unset; cozystack does not set it).
const silenceInterval = 5 * time.Minute
// latencyOffset is how far vmselect moves an instant query evaluated within
// it of the current time back (-search.latencyOffset, 30s by default and
// not set by cozystack); the proxy forwards neither nocache nor
// latency_offset.
const latencyOffset = 30 * time.Second
// queryDurationPart is the subset of the MetricsQL duration grammar
// (scanSingleDuration in metricsql) the scan understands. Step multiples
// (5i, $__interval), negative parts and upper-case units are left out on
+1 -1
View File
@@ -121,7 +121,7 @@ func BuildMetricsParams(endpoint string, in url.Values, namespace string, now ti
}
out.Set("step", formatSeconds(step))
}
req.start = queryStart(out.Get("query"), at, step)
req.start = queryStart(out.Get("query"), at.Add(-latencyOffset), step)
return req, nil
case "api/v1/query_range":
@@ -224,7 +224,7 @@ func TestBuildMetricsParamsCanonicalForms(t *testing.T) {
if req.params.Get("end") != "1793793600.000" || req.params.Get("start") != "1793793300.000" {
t.Errorf("labels window = %s..%s, want the last 5m", req.params.Get("start"), req.params.Get("end"))
}
if q := buildMetrics(t, "api/v1/query", url.Values{"query": {"up"}}); q.params.Has("time") || !q.start.Equal(testNow.Add(-15*time.Minute)) {
if q := buildMetrics(t, "api/v1/query", url.Values{"query": {"up"}}); q.params.Has("time") || !q.start.Equal(testNow.Add(-15*time.Minute-30*time.Second)) {
t.Errorf("instant query without time: params %v, start %v", q.params, q.start)
}
}
@@ -338,6 +338,7 @@ func TestMetricsStoreByLookback(t *testing.T) {
{"instant at start", "api/v1/query", url.Values{"query": {"x @ start()"}}, "longterm"},
{"instant step window", "api/v1/query", url.Values{"query": {"rate(x[5i])"}}, "longterm"},
{"instant step past retention", "api/v1/query", url.Values{"query": {"up"}, "step": {"259200"}}, "longterm"},
{"instant latency offset at the edge", "api/v1/query", url.Values{"query": {"default_rollup(x[71h54m59s])"}, "step": {"0.001"}}, "longterm"},
{"instant subquery past retention", "api/v1/query", url.Values{"query": {"max_over_time(rate(x[5m])[4d:1h])"}}, "longterm"},
{"quoted at sign", "api/v1/query", url.Values{"query": {`x{a="a@b"}`}}, "longterm"},
{"quoted open bracket hides window", "api/v1/query", url.Values{"query": {`rate(x{a="[5m"}[7d])`}}, "longterm"},