mirror of
https://github.com/grafana/grafana.git
synced 2025-09-26 06:54:00 +08:00
Prometheus: Fix Instant query time calculation (#60815)
* Use single point in time instead of doing time range calculation * Comment update
This commit is contained in:
@ -50,12 +50,13 @@ func (c *Client) QueryRange(ctx context.Context, q *models.Query) (*http.Respons
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) QueryInstant(ctx context.Context, q *models.Query) (*http.Response, error) {
|
func (c *Client) QueryInstant(ctx context.Context, q *models.Query) (*http.Response, error) {
|
||||||
qv := map[string]string{"query": q.Expr}
|
// We do not need a time range here.
|
||||||
tr := q.TimeRange()
|
// Instant query evaluates at a single point in time.
|
||||||
if !tr.End.IsZero() {
|
// Using q.TimeRange is aligning the query range to step.
|
||||||
qv["time"] = formatTime(tr.End)
|
// 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)
|
req, err := c.createQueryRequest(ctx, "api/v1/query", qv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Reference in New Issue
Block a user