mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 12:13:55 +09:00
fix(observability-proxy): forward the default instant query time
An instant query without time had its application lookup sized at the proxy's clock, but the time was not forwarded, so vmselect evaluated at its own later clock. With lookups taking most of the request deadline, the evaluation lands well past the end of the lookup and leaves out pods first sampled in between. Forward the instant the lookup was sized for. Assisted-by: LLM Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
1 parent
79ea8561de
commit
e8e0cede61
3 files changed
+26
-2
No files matched your search
@@ -134,8 +134,11 @@ func BuildMetricsParams(endpoint string, in url.Values, namespace string, now ti
|
||||
return req, herr
|
||||
}
|
||||
at = t
|
||||
out.Set("time", formatTime(t))
|
||||
}
|
||||
// The default is forwarded too: the application lookup is sized
|
||||
// for at, and vmselect's own clock reads later, by as long as the
|
||||
// lookups took.
|
||||
out.Set("time", formatTime(at))
|
||||
step := instantDefaultStep
|
||||
if v := in.Get("step"); v != "" {
|
||||
var herr *HTTPError
|
||||
|
||||
@@ -227,7 +227,7 @@ func TestBuildMetricsParamsCanonicalForms(t *testing.T) {
|
||||
if req.params.Get("end") != "2026-11-04T12:00:00.000Z" || req.params.Get("start") != "2026-11-04T11:55:00.000Z" {
|
||||
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-2*latencyOffset)) {
|
||||
if q := buildMetrics(t, "api/v1/query", url.Values{"query": {"up"}}); q.params.Get("time") != "2026-11-04T12:00:00.000Z" || !q.start.Equal(testNow.Add(-15*time.Minute-2*latencyOffset)) {
|
||||
t.Errorf("instant query without time: params %v, start %v", q.params, q.start)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -363,6 +363,27 @@ func TestServerApplicationLookupCoversNegativeOffset(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestServerApplicationForwardsDefaultTime: without time the lookup is
|
||||
// sized at the proxy's clock, so that instant is forwarded. Otherwise
|
||||
// vmselect evaluates at its own later clock, past the end of the lookup by
|
||||
// however long the lookups took, and leaves out pods first sampled since.
|
||||
func TestServerApplicationForwardsDefaultTime(t *testing.T) {
|
||||
h := newPolicyHarness(t, Config{}, appMetricsUpstream(nil, nil, http.StatusOK), appPolicy, nil)
|
||||
q := url.Values{"query": {"container_cpu_usage_seconds_total"}}
|
||||
if got := h.status(http.MethodGet, appRoot+"db.main/metrics/api/v1/query?"+q.Encode(), "good"); got != http.StatusOK {
|
||||
t.Fatalf("status = %d", got)
|
||||
}
|
||||
reqs := h.requests()
|
||||
lookup, final := reqs[0], reqs[len(reqs)-1]
|
||||
want := formatTime(testNow)
|
||||
if lookup.path != "/api/v1/label/pod/values" || lookup.form.Get("end") != want {
|
||||
t.Fatalf("lookup %s end = %s, want %s", lookup.path, lookup.form.Get("end"), want)
|
||||
}
|
||||
if final.path != "/api/v1/query" || final.form.Get("time") != want {
|
||||
t.Fatalf("query %s time = %q, want the lookup's instant %s", final.path, final.form.Get("time"), want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestServerApplicationRefusesUnboundedSampleTime refuses a query whose
|
||||
// samples may lie at a time the lookup cannot be sized for, rather than
|
||||
// answer with series silently left out.
|
||||
|
||||
Reference in new issue
Block a user