-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Query Frontend: fix downsampled middleware returning duplicate samples
Downsampled middleware incorrectly determined minimum response timestamp using only one data point, which resulted in superflous requests and duplicate samples in response. Those duplicate samples in turn broke graph rendering in grafana in Thanos UI. Signed-off-by: Vladimir Kononov <krya-kryak@users.noreply.github.com>
- Loading branch information
1 parent
2dab5ce
commit 6aaf4c2
Showing
4 changed files
with
135 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package queryfrontend | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cortexproject/cortex/pkg/cortexpb" | ||
"github.com/cortexproject/cortex/pkg/querier/queryrange" | ||
"github.com/thanos-io/thanos/pkg/testutil" | ||
) | ||
|
||
func TestDownsampled_MinResponseTime(t *testing.T) { | ||
for _, tc := range []struct { | ||
desc string | ||
sampleStreams []queryrange.SampleStream | ||
expected int64 | ||
}{ | ||
{ | ||
desc: "empty []sampleStream", | ||
sampleStreams: []queryrange.SampleStream{}, | ||
expected: -1, | ||
}, | ||
{ | ||
desc: "one SampleStream with zero samples", | ||
sampleStreams: []queryrange.SampleStream{ | ||
{ | ||
Samples: []cortexpb.Sample{}, | ||
}, | ||
}, | ||
expected: -1, | ||
}, | ||
{ | ||
desc: "one SampleStream with one sample at zero time", | ||
sampleStreams: []queryrange.SampleStream{ | ||
{ | ||
Samples: []cortexpb.Sample{ | ||
{TimestampMs: 0}, | ||
}, | ||
}, | ||
}, | ||
expected: 0, | ||
}, | ||
{ | ||
desc: "one SampleStream with one sample", | ||
sampleStreams: []queryrange.SampleStream{ | ||
{ | ||
Samples: []cortexpb.Sample{ | ||
{TimestampMs: 1}, | ||
}, | ||
}, | ||
}, | ||
expected: 1, | ||
}, | ||
{ | ||
desc: "two SampleStreams, first is the earliest", | ||
sampleStreams: []queryrange.SampleStream{ | ||
{ | ||
Samples: []cortexpb.Sample{ | ||
{TimestampMs: 1}, | ||
}, | ||
}, | ||
{ | ||
Samples: []cortexpb.Sample{ | ||
{TimestampMs: 2}, | ||
}, | ||
}, | ||
}, | ||
expected: 1, | ||
}, | ||
{ | ||
desc: "three SampleStreams, second is earliest", | ||
sampleStreams: []queryrange.SampleStream{ | ||
{ | ||
Samples: []cortexpb.Sample{ | ||
{TimestampMs: 2}, | ||
{TimestampMs: 3}, | ||
}, | ||
}, | ||
{ | ||
Samples: []cortexpb.Sample{ | ||
{TimestampMs: 1}, | ||
}, | ||
}, | ||
{ | ||
Samples: []cortexpb.Sample{ | ||
{TimestampMs: 2}, | ||
}, | ||
}, | ||
}, | ||
expected: 1, | ||
}, | ||
{ | ||
desc: "three SampleStreams, last is earliest", | ||
sampleStreams: []queryrange.SampleStream{ | ||
{ | ||
Samples: []cortexpb.Sample{ | ||
{TimestampMs: 2}, | ||
{TimestampMs: 3}, | ||
}, | ||
}, | ||
{ | ||
Samples: []cortexpb.Sample{ | ||
{TimestampMs: 2}, | ||
}, | ||
}, | ||
{ | ||
Samples: []cortexpb.Sample{ | ||
{TimestampMs: 1}, | ||
}, | ||
}, | ||
}, | ||
expected: 1, | ||
}, | ||
} { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
pr := queryrange.NewEmptyPrometheusResponse() | ||
pr.Data.Result = tc.sampleStreams | ||
res := minResponseTime(pr) | ||
testutil.Equals(t, tc.expected, res) | ||
}) | ||
} | ||
} |