Skip to content

Commit

Permalink
Updated prometheus common to v0.40.0 and queryrange.Sample fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rabenhorst committed Feb 27, 2023
1 parent ece82d3 commit 3281b75
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -62,7 +62,7 @@ require (
github.com/prometheus/alertmanager v0.25.0
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/client_model v0.3.0
github.com/prometheus/common v0.39.1-0.20230202092144-f9c1994be032
github.com/prometheus/common v0.40.0
github.com/prometheus/exporter-toolkit v0.8.2
// Prometheus maps version 2.x.y to tags v0.x.y.
github.com/prometheus/prometheus v0.42.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -802,8 +802,8 @@ github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9
github.com/prometheus/common v0.29.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
github.com/prometheus/common v0.37.0/go.mod h1:phzohg0JFMnBEFGxTDbfu3QyL5GI8gTQJFhYO5B3mfA=
github.com/prometheus/common v0.39.1-0.20230202092144-f9c1994be032 h1:OKL/rHv39LgZmRQZZcUOCzl0UuFu3OC6IMofPoseG0Y=
github.com/prometheus/common v0.39.1-0.20230202092144-f9c1994be032/go.mod h1:L65ZJPSmfn/UBWLQIHV7dBrKFidB/wPlF1y5TlSt9OE=
github.com/prometheus/common v0.40.0 h1:Afz7EVRqGg2Mqqf4JuF9vdvp1pi220m55Pi9T2JnO4Q=
github.com/prometheus/common v0.40.0/go.mod h1:L65ZJPSmfn/UBWLQIHV7dBrKFidB/wPlF1y5TlSt9OE=
github.com/prometheus/common/sigv4 v0.1.0 h1:qoVebwtwwEhS85Czm2dSROY5fTo2PAPEVdDeppTwGX4=
github.com/prometheus/common/sigv4 v0.1.0/go.mod h1:2Jkxxk9yYvCkE5G1sQT7GuEXm57JrvHu9k5YwTjsNtI=
github.com/prometheus/exporter-toolkit v0.8.2 h1:sbJAfBXQFkG6sUkbwBun8MNdzW9+wd5YfPYofbmj0YM=
Expand Down
6 changes: 3 additions & 3 deletions pkg/queryfrontend/queryinstant_codec.go
Expand Up @@ -285,7 +285,7 @@ func vectorMerge(req queryrange.Request, resps []*queryrange.PrometheusInstantQu
if existingSample, ok := output[metric]; !ok {
output[metric] = s
metrics = append(metrics, metric) // Preserve the order of metric.
} else if existingSample.GetSample().TimestampMs < s.GetSample().TimestampMs {
} else if existingSample.Timestamp < s.Timestamp {
// Choose the latest sample if we see overlap.
output[metric] = s
}
Expand Down Expand Up @@ -324,9 +324,9 @@ func vectorMerge(req queryrange.Request, resps []*queryrange.PrometheusInstantQu
// Order is determined by vector
switch sortPlan {
case sortByValuesAsc:
return samples[i].s.Sample.Value < samples[j].s.Sample.Value
return samples[i].s.SampleValue < samples[j].s.SampleValue
case sortByValuesDesc:
return samples[i].s.Sample.Value > samples[j].s.Sample.Value
return samples[i].s.SampleValue > samples[j].s.SampleValue
}
return samples[i].metric < samples[j].metric
})
Expand Down
24 changes: 16 additions & 8 deletions pkg/queryfrontend/queryinstant_codec_test.go
Expand Up @@ -348,7 +348,8 @@ func TestMergeResponse(t *testing.T) {
Vector: &queryrange.Vector{
Samples: []*queryrange.Sample{
{
Sample: cortexpb.Sample{TimestampMs: 0, Value: 1},
Timestamp: 0,
SampleValue: 1,
Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{
"__name__": "up",
"job": "foo",
Expand All @@ -369,7 +370,8 @@ func TestMergeResponse(t *testing.T) {
Vector: &queryrange.Vector{
Samples: []*queryrange.Sample{
{
Sample: cortexpb.Sample{TimestampMs: 0, Value: 2},
Timestamp: 0,
SampleValue: 2,
Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{
"__name__": "up",
"job": "bar",
Expand All @@ -391,14 +393,16 @@ func TestMergeResponse(t *testing.T) {
Vector: &queryrange.Vector{
Samples: []*queryrange.Sample{
{
Sample: cortexpb.Sample{TimestampMs: 0, Value: 1},
Timestamp: 0,
SampleValue: 1,
Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{
"__name__": "up",
"job": "foo",
})),
},
{
Sample: cortexpb.Sample{TimestampMs: 0, Value: 2},
Timestamp: 0,
SampleValue: 2,
Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{
"__name__": "up",
"job": "bar",
Expand Down Expand Up @@ -426,7 +430,8 @@ func TestMergeResponse(t *testing.T) {
Vector: &queryrange.Vector{
Samples: []*queryrange.Sample{
{
Sample: cortexpb.Sample{TimestampMs: 0, Value: 1},
Timestamp: 0,
SampleValue: 1,
Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{
"__name__": "up",
"job": "foo",
Expand All @@ -447,7 +452,8 @@ func TestMergeResponse(t *testing.T) {
Vector: &queryrange.Vector{
Samples: []*queryrange.Sample{
{
Sample: cortexpb.Sample{TimestampMs: 0, Value: 2},
Timestamp: 0,
SampleValue: 2,
Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{
"__name__": "up",
"job": "bar",
Expand All @@ -469,14 +475,16 @@ func TestMergeResponse(t *testing.T) {
Vector: &queryrange.Vector{
Samples: []*queryrange.Sample{
{
Sample: cortexpb.Sample{TimestampMs: 0, Value: 1},
Timestamp: 0,
SampleValue: 1,
Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{
"__name__": "up",
"job": "foo",
})),
},
{
Sample: cortexpb.Sample{TimestampMs: 0, Value: 2},
Timestamp: 0,
SampleValue: 2,
Labels: cortexpb.FromLabelsToLabelAdapters(labels.FromMap(map[string]string{
"__name__": "up",
"job": "bar",
Expand Down

0 comments on commit 3281b75

Please sign in to comment.