Skip to content

Commit

Permalink
Fix parseStep bug introduced in PR #3740 (#3887) (#3889)
Browse files Browse the repository at this point in the history
* Fix bug introduced in PR #3740

Signed-off-by: Hitanshu Mehta <hitanshu99amehta@gmail.com>

* Minor change in test

Signed-off-by: Hitanshu Mehta <hitanshu99amehta@gmail.com>

Co-authored-by: Hitanshu Mehta <44025541+hitanshu-mehta@users.noreply.github.com>
  • Loading branch information
bwplotka and hitanshu-mehta authored Mar 5, 2021
1 parent af4ee3a commit 26077e0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions pkg/api/query/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 8 additions & 6 deletions pkg/api/query/v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/static/js/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 26077e0

Please sign in to comment.