From 881dde505ac732bed6044dadc86efabcb737d2ad Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Sat, 8 Feb 2020 16:26:26 +0100 Subject: [PATCH] promql: fix promql query log step unit Signed-off-by: Julien Pivotto --- cmd/prometheus/query_log_test.go | 12 +++++++++--- promql/engine.go | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/prometheus/query_log_test.go b/cmd/prometheus/query_log_test.go index 2dd1bac68..503982bf2 100644 --- a/cmd/prometheus/query_log_test.go +++ b/cmd/prometheus/query_log_test.go @@ -105,7 +105,7 @@ func (p *queryLogTest) query(t *testing.T) { switch p.origin { case apiOrigin: r, err := http.Get(fmt.Sprintf( - "http://%s:%d%s/api/v1/query?query=%s", + "http://%s:%d%s/api/v1/query_range?step=5&start=0&end=3600&query=%s", p.host, p.port, p.prefix, @@ -148,7 +148,13 @@ func (p *queryLogTest) queryString() string { func (p *queryLogTest) validateLastQuery(t *testing.T, ql []queryLogLine) { q := ql[len(ql)-1] testutil.Equals(t, p.queryString(), q.Params.Query) - testutil.Equals(t, 0, q.Params.Step) + + switch p.origin { + case apiOrigin: + testutil.Equals(t, 5, q.Params.Step) + default: + testutil.Equals(t, 0, q.Params.Step) + } if p.origin != ruleOrigin { host := p.host @@ -160,7 +166,7 @@ func (p *queryLogTest) validateLastQuery(t *testing.T, ql []queryLogLine) { switch p.origin { case apiOrigin: - testutil.Equals(t, p.prefix+"/api/v1/query", q.Request.Path) + testutil.Equals(t, p.prefix+"/api/v1/query_range", q.Request.Path) case consoleOrigin: testutil.Equals(t, p.prefix+"/consoles/test.html", q.Request.Path) case ruleOrigin: diff --git a/promql/engine.go b/promql/engine.go index 0add9e147..87914c30f 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -437,7 +437,8 @@ func (ng *Engine) exec(ctx context.Context, q *query) (v Value, w storage.Warnin if eq, ok := q.Statement().(*EvalStmt); ok { params["start"] = formatDate(eq.Start) params["end"] = formatDate(eq.End) - params["step"] = eq.Interval + // The step provided by the user is in seconds. + params["step"] = durationMilliseconds(eq.Interval) / 1000 } f := []interface{}{"params", params} if err != nil {