Skip to content

Commit 34b87cd

Browse files
authored
add more unit test coverage for querying native histograms (#6031)
Signed-off-by: Ben Ye <[email protected]>
1 parent 595287d commit 34b87cd

File tree

10 files changed

+1351
-644
lines changed

10 files changed

+1351
-644
lines changed

pkg/ingester/client/compat.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,25 +113,6 @@ func ToQueryResponse(matrix model.Matrix) *QueryResponse {
113113
return resp
114114
}
115115

116-
// FromQueryResponse unpacks a QueryResponse proto.
117-
func FromQueryResponse(resp *QueryResponse) model.Matrix {
118-
m := make(model.Matrix, 0, len(resp.Timeseries))
119-
for _, ts := range resp.Timeseries {
120-
var ss model.SampleStream
121-
ss.Metric = cortexpb.FromLabelAdaptersToMetric(ts.Labels)
122-
ss.Values = make([]model.SamplePair, 0, len(ts.Samples))
123-
for _, s := range ts.Samples {
124-
ss.Values = append(ss.Values, model.SamplePair{
125-
Value: model.SampleValue(s.Value),
126-
Timestamp: model.Time(s.TimestampMs),
127-
})
128-
}
129-
m = append(m, &ss)
130-
}
131-
132-
return m
133-
}
134-
135116
// ToMetricsForLabelMatchersRequest builds a MetricsForLabelMatchersRequest proto
136117
func ToMetricsForLabelMatchersRequest(from, to model.Time, matchers []*labels.Matcher) (*MetricsForLabelMatchersRequest, error) {
137118
ms, err := toLabelMatchers(matchers)

pkg/ingester/client/compat_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package client
22

33
import (
4-
"fmt"
54
"reflect"
6-
"sort"
75
"strconv"
86
"testing"
97

@@ -75,36 +73,6 @@ func matchersEqual(expected, actual []*labels.Matcher) bool {
7573
return true
7674
}
7775

78-
func buildTestMatrix(numSeries int, samplesPerSeries int, offset int) model.Matrix {
79-
m := make(model.Matrix, 0, numSeries)
80-
for i := 0; i < numSeries; i++ {
81-
ss := model.SampleStream{
82-
Metric: model.Metric{
83-
model.MetricNameLabel: model.LabelValue(fmt.Sprintf("testmetric_%d", i)),
84-
model.JobLabel: "testjob",
85-
},
86-
Values: make([]model.SamplePair, 0, samplesPerSeries),
87-
}
88-
for j := 0; j < samplesPerSeries; j++ {
89-
ss.Values = append(ss.Values, model.SamplePair{
90-
Timestamp: model.Time(i + j + offset),
91-
Value: model.SampleValue(i + j + offset),
92-
})
93-
}
94-
m = append(m, &ss)
95-
}
96-
sort.Sort(m)
97-
return m
98-
}
99-
100-
func TestQueryResponse(t *testing.T) {
101-
want := buildTestMatrix(10, 10, 10)
102-
have := FromQueryResponse(ToQueryResponse(want))
103-
if !reflect.DeepEqual(have, want) {
104-
t.Fatalf("Bad FromQueryResponse(ToQueryResponse) round trip")
105-
}
106-
}
107-
10876
// The main usecase for `LabelsToKeyString` is to generate hashKeys
10977
// for maps. We are benchmarking that here.
11078
func BenchmarkSeriesMap(b *testing.B) {

pkg/querier/batch/batch.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ func (a *iteratorAdapter) AtHistogram(h *histogram.Histogram) (int64, *histogram
162162

163163
// AtFloatHistogram implements chunkenc.Iterator.
164164
func (a *iteratorAdapter) AtFloatHistogram(h *histogram.FloatHistogram) (int64, *histogram.FloatHistogram) {
165+
// PromQL engine always selects float histogram in its implementation so might call AtFloatHistogram
166+
// even if it is a histogram. https://github.com/prometheus/prometheus/blob/v2.53.0/promql/engine.go#L2276
167+
if a.curr.ValType == chunkenc.ValHistogram {
168+
return a.curr.Timestamps[a.curr.Index], a.curr.Histograms[a.curr.Index].ToFloat(h)
169+
}
165170
return a.curr.Timestamps[a.curr.Index], a.curr.FloatHistograms[a.curr.Index]
166171
}
167172

pkg/querier/batch/batch_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ func TestSeekCorrectlyDealWithSinglePointChunks(t *testing.T) {
147147
actual, val := sut.AtHistogram(nil)
148148
require.Equal(t, histograms[0], val)
149149
require.Equal(t, int64(1*time.Second/time.Millisecond), actual)
150+
151+
// Histogram chunk should support querying float histograms since it is what Query Engine does.
152+
actualT, fh := sut.AtFloatHistogram(nil)
153+
require.Equal(t, histograms[0].ToFloat(nil), fh)
154+
require.Equal(t, int64(1*time.Second/time.Millisecond), actualT)
150155
case promchunk.PrometheusFloatHistogramChunk:
151156
actual, val := sut.AtFloatHistogram(nil)
152157
require.Equal(t, histograms[0].ToFloat(nil), val)

pkg/querier/block_test.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)