From 1d0dd0338c65f4584a7622d783c3efda9e041696 Mon Sep 17 00:00:00 2001 From: ismail simsek Date: Thu, 29 Dec 2022 17:22:26 +0100 Subject: [PATCH] [v9.3.x] Prometheus: Fix Instant query time calculation (#60822) Prometheus: Fix Instant query time calculation (#60815) * Use single point in time instead of doing time range calculation * Comment update (cherry picked from commit 15d32546ea315f8ccada85cd64c5b49d55b0d6ec) --- pkg/tsdb/prometheus/client/client.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/tsdb/prometheus/client/client.go b/pkg/tsdb/prometheus/client/client.go index c3f0c4d0719..db7bd6a946b 100644 --- a/pkg/tsdb/prometheus/client/client.go +++ b/pkg/tsdb/prometheus/client/client.go @@ -50,12 +50,13 @@ func (c *Client) QueryRange(ctx context.Context, q *models.Query, headers http.H } func (c *Client) QueryInstant(ctx context.Context, q *models.Query, headers http.Header) (*http.Response, error) { - qv := map[string]string{"query": q.Expr} - tr := q.TimeRange() - if !tr.End.IsZero() { - qv["time"] = formatTime(tr.End) - } - + // We do not need a time range here. + // Instant query evaluates at a single point in time. + // Using q.TimeRange is aligning the query range to step. + // Which causes a misleading time point. + // Instead of aligning we use time point directly. + // https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries + qv := map[string]string{"query": q.Expr, "time": formatTime(q.End)} req, err := c.createQueryRequest(ctx, "api/v1/query", qv, headers) if err != nil { return nil, err