From 0d242197b36e3bb6bf338b39228d32dcf75bd5ac Mon Sep 17 00:00:00 2001 From: Sebastian Rabenhorst Date: Tue, 14 Feb 2023 14:58:32 +0100 Subject: [PATCH] Fixed qfe --- internal/cortex/querier/queryrange/compat.go | 10 +++--- .../cortex/querier/queryrange/query_range.go | 3 +- .../querier/queryrange/queryrange.pb.go | 36 +++++++++---------- .../querier/queryrange/queryrange.proto | 2 +- test/e2e/native_histograms_test.go | 19 +++++----- 5 files changed, 36 insertions(+), 34 deletions(-) diff --git a/internal/cortex/querier/queryrange/compat.go b/internal/cortex/querier/queryrange/compat.go index 9640fa59b7e..9d7e77720ab 100644 --- a/internal/cortex/querier/queryrange/compat.go +++ b/internal/cortex/querier/queryrange/compat.go @@ -21,7 +21,7 @@ func toModelSampleHistogramPair(s SampleHistogramPair) model.SampleHistogramPair func fromModelSampleHistogramPair(modelSampleHistogram model.SampleHistogramPair) (s SampleHistogramPair) { return SampleHistogramPair{ Timestamp: int64(modelSampleHistogram.Timestamp), - Histogram: fromModelSampleHistogram(&modelSampleHistogram.Histogram), + Histogram: fromModelSampleHistogram(modelSampleHistogram.Histogram), } } @@ -33,7 +33,7 @@ func fromModelSampleHistogram(modelSampleHistogram *model.SampleHistogram) (s Sa Lower: float64(b.Lower), Upper: float64(b.Upper), Count: float64(b.Count), - Boundaries: int64(b.Boundaries), + Boundaries: b.Boundaries, } } @@ -44,7 +44,7 @@ func fromModelSampleHistogram(modelSampleHistogram *model.SampleHistogram) (s Sa } } -func toModelSampleHistogram(s SampleHistogram) model.SampleHistogram { +func toModelSampleHistogram(s SampleHistogram) *model.SampleHistogram { modelBuckets := make([]*model.HistogramBucket, len(s.Buckets)) for i, b := range s.Buckets { @@ -52,11 +52,11 @@ func toModelSampleHistogram(s SampleHistogram) model.SampleHistogram { Lower: model.FloatString(b.Lower), Upper: model.FloatString(b.Upper), Count: model.FloatString(b.Count), - Boundaries: int(b.Boundaries), + Boundaries: b.Boundaries, } } - return model.SampleHistogram{ + return &model.SampleHistogram{ Count: model.FloatString(s.Count), Sum: model.FloatString(s.Sum), Buckets: modelBuckets, diff --git a/internal/cortex/querier/queryrange/query_range.go b/internal/cortex/querier/queryrange/query_range.go index 7c4ba5e7762..0cb17b27949 100644 --- a/internal/cortex/querier/queryrange/query_range.go +++ b/internal/cortex/querier/queryrange/query_range.go @@ -476,8 +476,7 @@ func (s *Sample) MarshalJSON() ([]byte, error) { sample.Value = model.SampleValue(s.SampleValue) sample.Timestamp = model.Time(s.Timestamp) if s.Histogram != nil { - msh := toModelSampleHistogram(*s.Histogram) - sample.Histogram = &msh + sample.Histogram = toModelSampleHistogram(*s.Histogram) } return json.Marshal(sample) } diff --git a/internal/cortex/querier/queryrange/queryrange.pb.go b/internal/cortex/querier/queryrange/queryrange.pb.go index a3359d8fcaa..1b57e8f3c2f 100644 --- a/internal/cortex/querier/queryrange/queryrange.pb.go +++ b/internal/cortex/querier/queryrange/queryrange.pb.go @@ -1201,7 +1201,7 @@ func (m *SampleHistogram) GetBuckets() []*HistogramBucket { } type HistogramBucket struct { - Boundaries int64 `protobuf:"varint,1,opt,name=boundaries,proto3" json:"boundaries,omitempty"` + Boundaries int32 `protobuf:"varint,1,opt,name=boundaries,proto3" json:"boundaries,omitempty"` Lower float64 `protobuf:"fixed64,2,opt,name=lower,proto3" json:"lower,omitempty"` Upper float64 `protobuf:"fixed64,3,opt,name=upper,proto3" json:"upper,omitempty"` Count float64 `protobuf:"fixed64,4,opt,name=count,proto3" json:"count,omitempty"` @@ -1243,7 +1243,7 @@ func (m *HistogramBucket) XXX_DiscardUnknown() { var xxx_messageInfo_HistogramBucket proto.InternalMessageInfo -func (m *HistogramBucket) GetBoundaries() int64 { +func (m *HistogramBucket) GetBoundaries() int32 { if m != nil { return m.Boundaries } @@ -1475,7 +1475,7 @@ func init() { } var fileDescriptor_9af7607b46ac39b7 = []byte{ - // 1356 bytes of a gzipped FileDescriptorProto + // 1357 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x57, 0xcd, 0x6f, 0x1b, 0x45, 0x1b, 0xef, 0xda, 0xce, 0xc6, 0x7e, 0x9c, 0x37, 0x69, 0x27, 0x7d, 0xdf, 0x6e, 0xf2, 0x86, 0xac, 0xd9, 0x22, 0x14, 0x4a, 0x6b, 0x4b, 0x41, 0xe5, 0x50, 0x89, 0x42, 0x97, 0x16, 0x52, 0xd4, 0x8f, @@ -1547,20 +1547,20 @@ var fileDescriptor_9af7607b46ac39b7 = []byte{ 0x16, 0x7d, 0xb7, 0xb6, 0xdc, 0x4f, 0x61, 0x65, 0x0e, 0x23, 0x23, 0x18, 0x24, 0x59, 0x2c, 0x94, 0x35, 0x07, 0xeb, 0x8d, 0x7c, 0x44, 0xf0, 0x4c, 0xdb, 0x70, 0xb0, 0x5c, 0xa2, 0xab, 0xb0, 0xd8, 0xcf, 0x06, 0x4f, 0xa8, 0x28, 0x3a, 0xae, 0x62, 0xb9, 0xb4, 0xa9, 0x30, 0xb8, 0xc0, 0x06, 0x1c, - 0x56, 0xe6, 0x78, 0x68, 0x13, 0xa0, 0x9f, 0x64, 0xf1, 0x90, 0xb0, 0xa8, 0x18, 0x71, 0xd8, 0xa2, - 0x48, 0x8f, 0xc6, 0xc9, 0x17, 0x94, 0x19, 0xeb, 0x7a, 0x23, 0xa9, 0x59, 0x9a, 0x52, 0xfd, 0x6d, - 0x72, 0xb0, 0xde, 0x94, 0xde, 0x37, 0x2c, 0xef, 0x83, 0xcf, 0x61, 0x59, 0xbe, 0x32, 0xe8, 0x70, - 0x76, 0xf3, 0x5a, 0x83, 0xfa, 0x13, 0x7a, 0x60, 0xae, 0x0c, 0x8b, 0xd3, 0xdc, 0x97, 0x5b, 0x2c, - 0x7f, 0xe4, 0x4b, 0x88, 0x3e, 0x17, 0x34, 0x16, 0xc5, 0x49, 0xac, 0x7c, 0x85, 0x6e, 0x29, 0x56, - 0xb8, 0x62, 0x4e, 0x4f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xb0, 0x2c, 0x5f, 0x19, 0x74, + 0x38, 0xbb, 0x79, 0xad, 0x41, 0xfd, 0x09, 0x3d, 0x30, 0x57, 0x86, 0xc5, 0x69, 0xee, 0xcb, 0x2d, + 0x96, 0x3f, 0xf2, 0x25, 0x44, 0x9f, 0x0b, 0x1a, 0x8b, 0xe2, 0x24, 0x56, 0xbe, 0x42, 0xb7, 0x14, + 0x2b, 0x5c, 0x31, 0xa7, 0xa7, 0x80, 0xe2, 0x62, 0x11, 0xfc, 0xe0, 0x80, 0xab, 0x41, 0xc8, 0x2f, + 0xde, 0x63, 0x7a, 0x6c, 0xab, 0x7e, 0x55, 0x84, 0xe2, 0x69, 0xb6, 0xa6, 0x9f, 0x66, 0xaa, 0x1d, + 0xb4, 0x17, 0x34, 0x1e, 0xea, 0x37, 0x5a, 0x07, 0x9a, 0x82, 0x91, 0x01, 0x7d, 0x1c, 0x0d, 0xcd, + 0x75, 0xab, 0xb8, 0x1b, 0x29, 0xf2, 0xed, 0x21, 0xba, 0x0e, 0x4d, 0x66, 0xc2, 0x31, 0x4f, 0xb6, + 0xf3, 0x87, 0x9e, 0x6c, 0x37, 0xe2, 0x83, 0x70, 0x69, 0x9a, 0xfb, 0x33, 0x24, 0x9e, 0xad, 0x3e, + 0x69, 0x34, 0xeb, 0x67, 0x1b, 0xc1, 0x65, 0x9d, 0x1a, 0xeb, 0xa9, 0xb5, 0x0e, 0xcd, 0x61, 0xc4, + 0xe5, 0xd0, 0x1d, 0x2a, 0xc7, 0x9b, 0x78, 0xb6, 0x0f, 0xbd, 0x17, 0x2f, 0x37, 0x9d, 0x9f, 0x5e, + 0x6e, 0x3a, 0xbf, 0xbd, 0xdc, 0x74, 0x3e, 0xb5, 0x5e, 0xda, 0x7d, 0x57, 0xd9, 0x7c, 0xe7, 0xcf, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x17, 0xc3, 0x35, 0xd6, 0xaa, 0x0f, 0x00, 0x00, } func (m *PrometheusRequestHeader) Marshal() (dAtA []byte, err error) { @@ -5928,7 +5928,7 @@ func (m *HistogramBucket) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Boundaries |= int64(b&0x7F) << shift + m.Boundaries |= int32(b&0x7F) << shift if b < 0x80 { break } diff --git a/internal/cortex/querier/queryrange/queryrange.proto b/internal/cortex/querier/queryrange/queryrange.proto index 032cdecdfdb..6f05fc16709 100644 --- a/internal/cortex/querier/queryrange/queryrange.proto +++ b/internal/cortex/querier/queryrange/queryrange.proto @@ -125,7 +125,7 @@ message SampleHistogram { } message HistogramBucket { - int64 boundaries = 1; + int32 boundaries = 1; double lower = 2; double upper = 3; double count = 4; diff --git a/test/e2e/native_histograms_test.go b/test/e2e/native_histograms_test.go index 5b901ed411d..c212423613e 100644 --- a/test/e2e/native_histograms_test.go +++ b/test/e2e/native_histograms_test.go @@ -68,7 +68,7 @@ func TestQueryNativeHistograms(t *testing.T) { t.Run("query histogram using histogram_count fn and deduplication", func(t *testing.T) { queryAndAssert(t, ctx, querier.Endpoint("http"), func() string { return fmt.Sprintf("histogram_count(%v)", testHistogramMetricName) }, ts, promclient.QueryOptions{Deduplicate: true}, model.Vector{ &model.Sample{ - Value: 17, + Value: 34, Metric: model.Metric{ "foo": "bar", "prometheus": "prom-ha", @@ -341,12 +341,10 @@ func expectedHistogramModelVector(histogram *histogram.Histogram, externalLabels metrics[model.LabelName(labelKey)] = model.LabelValue(labelValue) } - sh := histogramToSampleHistogram(histogram) - return model.Vector{ &model.Sample{ Metric: metrics, - Histogram: &sh, + Histogram: histogramToSampleHistogram(histogram), }, } } @@ -377,17 +375,22 @@ func expectedHistogramModelMatrix(histograms []*histogram.Histogram, startTime t } } -func histogramToSampleHistogram(h *histogram.Histogram) model.SampleHistogram { +func histogramToSampleHistogram(h *histogram.Histogram) *model.SampleHistogram { var buckets []*model.HistogramBucket + it := h.NegativeBucketIterator() + for it.Next() { + buckets = append([]*model.HistogramBucket{bucketToSampleHistogramBucket(it.At())}, buckets...) + } + buckets = append(buckets, bucketToSampleHistogramBucket(h.ZeroBucket())) - it := h.PositiveBucketIterator() + it = h.PositiveBucketIterator() for it.Next() { buckets = append(buckets, bucketToSampleHistogramBucket(it.At())) } - return model.SampleHistogram{ + return &model.SampleHistogram{ Count: model.FloatString(h.Count), Sum: model.FloatString(h.Sum), Buckets: buckets, @@ -403,7 +406,7 @@ func bucketToSampleHistogramBucket(bucket histogram.Bucket[uint64]) *model.Histo } } -func boundaries(bucket histogram.Bucket[uint64]) int { +func boundaries(bucket histogram.Bucket[uint64]) int32 { switch { case bucket.UpperInclusive && !bucket.LowerInclusive: return 0