[v9.2.x] Prometheus: Fix Instant query time calculation (#60821)

Prometheus: Fix Instant query time calculation (#60815)

* Use single point in time instead of doing time range calculation

* Comment update

(cherry picked from commit 15d32546ea)
This commit is contained in:
ismail simsek
2022-12-29 17:22:30 +01:00
committed by GitHub
parent ecd1f03a65
commit 3863c0d4ba
+7 -5
View File
@@ -51,11 +51,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) {
qs := map[string]string{"query": q.Expr}
tr := q.TimeRange()
if !tr.End.IsZero() {
qs["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
qs := map[string]string{"query": q.Expr, "time": formatTime(q.End)}
u, err := c.createUrl("api/v1/query", qs)
if err != nil {