Repository: thanos-io/thanos (Go)

Issue:
query: 0.19.0-rc.0 regression - Query with resolution. Graphs are dotted instead of lines

**Thanos, Prometheus and Golang version used**:
thanos v0.19.0-rc.0
prometheus v2.25.0
grafana v7.4.3

**What happened**:
We are validating 0.19.0-rc.0, by just upgrading the version, most of our grafana dashboards are becoming dotted graphs instead of lines. I suspect some resolution/step issue. As on thanos UI, it happens only when we set a resolution to 30s (our scrape interval)
![thanos-ui-reg](https://user-images.githubusercontent.com/25080995/109953116-eb2bce80-7cdf-11eb-93ec-0f252e69eaee.png)

Step is a default behaviour we have in our grafana dahsboards.

**What you expected to happen**:
Like v0.18.0 and like prometheus UI, having connected lines for the query.
![prometheus-ui](https://user-images.githubusercontent.com/25080995/109953093-e23afd00-7cdf-11eb-9267-48f0b56458f1.png)

**How to reproduce it (as minimally and precisely as possible)**:
Scrape something at 30s interval. Simple query raw metrics with a resolution of 30s. Compare Thanos replies vs prometheus reply.


Discussion:
Interesting. Thanks for reporting.

I wonder if it has something to do with the step changes we did with @hitanshu-mehta (https://github.com/thanos-io/thanos/pull/3740) 🤗 
Yes. Resolution set in UI is overwritten every time by this line.
https://github.com/thanos-io/thanos/blob/dfcfbe435c5722f67e4e4df50db915171ece4ff1/pkg/api/query/v1.go#L243
I can fix this :) 



Patch:
diff --git a/pkg/api/query/v1.go b/pkg/api/query/v1.go
index 9a86612687e..fe6ca993020 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/ui/static/js/graph.js b/pkg/ui/static/js/graph.js
index 6ba577a6c19..30d1fcaf465 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() {


Test patch:
diff --git a/pkg/api/query/v1_test.go b/pkg/api/query/v1_test.go
index f87deff16be..f93f6b2b17c 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,
 					},
 				},