From 26077e0b4a90adb10c3eefcd95eafa3342a4a4ee Mon Sep 17 00:00:00 2001 From: Bartlomiej Plotka Date: Fri, 5 Mar 2021 22:21:37 +0100 Subject: [PATCH] Fix parseStep bug introduced in PR #3740 (#3887) (#3889) * Fix bug introduced in PR #3740 Signed-off-by: Hitanshu Mehta * Minor change in test Signed-off-by: Hitanshu Mehta Co-authored-by: Hitanshu Mehta <44025541+hitanshu-mehta@users.noreply.github.com> --- pkg/api/query/v1.go | 1 + pkg/api/query/v1_test.go | 14 ++++++++------ pkg/ui/static/js/graph.js | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/api/query/v1.go b/pkg/api/query/v1.go index e186057208..b27031e6e3 100644 --- a/pkg/api/query/v1.go +++ b/pkg/api/query/v1.go @@ -247,6 +247,7 @@ func (qapi *QueryAPI) parseStep(r *http.Request, defaultRangeQueryStep time.Dura if err != nil { return 0, &api.ApiError{Typ: api.ErrorBadData, Err: errors.Wrapf(err, "'%s' parameter", Step)} } + return defaultRangeQueryStep, nil } // Default step is used this way to make it consistent with UI. diff --git a/pkg/api/query/v1_test.go b/pkg/api/query/v1_test.go index f87deff16b..f93f6b2b17 100644 --- a/pkg/api/query/v1_test.go +++ b/pkg/api/query/v1_test.go @@ -465,18 +465,20 @@ func TestQueryEndpoints(t *testing.T) { query: url.Values{ "query": []string{"time()"}, "start": []string{"0"}, - "end": []string{"2"}, + "end": []string{"500"}, "step": []string{"1"}, }, response: &queryData{ ResultType: parser.ValueTypeMatrix, Result: promql.Matrix{ promql.Series{ - Points: []promql.Point{ - {V: 0, T: timestamp.FromTime(start)}, - {V: 1, T: timestamp.FromTime(start.Add(1 * time.Second))}, - {V: 2, T: timestamp.FromTime(start.Add(2 * time.Second))}, - }, + Points: func(end, step float64) []promql.Point { + var res []promql.Point + for v := float64(0); v <= end; v += step { + res = append(res, promql.Point{V: v, T: timestamp.FromTime(start.Add(time.Duration(v) * time.Second))}) + } + return res + }(500, 1), Metric: nil, }, }, diff --git a/pkg/ui/static/js/graph.js b/pkg/ui/static/js/graph.js index 6ba577a6c1..30d1fcaf46 100644 --- a/pkg/ui/static/js/graph.js +++ b/pkg/ui/static/js/graph.js @@ -309,7 +309,7 @@ Prometheus.Graph.prototype.setDefaultStep = function(el) { self.showError("Error querying flags."); return; } - el.defaultStep = (json.data && "query.default-stp" in json.data) ? json.data["query.default-stp"] : "1s" + el.defaultStep = (json.data && "query.default-step" in json.data) ? json.data["query.default-step"] : "1s" }, error: function() {