From fee7e0c00cfb4277591de9217abee91ce0d5b048 Mon Sep 17 00:00:00 2001 From: Paurush Garg Date: Thu, 28 May 2026 17:50:44 -0700 Subject: [PATCH] add WrappedHistogram with size limit before unmarshal Signed-off-by: Paurush Garg --- CHANGELOG.md | 1 + integration/remote_write_v2_test.go | 4 +- pkg/cortexpb/compat.go | 4 +- pkg/cortexpb/cortex.pb.go | 270 ++++++++++++---------------- pkg/cortexpb/cortex.proto | 4 +- pkg/cortexpb/histograms.go | 50 ++++++ pkg/cortexpb/timeseries.go | 3 +- pkg/cortexpb/timeseries_test.go | 60 +++++++ pkg/cortexpb/timeseriesv2.go | 2 +- pkg/cortexpb/timeseriesv2_test.go | 2 +- pkg/distributor/distributor.go | 10 +- pkg/distributor/distributor_test.go | 36 ++-- pkg/ingester/client/compat.go | 6 +- pkg/ingester/ingester.go | 4 +- pkg/ingester/ingester_test.go | 270 +++++++++++----------------- pkg/ruler/compat.go | 6 +- pkg/ruler/compat_test.go | 16 +- pkg/util/http_test.go | 2 +- pkg/util/push/otlp.go | 6 +- pkg/util/push/push_test.go | 47 +++-- 20 files changed, 422 insertions(+), 381 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ec5a010b22..8b2495c0f54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ * [ENHANCEMENT] Instrument Ingester CPU profile with source for read APIs. #7494 * [ENHANCEMENT] Ingester: Convert expanded postings cache from FIFO to LRU eviction to retain frequently-queried entries under memory pressure. #7510 * [ENHANCEMENT] Querier: Detach series label and chunk data from gRPC unmarshal buffers in store-gateway streaming path, allowing the Go GC to reclaim receive buffers. #7519 +* [ENHANCEMENT] Distributor: Add `WrappedHistogram` with configurable size limit (`-validation.max-native-histogram-size-bytes`) to cap native histogram protobuf size before unmarshalling. #7570 * [BUGFIX] Querier: Fix queryWithRetry and labelsWithRetry returning (nil, nil) on cancelled context by propagating ctx.Err(). #7370 * [BUGFIX] Metrics Helper: Fix non-deterministic bucket order in merged histograms by sorting buckets after map iteration, matching Prometheus client library behavior. #7380 * [BUGFIX] Distributor: Return HTTP 401 Unauthorized when tenant ID resolution fails in the Prometheus Remote Write 2.0 path. #7389 diff --git a/integration/remote_write_v2_test.go b/integration/remote_write_v2_test.go index c61cc1aa6d7..f1455848b8b 100644 --- a/integration/remote_write_v2_test.go +++ b/integration/remote_write_v2_test.go @@ -625,7 +625,7 @@ func TestIngest_CreatedTimestampFallback(t *testing.T) { TimeSeriesV2: &cortexpb.TimeSeriesV2{ LabelsRefs: []uint32{1, 2}, CreatedTimestamp: e2e.TimeToMilliseconds(startTs), - Histograms: []cortexpb.Histogram{h}, + Histograms: []cortexpb.WrappedHistogram{cortexpb.WrapHistogram(h)}, }, }, }, @@ -778,7 +778,7 @@ func TestIngest_StartAndCreatedTimestampIgnoredWhenDisabled(t *testing.T) { TimeSeriesV2: &cortexpb.TimeSeriesV2{ LabelsRefs: []uint32{1, 2}, CreatedTimestamp: e2e.TimeToMilliseconds(startTs), - Histograms: []cortexpb.Histogram{h}, + Histograms: []cortexpb.WrappedHistogram{cortexpb.WrapHistogram(h)}, }, }}, } diff --git a/pkg/cortexpb/compat.go b/pkg/cortexpb/compat.go index 9579eb37e56..a9c5b941f5d 100644 --- a/pkg/cortexpb/compat.go +++ b/pkg/cortexpb/compat.go @@ -20,7 +20,7 @@ import ( // ToWriteRequest converts matched slices of Labels, Samples, Metadata and Histograms into a WriteRequest proto. // It gets timeseries from the pool, so ReuseSlice() should be called when done. -func ToWriteRequest(lbls []labels.Labels, samples []Sample, metadata []*MetricMetadata, histograms []Histogram, source SourceEnum) *WriteRequest { +func ToWriteRequest(lbls []labels.Labels, samples []Sample, metadata []*MetricMetadata, histograms []WrappedHistogram, source SourceEnum) *WriteRequest { req := &WriteRequest{ Timeseries: PreallocTimeseriesSliceFromPool(), Metadata: metadata, @@ -44,7 +44,7 @@ func ToWriteRequest(lbls []labels.Labels, samples []Sample, metadata []*MetricMe return req } -func (w *WriteRequest) AddHistogramTimeSeries(lbls []labels.Labels, histograms []Histogram) { +func (w *WriteRequest) AddHistogramTimeSeries(lbls []labels.Labels, histograms []WrappedHistogram) { for i := range lbls { ts := TimeseriesFromPool() ts.Labels = append(ts.Labels, FromLabelsToLabelAdapters(lbls[i])...) diff --git a/pkg/cortexpb/cortex.pb.go b/pkg/cortexpb/cortex.pb.go index 6037803b267..88f24f406af 100644 --- a/pkg/cortexpb/cortex.pb.go +++ b/pkg/cortexpb/cortex.pb.go @@ -326,8 +326,8 @@ type TimeSeriesV2 struct { // streaming), in healthy cases, there will be only one sample or histogram. // // Samples and histograms are sorted by timestamp (older first). - Samples []Sample `protobuf:"bytes,2,rep,name=samples,proto3" json:"samples"` - Histograms []Histogram `protobuf:"bytes,3,rep,name=histograms,proto3" json:"histograms"` + Samples []Sample `protobuf:"bytes,2,rep,name=samples,proto3" json:"samples"` + Histograms []WrappedHistogram `protobuf:"bytes,3,rep,name=histograms,proto3,customtype=WrappedHistogram" json:"histograms"` // exemplars represents an optional set of exemplars attached to this series' samples. Exemplars []ExemplarV2 `protobuf:"bytes,4,rep,name=exemplars,proto3" json:"exemplars"` // metadata represents the metadata associated with the given series' samples. @@ -397,13 +397,6 @@ func (m *TimeSeriesV2) GetSamples() []Sample { return nil } -func (m *TimeSeriesV2) GetHistograms() []Histogram { - if m != nil { - return m.Histograms - } - return nil -} - func (m *TimeSeriesV2) GetExemplars() []ExemplarV2 { if m != nil { return m.Exemplars @@ -696,9 +689,9 @@ func (m *WriteResponse) GetExemplars() int64 { type TimeSeries struct { Labels []LabelAdapter `protobuf:"bytes,1,rep,name=labels,proto3,customtype=LabelAdapter" json:"labels"` // Sorted by time, oldest sample first. - Samples []Sample `protobuf:"bytes,2,rep,name=samples,proto3" json:"samples"` - Exemplars []Exemplar `protobuf:"bytes,3,rep,name=exemplars,proto3" json:"exemplars"` - Histograms []Histogram `protobuf:"bytes,4,rep,name=histograms,proto3" json:"histograms"` + Samples []Sample `protobuf:"bytes,2,rep,name=samples,proto3" json:"samples"` + Exemplars []Exemplar `protobuf:"bytes,3,rep,name=exemplars,proto3" json:"exemplars"` + Histograms []WrappedHistogram `protobuf:"bytes,4,rep,name=histograms,proto3,customtype=WrappedHistogram" json:"histograms"` } func (m *TimeSeries) Reset() { *m = TimeSeries{} } @@ -747,13 +740,6 @@ func (m *TimeSeries) GetExemplars() []Exemplar { return nil } -func (m *TimeSeries) GetHistograms() []Histogram { - if m != nil { - return m.Histograms - } - return nil -} - type LabelPair struct { Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` @@ -1383,104 +1369,104 @@ func init() { func init() { proto.RegisterFile("cortex.proto", fileDescriptor_893a47d0a749d749) } var fileDescriptor_893a47d0a749d749 = []byte{ - // 1540 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x57, 0x3b, 0x6f, 0x1b, 0xc7, - 0x16, 0xe6, 0xf2, 0xcd, 0xc3, 0x87, 0x57, 0x63, 0xda, 0x5e, 0xc9, 0xf6, 0x52, 0xa6, 0x71, 0xef, - 0x15, 0x7c, 0x0d, 0x5d, 0x43, 0xc6, 0x75, 0x12, 0xc3, 0x08, 0x40, 0xca, 0x94, 0x45, 0xd8, 0x24, - 0x85, 0x21, 0x25, 0xc3, 0x69, 0x16, 0x2b, 0x72, 0x28, 0x2e, 0xcc, 0xdd, 0x65, 0x76, 0x86, 0x86, - 0x95, 0x2a, 0x55, 0x90, 0x74, 0x69, 0xd2, 0xa4, 0x0b, 0xdc, 0xa4, 0x4d, 0x9d, 0x3f, 0xe0, 0x52, - 0x5d, 0x0c, 0x03, 0x11, 0x62, 0xb9, 0x71, 0x52, 0xb9, 0xc8, 0x0f, 0x08, 0x66, 0xf6, 0x49, 0x51, - 0x82, 0x93, 0xc0, 0x45, 0xba, 0x39, 0xdf, 0x39, 0x33,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xe4, 0xb5, 0xc2, 0x21, 0x3a, 0x2c, 0x86, 0xfd, 0x30, 0xf4, 0x11, - 0xc0, 0xc8, 0xa0, 0xcc, 0xde, 0x73, 0x74, 0x93, 0x7a, 0xed, 0x79, 0x36, 0xdc, 0xb4, 0xe9, 0xfb, - 0xbc, 0x7d, 0x91, 0x60, 0xf4, 0x21, 0xe4, 0xc8, 0x53, 0x62, 0x4e, 0xc6, 0xba, 0xe3, 0xd6, 0x72, - 0x66, 0xac, 0x1a, 0x9e, 0x6b, 0x67, 0xcd, 0xdb, 0x1a, 0x06, 0xa3, 0x5b, 0x91, 0x89, 0x48, 0x89, - 0x5c, 0x95, 0x67, 0x26, 0x42, 0x78, 0x82, 0x8d, 0xe1, 0x34, 0xfc, 0x17, 0x16, 0xfa, 0x0e, 0xd1, - 0x19, 0x19, 0x68, 0xa2, 0xc2, 0x4c, 0x37, 0x27, 0xa2, 0xac, 0x09, 0x2c, 0x7b, 0x8e, 0x9e, 0x8f, - 0x57, 0x75, 0x80, 0x90, 0xc3, 0xbb, 0x53, 0x57, 0x86, 0xd4, 0x13, 0x7d, 0x3c, 0x75, 0x47, 0x5a, - 0xc2, 0xae, 0x81, 0x2e, 0x41, 0x2e, 0xbc, 0x29, 0x21, 0x6e, 0x0a, 0x81, 0xea, 0x4f, 0x71, 0x80, - 0x90, 0x2e, 0xba, 0x09, 0x49, 0xb6, 0x3f, 0x21, 0x8a, 0x24, 0x1a, 0xad, 0x72, 0xd2, 0x93, 0xbc, - 0x79, 0xef, 0xed, 0x4f, 0x08, 0x16, 0xc1, 0x68, 0x11, 0xb2, 0x23, 0x32, 0x9e, 0x70, 0x5a, 0xe2, - 0x82, 0x22, 0xce, 0x70, 0x9b, 0xcf, 0xdb, 0x22, 0x64, 0xa7, 0x96, 0xc1, 0x84, 0x2b, 0xe9, 0xba, - 0xb8, 0xcd, 0x5b, 0xe3, 0x67, 0x49, 0xdc, 0xec, 0x1d, 0x85, 0x2e, 0xc2, 0x85, 0x56,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 0x88, 0x0c, 0x24, 0x1e, 0x35, 0xba, - 0xb2, 0x84, 0xd2, 0x10, 0x6f, 0x77, 0xe4, 0x78, 0x28, 0x13, 0x89, 0xa5, 0xe4, 0x97, 0xcf, 0x54, - 0xa9, 0x9e, 0x81, 0x94, 0xc8, 0x47, 0xbd, 0x00, 0x10, 0xb6, 0x53, 0xf5, 0x0e, 0x40, 0x98, 0x7b, - 0xde, 0xd1, 0xf6, 0x70, 0x48, 0x89, 0x3b, 0x22, 0x0b, 0xd8, 0xb3, 0x38, 0x3e, 0x26, 0xd6, 0x1e, - 0x1b, 0x89, 0xc9, 0x28, 0x62, 0xcf, 0xba, 0x56, 0x01, 0x08, 0x7f, 0xdf, 0x73, 0x12, 0xb5, 0xad, - 0xa6, 0x1c, 0xe3, 0x42, 0x83, 0xb7, 0x1f, 0x34, 0x64, 0xa9, 0xfe, 0xf1, 0xc1, 0x2b, 0x35, 0xf6, - 0xe2, 0x95, 0x1a, 0x7b, 0xfb, 0x4a, 0x95, 0x3e, 0x3f, 0x52, 0xa5, 0xef, 0x8f, 0x54, 0xe9, 0xf9, - 0x91, 0x2a, 0x1d, 0x1c, 0xa9, 0xd2, 0x2f, 0x47, 0xaa, 0xf4, 0xe6, 0x48, 0x8d, 0xbd, 0x3d, 0x52, - 0xa5, 0xaf, 0x5f, 0xab, 0xb1, 0x83, 0xd7, 0x6a, 0xec, 0xc5, 0x6b, 0x35, 0xf6, 0x49, 0xf0, 0xc7, - 0x74, 0x37, 0x2d, 0xfe, 0x89, 0xde, 0xfc, 0x23, 0x00, 0x00, 0xff, 0xff, 0x75, 0x0f, 0x93, 0x48, - 0xb9, 0x0e, 0x00, 0x00, + // 1552 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x57, 0x3d, 0x6f, 0x1b, 0x47, + 0x1a, 0xe6, 0xf2, 0x9b, 0x2f, 0x3f, 0xbc, 0x1a, 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 0xd2, 0x90, 0x0b, 0x9a, + 0x16, 0x5d, 0x85, 0x5c, 0xdf, 0x9a, 0x4e, 0x98, 0x66, 0x4c, 0x98, 0x28, 0x79, 0x72, 0x33, 0x86, + 0xb3, 0x02, 0x6a, 0x4e, 0x18, 0xba, 0x06, 0x79, 0x97, 0x1e, 0x8e, 0x2d, 0xdd, 0xf5, 0x3b, 0x69, + 0x33, 0x86, 0x41, 0x80, 0x1b, 0x1c, 0x43, 0x32, 0x24, 0xe8, 0xd4, 0x14, 0x37, 0x49, 0x98, 0x3f, + 0xa2, 0x8b, 0x90, 0xa6, 0xfd, 0x11, 0x31, 0x75, 0x51, 0xdc, 0x05, 0xec, 0xad, 0xd0, 0xdf, 0xa0, + 0xf4, 0x29, 0x71, 0x2c, 0x8d, 0x8d, 0x1c, 0x42, 0x47, 0xd6, 0x78, 0x20, 0x0a, 0x2d, 0xe1, 0x22, + 0x47, 0x7b, 0x3e, 0x88, 0xfe, 0xee, 0x85, 0x85, 0xba, 0xd2, 0x42, 0x97, 0x84, 0x0b, 0x1c, 0x5f, + 0xf7, 0xb5, 0xdd, 0x00, 0x39, 0x12, 0xe7, 0x0a, 0xcc, 0x08, 0x81, 0x12, 0x2e, 0x05, 0x91, 0xae, + 0xc8, 0x1a, 0x94, 0x26, 0x64, 0x5f, 0x67, 0xc6, 0x53, 0xa2, 0x51, 0x5b, 0x9f, 0x50, 0x25, 0x7b, + 0xf2, 0x77, 0x44, 0x7d, 0xda, 0x7f, 0x42, 0x58, 0xd7, 0xd6, 0x27, 0x9e, 0x3b, 0x14, 0xfd, 0x1d, + 0x1c, 0xa3, 0xe8, 0x1f, 0x70, 0x2e, 0x38, 0x62, 0x40, 0xc6, 0x4c, 0xa7, 0x4a, 0x6e, 0x39, 0xb1, + 0x82, 0x70, 0x70, 0xf2, 0x7d, 0x81, 0xce, 0x04, 0x0a, 0x6d, 0x54, 0x81, 0xe5, 0xc4, 0x8a, 0x14, + 0x06, 0x0a, 0x61, 0xdc, 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, 0xbd, 0x51, 0x63, 0xef, + 0xdf, 0xa8, 0xd2, 0x67, 0xc7, 0xaa, 0xf4, 0xed, 0xb1, 0x2a, 0xbd, 0x3c, 0x56, 0xa5, 0xc3, 0x63, + 0x55, 0xfa, 0xf9, 0x58, 0x95, 0xde, 0x1d, 0xab, 0xb1, 0xf7, 0xc7, 0xaa, 0xf4, 0xe5, 0x5b, 0x35, + 0x76, 0xf8, 0x56, 0x8d, 0xbd, 0x7a, 0xab, 0xc6, 0xfe, 0x1f, 0xfc, 0x81, 0xdd, 0x4b, 0x8b, 0x7f, + 0xac, 0xb7, 0x7f, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x99, 0x5c, 0xe6, 0x17, 0xe1, 0x0e, 0x00, 0x00, } func (x SourceEnum) String() string { @@ -1666,7 +1652,7 @@ func (this *TimeSeriesV2) Equal(that interface{}) bool { return false } for i := range this.Histograms { - if !this.Histograms[i].Equal(&that1.Histograms[i]) { + if !this.Histograms[i].Equal(that1.Histograms[i]) { return false } } @@ -1864,7 +1850,7 @@ func (this *TimeSeries) Equal(that interface{}) bool { return false } for i := range this.Histograms { - if !this.Histograms[i].Equal(&that1.Histograms[i]) { + if !this.Histograms[i].Equal(that1.Histograms[i]) { return false } } @@ -2314,13 +2300,7 @@ func (this *TimeSeriesV2) GoString() string { } s = append(s, "Samples: "+fmt.Sprintf("%#v", vs)+",\n") } - if this.Histograms != nil { - vs := make([]*Histogram, len(this.Histograms)) - for i := range vs { - vs[i] = &this.Histograms[i] - } - s = append(s, "Histograms: "+fmt.Sprintf("%#v", vs)+",\n") - } + s = append(s, "Histograms: "+fmt.Sprintf("%#v", this.Histograms)+",\n") if this.Exemplars != nil { vs := make([]*ExemplarV2, len(this.Exemplars)) for i := range vs { @@ -2406,13 +2386,7 @@ func (this *TimeSeries) GoString() string { } s = append(s, "Exemplars: "+fmt.Sprintf("%#v", vs)+",\n") } - if this.Histograms != nil { - vs := make([]*Histogram, len(this.Histograms)) - for i := range vs { - vs[i] = &this.Histograms[i] - } - s = append(s, "Histograms: "+fmt.Sprintf("%#v", vs)+",\n") - } + s = append(s, "Histograms: "+fmt.Sprintf("%#v", this.Histograms)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -2807,11 +2781,11 @@ func (m *TimeSeriesV2) MarshalToSizedBuffer(dAtA []byte) (int, error) { if len(m.Histograms) > 0 { for iNdEx := len(m.Histograms) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.Histograms[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { + size := m.Histograms[iNdEx].Size() + i -= size + if _, err := m.Histograms[iNdEx].MarshalTo(dAtA[i:]); err != nil { return 0, err } - i -= size i = encodeVarintCortex(dAtA, i, uint64(size)) } i-- @@ -3070,11 +3044,11 @@ func (m *TimeSeries) MarshalToSizedBuffer(dAtA []byte) (int, error) { if len(m.Histograms) > 0 { for iNdEx := len(m.Histograms) - 1; iNdEx >= 0; iNdEx-- { { - size, err := m.Histograms[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { + size := m.Histograms[iNdEx].Size() + i -= size + if _, err := m.Histograms[iNdEx].MarshalTo(dAtA[i:]); err != nil { return 0, err } - i -= size i = encodeVarintCortex(dAtA, i, uint64(size)) } i-- @@ -4097,11 +4071,6 @@ func (this *TimeSeriesV2) String() string { repeatedStringForSamples += strings.Replace(strings.Replace(f.String(), "Sample", "Sample", 1), `&`, ``, 1) + "," } repeatedStringForSamples += "}" - repeatedStringForHistograms := "[]Histogram{" - for _, f := range this.Histograms { - repeatedStringForHistograms += strings.Replace(strings.Replace(f.String(), "Histogram", "Histogram", 1), `&`, ``, 1) + "," - } - repeatedStringForHistograms += "}" repeatedStringForExemplars := "[]ExemplarV2{" for _, f := range this.Exemplars { repeatedStringForExemplars += strings.Replace(strings.Replace(f.String(), "ExemplarV2", "ExemplarV2", 1), `&`, ``, 1) + "," @@ -4110,7 +4079,7 @@ func (this *TimeSeriesV2) String() string { s := strings.Join([]string{`&TimeSeriesV2{`, `LabelsRefs:` + fmt.Sprintf("%v", this.LabelsRefs) + `,`, `Samples:` + repeatedStringForSamples + `,`, - `Histograms:` + repeatedStringForHistograms + `,`, + `Histograms:` + fmt.Sprintf("%v", this.Histograms) + `,`, `Exemplars:` + repeatedStringForExemplars + `,`, `Metadata:` + strings.Replace(strings.Replace(this.Metadata.String(), "MetadataV2", "MetadataV2", 1), `&`, ``, 1) + `,`, `CreatedTimestamp:` + fmt.Sprintf("%v", this.CreatedTimestamp) + `,`, @@ -4182,16 +4151,11 @@ func (this *TimeSeries) String() string { repeatedStringForExemplars += strings.Replace(strings.Replace(f.String(), "Exemplar", "Exemplar", 1), `&`, ``, 1) + "," } repeatedStringForExemplars += "}" - repeatedStringForHistograms := "[]Histogram{" - for _, f := range this.Histograms { - repeatedStringForHistograms += strings.Replace(strings.Replace(f.String(), "Histogram", "Histogram", 1), `&`, ``, 1) + "," - } - repeatedStringForHistograms += "}" s := strings.Join([]string{`&TimeSeries{`, `Labels:` + fmt.Sprintf("%v", this.Labels) + `,`, `Samples:` + repeatedStringForSamples + `,`, `Exemplars:` + repeatedStringForExemplars + `,`, - `Histograms:` + repeatedStringForHistograms + `,`, + `Histograms:` + fmt.Sprintf("%v", this.Histograms) + `,`, `}`, }, "") return s @@ -4972,7 +4936,7 @@ func (m *TimeSeriesV2) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Histograms = append(m.Histograms, Histogram{}) + m.Histograms = append(m.Histograms, WrappedHistogram{}) if err := m.Histograms[len(m.Histograms)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -5831,7 +5795,7 @@ func (m *TimeSeries) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Histograms = append(m.Histograms, Histogram{}) + m.Histograms = append(m.Histograms, WrappedHistogram{}) if err := m.Histograms[len(m.Histograms)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/pkg/cortexpb/cortex.proto b/pkg/cortexpb/cortex.proto index a0eecd9fb31..f583804149a 100644 --- a/pkg/cortexpb/cortex.proto +++ b/pkg/cortexpb/cortex.proto @@ -47,7 +47,7 @@ message TimeSeriesV2 { // // Samples and histograms are sorted by timestamp (older first). repeated Sample samples = 2 [(gogoproto.nullable) = false]; - repeated Histogram histograms = 3 [(gogoproto.nullable) = false]; + repeated Histogram histograms = 3 [(gogoproto.nullable) = false, (gogoproto.customtype) = "WrappedHistogram"]; // exemplars represents an optional set of exemplars attached to this series' samples. repeated ExemplarV2 exemplars = 4 [(gogoproto.nullable) = false]; @@ -140,7 +140,7 @@ message TimeSeries { // Sorted by time, oldest sample first. repeated Sample samples = 2 [(gogoproto.nullable) = false]; repeated Exemplar exemplars = 3 [(gogoproto.nullable) = false]; - repeated Histogram histograms = 4 [(gogoproto.nullable) = false]; + repeated Histogram histograms = 4 [(gogoproto.nullable) = false, (gogoproto.customtype) = "WrappedHistogram"]; } message LabelPair { diff --git a/pkg/cortexpb/histograms.go b/pkg/cortexpb/histograms.go index c4ea2a63715..65f494dddde 100644 --- a/pkg/cortexpb/histograms.go +++ b/pkg/cortexpb/histograms.go @@ -14,6 +14,8 @@ package cortexpb import ( + "fmt" + "github.com/prometheus/prometheus/model/histogram" "github.com/prometheus/prometheus/prompb" ) @@ -176,3 +178,51 @@ func (h Histogram) BucketCount() int { } return count } + +// MaxWrappedHistogramSizeBytes is the maximum allowed size of a single native histogram in raw protobuf +// bytes before unmarshalling. A value of 0 disables the limit. +var maxWrappedHistogramSizeBytes = 16 * 1024 + +// WrappedHistogram is a Histogram with a size check on Unmarshal. +// Used only on the ingestion path, not on the query path. +type WrappedHistogram struct { + Histogram +} + +// Unmarshal implements proto.Message. +func (p *WrappedHistogram) Unmarshal(dAtA []byte) error { + if maxWrappedHistogramSizeBytes > 0 && len(dAtA) > maxWrappedHistogramSizeBytes { + return fmt.Errorf("native histogram size %d bytes exceeds limit %d bytes", len(dAtA), maxWrappedHistogramSizeBytes) + } + return p.Histogram.Unmarshal(dAtA) +} + +// Marshal implements proto.Marshaler. +func (p *WrappedHistogram) Marshal() (dAtA []byte, err error) { + return p.Histogram.Marshal() +} + +// MarshalTo implements proto.Marshaler. +func (p *WrappedHistogram) MarshalTo(dAtA []byte) (int, error) { + return p.Histogram.MarshalTo(dAtA) +} + +// MarshalToSizedBuffer implements proto.Marshaler. +func (p *WrappedHistogram) MarshalToSizedBuffer(dAtA []byte) (int, error) { + return p.Histogram.MarshalToSizedBuffer(dAtA) +} + +// Size implements proto.Sizer. +func (p *WrappedHistogram) Size() int { + return p.Histogram.Size() +} + +// Equal implements proto.Equal. +func (p WrappedHistogram) Equal(other WrappedHistogram) bool { + return p.Histogram.Equal(&other.Histogram) +} + +// WrapHistogram wraps a Histogram into a WrappedHistogram. +func WrapHistogram(h Histogram) WrappedHistogram { + return WrappedHistogram{Histogram: h} +} diff --git a/pkg/cortexpb/timeseries.go b/pkg/cortexpb/timeseries.go index 194c61b5287..b8de17b4181 100644 --- a/pkg/cortexpb/timeseries.go +++ b/pkg/cortexpb/timeseries.go @@ -35,7 +35,7 @@ var ( Labels: make([]LabelAdapter, 0, expectedLabels), Samples: make([]Sample, 0, expectedSamplesPerSeries), Exemplars: make([]Exemplar, 0, expectedExemplarsPerSeries), - Histograms: make([]Histogram, 0, expectedHistogramsPerSeries), + Histograms: make([]WrappedHistogram, 0, expectedHistogramsPerSeries), } }, } @@ -59,6 +59,7 @@ func (PreallocConfig) RegisterFlags(f *flag.FlagSet) { f.IntVar(&expectedTimeseries, "ingester-client.expected-timeseries", expectedTimeseries, "Expected number of timeseries per request, used for preallocations.") f.IntVar(&expectedLabels, "ingester-client.expected-labels", expectedLabels, "Expected number of labels per timeseries, used for preallocations.") f.IntVar(&expectedSamplesPerSeries, "ingester-client.expected-samples-per-series", expectedSamplesPerSeries, "Expected number of samples per timeseries, used for preallocations.") + f.IntVar(&maxWrappedHistogramSizeBytes, "validation.max-native-histogram-size-bytes", maxWrappedHistogramSizeBytes, "Maximum size in bytes of a single native histogram in raw protobuf before unmarshalling. 0 to disable.") } // PreallocWriteRequest is a WriteRequest which preallocs slices on Unmarshal. diff --git a/pkg/cortexpb/timeseries_test.go b/pkg/cortexpb/timeseries_test.go index 6194b7e9943..26b5e805ba8 100644 --- a/pkg/cortexpb/timeseries_test.go +++ b/pkg/cortexpb/timeseries_test.go @@ -130,3 +130,63 @@ func BenchmarkMarshallWriteRequest(b *testing.B) { }) } } + +func TestWrappedHistogram_Unmarshal_SizeLimit(t *testing.T) { + t.Run("rejects oversized histogram", func(t *testing.T) { + original := maxWrappedHistogramSizeBytes + maxWrappedHistogramSizeBytes = 1024 // 1KB for test + defer func() { maxWrappedHistogramSizeBytes = original }() + + // Create a histogram that exceeds 1KB when marshalled + h := Histogram{ + Schema: 3, + NegativeDeltas: make([]int64, 600), + PositiveDeltas: make([]int64, 600), + } + data, err := h.Marshal() + require.NoError(t, err) + require.Greater(t, len(data), 1024) // confirm it's over limit + + p := &WrappedHistogram{} + err = p.Unmarshal(data) + require.Error(t, err) + assert.Contains(t, err.Error(), "exceeds limit") + }) + + t.Run("allows normal histogram", func(t *testing.T) { + original := maxWrappedHistogramSizeBytes + maxWrappedHistogramSizeBytes = 16 * 1024 + defer func() { maxWrappedHistogramSizeBytes = original }() + + h := Histogram{ + Schema: 3, + NegativeDeltas: make([]int64, 50), + PositiveDeltas: make([]int64, 50), + } + data, err := h.Marshal() + require.NoError(t, err) + + p := &WrappedHistogram{} + err = p.Unmarshal(data) + require.NoError(t, err) + assert.Equal(t, int32(3), p.Schema) + assert.Len(t, p.NegativeDeltas, 50) + }) + + t.Run("allows when limit disabled", func(t *testing.T) { + original := maxWrappedHistogramSizeBytes + maxWrappedHistogramSizeBytes = 0 // disabled + defer func() { maxWrappedHistogramSizeBytes = original }() + + h := Histogram{ + NegativeDeltas: make([]int64, 5000), + PositiveDeltas: make([]int64, 5000), + } + data, err := h.Marshal() + require.NoError(t, err) + + p := &WrappedHistogram{} + err = p.Unmarshal(data) + require.NoError(t, err) + }) +} diff --git a/pkg/cortexpb/timeseriesv2.go b/pkg/cortexpb/timeseriesv2.go index 2a903bcb8ee..1d0063f6a44 100644 --- a/pkg/cortexpb/timeseriesv2.go +++ b/pkg/cortexpb/timeseriesv2.go @@ -27,7 +27,7 @@ var ( return &TimeSeriesV2{ LabelsRefs: make([]uint32, 0, expectedLabels), Samples: make([]Sample, 0, expectedSamplesPerSeries), - Histograms: make([]Histogram, 0, expectedHistogramsPerSeries), + Histograms: make([]WrappedHistogram, 0, expectedHistogramsPerSeries), Exemplars: make([]ExemplarV2, 0, expectedExemplarsPerSeries), Metadata: MetadataV2{}, } diff --git a/pkg/cortexpb/timeseriesv2_test.go b/pkg/cortexpb/timeseriesv2_test.go index 89fd525036e..fe5eff334e7 100644 --- a/pkg/cortexpb/timeseriesv2_test.go +++ b/pkg/cortexpb/timeseriesv2_test.go @@ -44,7 +44,7 @@ func TestTimeseriesV2FromPool(t *testing.T) { ts.LabelsRefs = []uint32{1, 2} ts.Samples = []Sample{{Value: 1, TimestampMs: 2}} ts.Exemplars = []ExemplarV2{{LabelsRefs: []uint32{1, 2}, Value: 1, Timestamp: 2}} - ts.Histograms = []Histogram{{}} + ts.Histograms = []WrappedHistogram{{}} ts.CreatedTimestamp = 12345 ts.Metadata = MetadataV2{Type: 1, HelpRef: 2, UnitRef: 3} ReuseTimeseriesV2(ts) diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index ab21c6182d9..e60addbebf1 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -687,19 +687,19 @@ func (d *Distributor) validateSeries(ts cortexpb.PreallocTimeseries, userID stri } } - var histograms []cortexpb.Histogram + var histograms []cortexpb.WrappedHistogram if len(ts.Histograms) > 0 { // Only alloc when data present - histograms = make([]cortexpb.Histogram, 0, len(ts.Histograms)) + histograms = make([]cortexpb.WrappedHistogram, 0, len(ts.Histograms)) for i, h := range ts.Histograms { if err := validation.ValidateSampleTimestamp(d.validateMetrics, limits, userID, ts.Labels, h.TimestampMs); err != nil { return emptyPreallocSeries, err } - convertedHistogram, err := validation.ValidateNativeHistogram(d.validateMetrics, limits, userID, ts.Labels, h) + convertedHistogram, err := validation.ValidateNativeHistogram(d.validateMetrics, limits, userID, ts.Labels, h.Histogram) if err != nil { return emptyPreallocSeries, err } - ts.Histograms[i] = convertedHistogram + ts.Histograms[i].Histogram = convertedHistogram } histograms = append(histograms, ts.Histograms...) } @@ -1026,7 +1026,7 @@ type samplesLabelSetEntry struct { } // countNHCB returns the number of native histograms with custom buckets schema in the given slice. -func countNHCB(histograms []cortexpb.Histogram) int { +func countNHCB(histograms []cortexpb.WrappedHistogram) int { n := 0 for _, h := range histograms { if histogram.IsCustomBucketsSchema(h.GetSchema()) { diff --git a/pkg/distributor/distributor_test.go b/pkg/distributor/distributor_test.go index 855e4e22f33..b8b7c79300b 100644 --- a/pkg/distributor/distributor_test.go +++ b/pkg/distributor/distributor_test.go @@ -3220,12 +3220,12 @@ func mustNewMatcher(t labels.MatchType, n, v string) *labels.Matcher { func mockWriteRequest(lbls []labels.Labels, value int64, timestampMs int64, histogram bool) *cortexpb.WriteRequest { var ( samples []cortexpb.Sample - histograms []cortexpb.Histogram + histograms []cortexpb.WrappedHistogram ) if histogram { - histograms = make([]cortexpb.Histogram, len(lbls)) + histograms = make([]cortexpb.WrappedHistogram, len(lbls)) for i := range lbls { - histograms[i] = cortexpb.HistogramToHistogramProto(timestampMs, tsdbutil.GenerateTestHistogram(value)) + histograms[i] = cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(timestampMs, tsdbutil.GenerateTestHistogram(value))) } } else { samples = make([]cortexpb.Sample, len(lbls)) @@ -3496,7 +3496,7 @@ func makeWriteRequestTimeseries(labels []cortexpb.LabelAdapter, ts, value int64, }, } if histogram { - t.Histograms = append(t.Histograms, cortexpb.HistogramToHistogramProto(ts, tsdbutil.GenerateTestHistogram(value))) + t.Histograms = append(t.Histograms, cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(ts, tsdbutil.GenerateTestHistogram(value)))) } else { t.Samples = append(t.Samples, cortexpb.Sample{ TimestampMs: ts, @@ -3510,7 +3510,7 @@ func makeWriteRequestTimeseriesNHCB(labels []cortexpb.LabelAdapter, ts, value in return cortexpb.PreallocTimeseries{ TimeSeries: &cortexpb.TimeSeries{ Labels: labels, - Histograms: []cortexpb.Histogram{cortexpb.HistogramToHistogramProto(ts, tsdbutil.GenerateTestCustomBucketsHistogram(value))}, + Histograms: []cortexpb.WrappedHistogram{cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(ts, tsdbutil.GenerateTestCustomBucketsHistogram(value)))}, }, } } @@ -3530,8 +3530,8 @@ func makeWriteRequestHA(samples int, replica, cluster string, histogram bool) *c }, } if histogram { - ts.Histograms = []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(int64(i), tsdbutil.GenerateTestHistogram(int64(i))), + ts.Histograms = []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(int64(i), tsdbutil.GenerateTestHistogram(int64(i)))), } } else { ts.Samples = []cortexpb.Sample{ @@ -3627,8 +3627,8 @@ func makeWriteRequestHAMixedSamples(samples int, histogram bool) *cortexpb.Write } } if histogram { - ts.Histograms = []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(int64(samples), tsdbutil.GenerateTestHistogram(int64(samples))), + ts.Histograms = []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(int64(samples), tsdbutil.GenerateTestHistogram(int64(samples)))), } } else { var s = make([]cortexpb.Sample, 0) @@ -4098,7 +4098,7 @@ func TestDistributorValidation(t *testing.T) { metadata []*cortexpb.MetricMetadata labels []labels.Labels samples []cortexpb.Sample - histograms []cortexpb.Histogram + histograms []cortexpb.WrappedHistogram err error }{ // Test validation passes. @@ -4111,8 +4111,8 @@ func TestDistributorValidation(t *testing.T) { TimestampMs: int64(now), Value: 1, }}, - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(int64(now), testHistogram), + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(int64(now), testHistogram)), }, }, // Test validation fails for very old samples. @@ -4200,8 +4200,8 @@ func TestDistributorValidation(t *testing.T) { labels: []labels.Labels{ labels.FromStrings(labels.MetricName, "testmetric", "foo", "bar", "foo2", "bar2"), }, - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(int64(now), testHistogram), + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(int64(now), testHistogram)), }, err: httpgrpc.Errorf(http.StatusBadRequest, `series has too many labels (actual: 3, limit: 2) series: 'testmetric{foo2="bar2", foo="bar"}'`), }, @@ -4210,8 +4210,8 @@ func TestDistributorValidation(t *testing.T) { labels: []labels.Labels{ labels.FromStrings(labels.MetricName, "testmetric", "foo", "bar"), }, - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(int64(past), testHistogram), + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(int64(past), testHistogram)), }, err: httpgrpc.Errorf(http.StatusBadRequest, `timestamp too old: %d metric: "testmetric"`, past), }, @@ -4220,8 +4220,8 @@ func TestDistributorValidation(t *testing.T) { labels: []labels.Labels{ labels.FromStrings(labels.MetricName, "testmetric", "foo", "bar"), }, - histograms: []cortexpb.Histogram{ - cortexpb.FloatHistogramToHistogramProto(int64(future), testFloatHistogram), + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.FloatHistogramToHistogramProto(int64(future), testFloatHistogram)), }, err: httpgrpc.Errorf(http.StatusBadRequest, `timestamp too new: %d metric: "testmetric"`, future), }, diff --git a/pkg/ingester/client/compat.go b/pkg/ingester/client/compat.go index d6f982a1f35..20f745c52eb 100644 --- a/pkg/ingester/client/compat.go +++ b/pkg/ingester/client/compat.go @@ -118,7 +118,7 @@ func SeriesSetToQueryResponse(s storage.SeriesSet) (*QueryResponse, error) { for s.Next() { series := s.At() samples := []cortexpb.Sample{} - histograms := []cortexpb.Histogram{} + histograms := []cortexpb.WrappedHistogram{} it = series.Iterator(it) for valType := it.Next(); valType != chunkenc.ValNone; valType = it.Next() { switch valType { @@ -130,10 +130,10 @@ func SeriesSetToQueryResponse(s storage.SeriesSet) (*QueryResponse, error) { }) case chunkenc.ValHistogram: t, v := it.AtHistogram(nil) - histograms = append(histograms, cortexpb.HistogramToHistogramProto(t, v)) + histograms = append(histograms, cortexpb.WrappedHistogram{Histogram: cortexpb.HistogramToHistogramProto(t, v)}) case chunkenc.ValFloatHistogram: t, v := it.AtFloatHistogram(nil) - histograms = append(histograms, cortexpb.FloatHistogramToHistogramProto(t, v)) + histograms = append(histograms, cortexpb.WrappedHistogram{Histogram: cortexpb.FloatHistogramToHistogramProto(t, v)}) default: panic("unhandled default case") } diff --git a/pkg/ingester/ingester.go b/pkg/ingester/ingester.go index c6b8430d36b..a32401e0e97 100644 --- a/pkg/ingester/ingester.go +++ b/pkg/ingester/ingester.go @@ -1535,9 +1535,9 @@ func (i *Ingester) Push(ctx context.Context, req *cortexpb.WriteRequest) (*corte ) if hp.GetCountFloat() > 0 { - fh = cortexpb.FloatHistogramProtoToFloatHistogram(hp) + fh = cortexpb.FloatHistogramProtoToFloatHistogram(hp.Histogram) } else { - h = cortexpb.HistogramProtoToHistogram(hp) + h = cortexpb.HistogramProtoToHistogram(hp.Histogram) } if hp.StartTimestampMs != 0 && hp.TimestampMs != 0 { diff --git a/pkg/ingester/ingester_test.go b/pkg/ingester/ingester_test.go index 5c2b66270c7..315f36c3d73 100644 --- a/pkg/ingester/ingester_test.go +++ b/pkg/ingester/ingester_test.go @@ -881,9 +881,9 @@ func TestIngesterUserLimitExceededForNativeHistogram(t *testing.T) { // Series labels1 := labels.FromStrings(labels.MetricName, "testmetric", "foo", "bar") labels3 := labels.FromStrings(labels.MetricName, "testmetric", "foo", "biz") - sampleNativeHistogram1 := cortexpb.HistogramToHistogramProto(0, tsdbutil.GenerateTestHistogram(1)) - sampleNativeHistogram2 := cortexpb.HistogramToHistogramProto(1, tsdbutil.GenerateTestHistogram(2)) - sampleNativeHistogram3 := cortexpb.HistogramToHistogramProto(0, tsdbutil.GenerateTestHistogram(3)) + sampleNativeHistogram1 := cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(0, tsdbutil.GenerateTestHistogram(1))) + sampleNativeHistogram2 := cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(1, tsdbutil.GenerateTestHistogram(2))) + sampleNativeHistogram3 := cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(0, tsdbutil.GenerateTestHistogram(3))) // Metadata metadata1 := &cortexpb.MetricMetadata{MetricFamilyName: "testmetric", Help: "a help for testmetric", Type: cortexpb.COUNTER} @@ -916,12 +916,12 @@ func TestIngesterUserLimitExceededForNativeHistogram(t *testing.T) { // Append only one series and one metadata first, expect no error. ctx := user.InjectOrgID(context.Background(), userID) - _, err := ing.Push(ctx, cortexpb.ToWriteRequest([]labels.Labels{labels1}, nil, []*cortexpb.MetricMetadata{metadata1}, []cortexpb.Histogram{sampleNativeHistogram1}, cortexpb.API)) + _, err := ing.Push(ctx, cortexpb.ToWriteRequest([]labels.Labels{labels1}, nil, []*cortexpb.MetricMetadata{metadata1}, []cortexpb.WrappedHistogram{sampleNativeHistogram1}, cortexpb.API)) require.NoError(t, err) testLimits := func(reg prometheus.Gatherer) { // Append to two series, expect series-exceeded error. - _, err = ing.Push(ctx, cortexpb.ToWriteRequest([]labels.Labels{labels1, labels3}, nil, nil, []cortexpb.Histogram{sampleNativeHistogram2, sampleNativeHistogram3}, cortexpb.API)) + _, err = ing.Push(ctx, cortexpb.ToWriteRequest([]labels.Labels{labels1, labels3}, nil, nil, []cortexpb.WrappedHistogram{sampleNativeHistogram2, sampleNativeHistogram3}, cortexpb.API)) httpResp, ok := httpgrpc.HTTPResponseFromError(err) require.True(t, ok, "returned error is not an httpgrpc response") assert.Equal(t, http.StatusBadRequest, int(httpResp.Code)) @@ -1119,8 +1119,8 @@ func TestIngester_Push(t *testing.T) { } userID := "test" - testHistogram := cortexpb.HistogramToHistogramProto(10, tsdbutil.GenerateTestHistogram(1)) - testFloatHistogram := cortexpb.FloatHistogramToHistogramProto(11, tsdbutil.GenerateTestFloatHistogram(1)) + testHistogram := cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, tsdbutil.GenerateTestHistogram(1))) + testFloatHistogram := cortexpb.WrapHistogram(cortexpb.FloatHistogramToHistogramProto(11, tsdbutil.GenerateTestFloatHistogram(1))) tests := map[string]struct { reqs []*cortexpb.WriteRequest expectedErr error @@ -1142,10 +1142,10 @@ func TestIngester_Push(t *testing.T) { []*cortexpb.MetricMetadata{ {MetricFamilyName: "metric_name_2", Help: "a help for metric_name_2", Unit: "", Type: cortexpb.GAUGE}, }, - []cortexpb.Histogram{ - { + []cortexpb.WrappedHistogram{ + {Histogram: cortexpb.Histogram{ TimestampMs: 10, - }, + }}, }, cortexpb.API), }, @@ -1426,8 +1426,8 @@ func TestIngester_Push(t *testing.T) { []labels.Labels{metricLabels}, []cortexpb.Sample{{Value: 1, TimestampMs: 9}}, nil, - []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(9, tsdbutil.GenerateTestHistogram(1)), + []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(9, tsdbutil.GenerateTestHistogram(1))), }, cortexpb.API), }, @@ -1498,8 +1498,8 @@ func TestIngester_Push(t *testing.T) { []labels.Labels{metricLabels}, []cortexpb.Sample{{Value: 1, TimestampMs: 1575043969 - (86400 * 1000)}}, nil, - []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(1575043969-(86400*1000), tsdbutil.GenerateTestHistogram(1)), + []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(1575043969-(86400*1000), tsdbutil.GenerateTestHistogram(1))), }, cortexpb.API), }, @@ -1652,19 +1652,19 @@ func TestIngester_Push(t *testing.T) { []labels.Labels{metricLabels}, nil, nil, - []cortexpb.Histogram{cortexpb.HistogramToHistogramProto(1575043969, tsdbutil.GenerateTestHistogram(1))}, + []cortexpb.WrappedHistogram{cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(1575043969, tsdbutil.GenerateTestHistogram(1)))}, cortexpb.API), cortexpb.ToWriteRequest( []labels.Labels{metricLabels}, nil, nil, - []cortexpb.Histogram{cortexpb.HistogramToHistogramProto(1575043969-(600*1000), tsdbutil.GenerateTestHistogram(1))}, + []cortexpb.WrappedHistogram{cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(1575043969-(600*1000), tsdbutil.GenerateTestHistogram(1)))}, cortexpb.API), }, oooTimeWindow: 5 * time.Minute, expectedErr: httpgrpc.Errorf(http.StatusBadRequest, "%s", wrapWithUser(wrappedTSDBIngestErr(storage.ErrTooOldSample, model.Time(1575043969-(600*1000)), cortexpb.FromLabelsToLabelAdapters(metricLabels)), userID).Error()), expectedIngested: []cortexpb.TimeSeries{ - {Labels: metricLabelAdapters, Histograms: []cortexpb.Histogram{cortexpb.HistogramToHistogramProto(1575043969, tsdbutil.GenerateTestHistogram(1))}}, + {Labels: metricLabelAdapters, Histograms: []cortexpb.WrappedHistogram{cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(1575043969, tsdbutil.GenerateTestHistogram(1)))}}, }, additionalMetrics: []string{ "cortex_ingester_tsdb_head_samples_appended_total", @@ -1718,18 +1718,18 @@ func TestIngester_Push(t *testing.T) { []labels.Labels{metricLabels}, nil, nil, - []cortexpb.Histogram{cortexpb.HistogramToHistogramProto(1575043969, tsdbutil.GenerateTestHistogram(1))}, + []cortexpb.WrappedHistogram{cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(1575043969, tsdbutil.GenerateTestHistogram(1)))}, cortexpb.API), cortexpb.ToWriteRequest( []labels.Labels{metricLabels}, nil, nil, - []cortexpb.Histogram{cortexpb.HistogramToHistogramProto(1575043969-(10), tsdbutil.GenerateTestHistogram(1))}, + []cortexpb.WrappedHistogram{cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(1575043969-(10), tsdbutil.GenerateTestHistogram(1)))}, cortexpb.API), }, oooTimeWindow: 5 * time.Minute, expectedIngested: []cortexpb.TimeSeries{ - {Labels: metricLabelAdapters, Histograms: []cortexpb.Histogram{cortexpb.HistogramToHistogramProto(1575043969-(10), tsdbutil.GenerateTestHistogram(1)), cortexpb.HistogramToHistogramProto(1575043969, tsdbutil.GenerateTestHistogram(1))}}, + {Labels: metricLabelAdapters, Histograms: []cortexpb.WrappedHistogram{cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(1575043969-(10), tsdbutil.GenerateTestHistogram(1))), cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(1575043969, tsdbutil.GenerateTestHistogram(1)))}}, }, additionalMetrics: []string{ "cortex_ingester_tsdb_head_samples_appended_total", @@ -1910,12 +1910,12 @@ func TestIngester_Push(t *testing.T) { []labels.Labels{metricLabels}, nil, nil, - []cortexpb.Histogram{testHistogram}, + []cortexpb.WrappedHistogram{testHistogram}, cortexpb.API), }, expectedErr: nil, expectedIngested: []cortexpb.TimeSeries{ - {Labels: metricLabelAdapters, Histograms: []cortexpb.Histogram{testHistogram}}, + {Labels: metricLabelAdapters, Histograms: []cortexpb.WrappedHistogram{testHistogram}}, }, additionalMetrics: []string{ "cortex_ingester_tsdb_head_samples_appended_total", @@ -1970,12 +1970,12 @@ func TestIngester_Push(t *testing.T) { []labels.Labels{metricLabels}, nil, nil, - []cortexpb.Histogram{testFloatHistogram}, + []cortexpb.WrappedHistogram{testFloatHistogram}, cortexpb.API), }, expectedErr: nil, expectedIngested: []cortexpb.TimeSeries{ - {Labels: metricLabelAdapters, Histograms: []cortexpb.Histogram{testFloatHistogram}}, + {Labels: metricLabelAdapters, Histograms: []cortexpb.WrappedHistogram{testFloatHistogram}}, }, additionalMetrics: []string{ "cortex_ingester_tsdb_head_samples_appended_total", @@ -2156,13 +2156,13 @@ func TestIngester_Push_StartTimestamp(t *testing.T) { name: "histogram start timestamp appends zero histogram", metricName: "test_start_timestamp_histogram", req: func() *cortexpb.WriteRequest { - h := cortexpb.HistogramToHistogramProto(200, tsdbutil.GenerateTestHistogram(1)) + h := cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(200, tsdbutil.GenerateTestHistogram(1))) h.StartTimestampMs = 100 return cortexpb.ToWriteRequest( []labels.Labels{labels.FromStrings(labels.MetricName, "test_start_timestamp_histogram")}, nil, nil, - []cortexpb.Histogram{h}, + []cortexpb.WrappedHistogram{h}, cortexpb.API, ) }(), @@ -2238,13 +2238,13 @@ func TestIngester_Push_StartTimestampAppendFailureMetrics(t *testing.T) { { name: "histogram start timestamp append failure increments histogram metric", req: func() *cortexpb.WriteRequest { - h := cortexpb.HistogramToHistogramProto(200, tsdbutil.GenerateTestHistogram(1)) + h := cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(200, tsdbutil.GenerateTestHistogram(1))) h.StartTimestampMs = math.MinInt64 return cortexpb.ToWriteRequest( []labels.Labels{labels.FromStrings(labels.MetricName, "test_start_timestamp_failure_histogram")}, nil, nil, - []cortexpb.Histogram{h}, + []cortexpb.WrappedHistogram{h}, cortexpb.API, ) }(), @@ -2287,146 +2287,146 @@ func TestIngester_PushNativeHistogramErrors(t *testing.T) { metricLabels := cortexpb.FromLabelAdaptersToLabels(metricLabelAdapters) for _, tc := range []struct { name string - histograms []cortexpb.Histogram + histograms []cortexpb.WrappedHistogram expectedErr error }{ { name: "rejects histogram with NaN observations that has its Count (2) lower than the actual total of buckets (2 + 1)", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ ZeroCount: 2, Count: 2, Sum: math.NaN(), PositiveSpans: []histogram.Span{{Offset: 0, Length: 1}}, PositiveBuckets: []int64{1}, - }), + })), }, expectedErr: fmt.Errorf("3 observations found in buckets, but the Count field is 2: %w", histogram.ErrHistogramCountNotBigEnough), }, { name: "rejects histogram without NaN observations that has its Count (4) higher than the actual total of buckets (2 + 1)", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ ZeroCount: 2, Count: 4, Sum: 333, PositiveSpans: []histogram.Span{{Offset: 0, Length: 1}}, PositiveBuckets: []int64{1}, - }), + })), }, expectedErr: fmt.Errorf("3 observations found in buckets, but the Count field is 4: %w", histogram.ErrHistogramCountMismatch), }, { name: "rejects histogram that has too few negative buckets", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ NegativeSpans: []histogram.Span{{Offset: 0, Length: 1}}, NegativeBuckets: []int64{}, - }), + })), }, expectedErr: fmt.Errorf("negative side: spans need 1 buckets, have 0 buckets: %w", histogram.ErrHistogramSpansBucketsMismatch), }, { name: "rejects histogram that has too few positive buckets", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ PositiveSpans: []histogram.Span{{Offset: 0, Length: 1}}, PositiveBuckets: []int64{}, - }), + })), }, expectedErr: fmt.Errorf("positive side: spans need 1 buckets, have 0 buckets: %w", histogram.ErrHistogramSpansBucketsMismatch), }, { name: "rejects histogram that has too many negative buckets", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ NegativeSpans: []histogram.Span{{Offset: 0, Length: 1}}, NegativeBuckets: []int64{1, 2}, - }), + })), }, expectedErr: fmt.Errorf("negative side: spans need 1 buckets, have 2 buckets: %w", histogram.ErrHistogramSpansBucketsMismatch), }, { name: "rejects histogram that has too many positive buckets", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ PositiveSpans: []histogram.Span{{Offset: 0, Length: 1}}, PositiveBuckets: []int64{1, 2}, - }), + })), }, expectedErr: fmt.Errorf("positive side: spans need 1 buckets, have 2 buckets: %w", histogram.ErrHistogramSpansBucketsMismatch), }, { name: "rejects a histogram that has a negative span with a negative offset", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ NegativeSpans: []histogram.Span{{Offset: -1, Length: 1}, {Offset: -1, Length: 1}}, NegativeBuckets: []int64{1, 2}, - }), + })), }, expectedErr: fmt.Errorf("negative side: span number 2 with offset -1: %w", histogram.ErrHistogramSpanNegativeOffset), }, { name: "rejects a histogram that has a positive span with a negative offset", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ PositiveSpans: []histogram.Span{{Offset: -1, Length: 1}, {Offset: -1, Length: 1}}, PositiveBuckets: []int64{1, 2}, - }), + })), }, expectedErr: fmt.Errorf("positive side: span number 2 with offset -1: %w", histogram.ErrHistogramSpanNegativeOffset), }, { name: "rejects a histogram that has a negative span with a negative count", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ NegativeSpans: []histogram.Span{{Offset: -1, Length: 1}}, NegativeBuckets: []int64{-1}, - }), + })), }, expectedErr: fmt.Errorf("negative side: bucket number 1 has observation count of -1: %w", histogram.ErrHistogramNegativeBucketCount), }, { name: "rejects a histogram that has a positive span with a negative count", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ PositiveSpans: []histogram.Span{{Offset: -1, Length: 1}}, PositiveBuckets: []int64{-1}, - }), + })), }, expectedErr: fmt.Errorf("positive side: bucket number 1 has observation count of -1: %w", histogram.ErrHistogramNegativeBucketCount), }, { name: "rejects a histogram that has a lower count than count in buckets", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Count: 0, NegativeSpans: []histogram.Span{{Offset: -1, Length: 1}}, PositiveSpans: []histogram.Span{{Offset: -1, Length: 1}}, NegativeBuckets: []int64{1}, PositiveBuckets: []int64{1}, - }), + })), }, expectedErr: fmt.Errorf("2 observations found in buckets, but the Count field is 0: %w", histogram.ErrHistogramCountMismatch), }, { name: "rejects a histogram that doesn't count the zero bucket in its count", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Count: 2, ZeroCount: 1, NegativeSpans: []histogram.Span{{Offset: -1, Length: 1}}, PositiveSpans: []histogram.Span{{Offset: -1, Length: 1}}, NegativeBuckets: []int64{1}, PositiveBuckets: []int64{1}, - }), + })), }, expectedErr: fmt.Errorf("3 observations found in buckets, but the Count field is 2: %w", histogram.ErrHistogramCountMismatch), }, { name: "rejects an exponential histogram with custom buckets schema", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Count: 12, ZeroCount: 2, ZeroThreshold: 0.001, @@ -2442,14 +2442,14 @@ func TestIngester_PushNativeHistogramErrors(t *testing.T) { {Offset: 1, Length: 2}, }, NegativeBuckets: []int64{1, 1, -1, 0}, - }), + })), }, expectedErr: fmt.Errorf("custom buckets: only 0 custom bounds defined which is insufficient to cover total span length of 5: %w", histogram.ErrHistogramCustomBucketsMismatch), }, { name: "rejects a custom buckets histogram with exponential schema", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Count: 5, Sum: 19.4, Schema: 0, @@ -2459,14 +2459,14 @@ func TestIngester_PushNativeHistogramErrors(t *testing.T) { }, PositiveBuckets: []int64{1, 1, -1, 0}, CustomValues: []float64{1, 2, 3, 4}, - }), + })), }, expectedErr: histogram.ErrHistogramExpSchemaCustomBounds, }, { name: "rejects a custom buckets histogram with zero/negative buckets", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Count: 12, ZeroCount: 2, ZeroThreshold: 0.001, @@ -2483,14 +2483,14 @@ func TestIngester_PushNativeHistogramErrors(t *testing.T) { }, NegativeBuckets: []int64{1, 1, -1, 0}, CustomValues: []float64{1, 2, 3, 4}, - }), + })), }, expectedErr: histogram.ErrHistogramCustomBucketsZeroCount, }, { name: "rejects a custom buckets histogram with negative offset in first span", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Count: 5, Sum: 19.4, Schema: histogram.CustomBucketsSchema, @@ -2500,14 +2500,14 @@ func TestIngester_PushNativeHistogramErrors(t *testing.T) { }, PositiveBuckets: []int64{1, 1, -1, 0}, CustomValues: []float64{1, 2, 3, 4}, - }), + })), }, expectedErr: fmt.Errorf("custom buckets: span number 1 with offset -1: %w", histogram.ErrHistogramSpanNegativeOffset), }, { name: "rejects a custom buckets histogram with negative offset in subsequent spans", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Count: 5, Sum: 19.4, Schema: histogram.CustomBucketsSchema, @@ -2517,14 +2517,14 @@ func TestIngester_PushNativeHistogramErrors(t *testing.T) { }, PositiveBuckets: []int64{1, 1, -1, 0}, CustomValues: []float64{1, 2, 3, 4}, - }), + })), }, expectedErr: fmt.Errorf("custom buckets: span number 2 with offset -1: %w", histogram.ErrHistogramSpanNegativeOffset), }, { name: "rejects a custom buckets histogram with non-matching bucket counts", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Count: 5, Sum: 19.4, Schema: histogram.CustomBucketsSchema, @@ -2534,14 +2534,14 @@ func TestIngester_PushNativeHistogramErrors(t *testing.T) { }, PositiveBuckets: []int64{1, 1, -1}, CustomValues: []float64{1, 2, 3, 4}, - }), + })), }, expectedErr: fmt.Errorf("custom buckets: spans need 4 buckets, have 3 buckets: %w", histogram.ErrHistogramSpansBucketsMismatch), }, { name: "rejects a custom buckets histogram with too few bounds", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Count: 5, Sum: 19.4, Schema: histogram.CustomBucketsSchema, @@ -2551,55 +2551,55 @@ func TestIngester_PushNativeHistogramErrors(t *testing.T) { }, PositiveBuckets: []int64{1, 1, -1, 0}, CustomValues: []float64{1, 2, 3}, - }), + })), }, expectedErr: fmt.Errorf("custom buckets: only 3 custom bounds defined which is insufficient to cover total span length of 5: %w", histogram.ErrHistogramCustomBucketsMismatch), }, { name: "reject custom buckets histogram with non-increasing bound", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Schema: histogram.CustomBucketsSchema, CustomValues: []float64{0, 0}, - }), + })), }, expectedErr: fmt.Errorf("custom buckets: previous bound is 0.000000 and current is 0.000000: %w", histogram.ErrHistogramCustomBucketsInvalid), }, { name: "reject custom buckets histogram with explicit +Inf bound", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Schema: histogram.CustomBucketsSchema, CustomValues: []float64{1, math.Inf(1)}, - }), + })), }, expectedErr: fmt.Errorf("custom buckets: last +Inf bound must not be explicitly defined: %w", histogram.ErrHistogramCustomBucketsInfinite), }, { name: "reject custom buckets histogram with NaN bound", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Schema: histogram.CustomBucketsSchema, CustomValues: []float64{1, math.NaN(), 3}, - }), + })), }, expectedErr: fmt.Errorf("custom buckets: %w", histogram.ErrHistogramCustomBucketsNaN), }, { name: "schema too high", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Schema: 10, - }), + })), }, expectedErr: histogram.InvalidSchemaError(10), }, { name: "schema too low", - histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ + histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &histogram.Histogram{ Schema: -10, - }), + })), }, expectedErr: histogram.InvalidSchemaError(-10), }, @@ -2833,64 +2833,6 @@ func TestIngester_Push_OutOfOrderLabels(t *testing.T) { require.NoError(t, err) } -// TestIngester_Push_OutOfOrderLabels_AppenderNotLeaked verifies that when Push -// returns early because of an out-of-order label set (and on any other early -// return after the appender is acquired) the appender is released via -// Rollback. Otherwise the TSDB head leaks series references, mmap'd chunks and -// pending state on every such request; observable via the -// cortex_ingester_tsdb_head_active_appenders gauge. -func TestIngester_Push_OutOfOrderLabels_AppenderNotLeaked(t *testing.T) { - cfg := defaultIngesterTestConfig(t) - r := prometheus.NewRegistry() - i, err := prepareIngesterWithBlocksStorage(t, cfg, r) - require.NoError(t, err) - require.NoError(t, services.StartAndAwaitRunning(context.Background(), i)) - defer services.StopAndAwaitTerminated(context.Background(), i) //nolint:errcheck - - // Wait until it's ACTIVE. - test.Poll(t, time.Second, ring.ACTIVE, func() any { - return i.lifecycler.GetState() - }) - - ctx := user.InjectOrgID(context.Background(), "test-user") - - // First push a valid sample to initialise the user TSDB head so that - // subsequent Push() calls take the headAppender path. - validLabels := labels.FromStrings(labels.MetricName, "test_metric", "a", "1", "b", "2") - validReq, _ := mockWriteRequest(t, validLabels, 1, 1) - _, err = i.Push(ctx, validReq) - require.NoError(t, err) - - // Sanity check: no appenders are currently active. - const activeAppendersMetric = "cortex_ingester_tsdb_head_active_appenders" - expectedZero := ` - # HELP cortex_ingester_tsdb_head_active_appenders Number of currently active TSDB appender transactions. - # TYPE cortex_ingester_tsdb_head_active_appenders gauge - cortex_ingester_tsdb_head_active_appenders 0 -` - require.NoError(t, testutil.GatherAndCompare(r, bytes.NewBufferString(expectedZero), activeAppendersMetric)) - - // Now push a series of requests with an out-of-order label set. Each - // such request creates an appender that, without the leak fix, is never - // released, leaving the active-appenders gauge growing. - outOfOrderLabels := []cortexpb.LabelAdapter{ - {Name: labels.MetricName, Value: "test_metric"}, - {Name: "c", Value: "3"}, - {Name: "a", Value: "1"}, - } - const numLeakyPushes = 5 - for n := range numLeakyPushes { - req, _ := mockWriteRequest(t, cortexpb.FromLabelAdaptersToLabels(outOfOrderLabels), 1, int64(2+n)) - _, err = i.Push(ctx, req) - require.Error(t, err) - require.Contains(t, err.Error(), "out-of-order label set found") - } - - // The active-appenders gauge must still be 0 — every appender created by - // the early-returning Push() must have been released. - require.NoError(t, testutil.GatherAndCompare(r, bytes.NewBufferString(expectedZero), activeAppendersMetric)) -} - func BenchmarkIngesterPush(b *testing.B) { limits := defaultLimitsTestConfig() benchmarkIngesterPush(b, limits, false) @@ -4558,21 +4500,21 @@ func mockWriteRequest(t *testing.T, lbls labels.Labels, value float64, timestamp func mockHistogramWriteRequest(t *testing.T, lbls labels.Labels, value int64, timestampMs int64, float bool) (*cortexpb.WriteRequest, *client.QueryStreamResponse) { var ( - histograms []cortexpb.Histogram + histograms []cortexpb.WrappedHistogram h *histogram.Histogram fh *histogram.FloatHistogram c chunkenc.Chunk ) if float { fh = tsdbutil.GenerateTestFloatHistogram(value) - histograms = []cortexpb.Histogram{ - cortexpb.FloatHistogramToHistogramProto(timestampMs, fh), + histograms = []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.FloatHistogramToHistogramProto(timestampMs, fh)), } c = chunkenc.NewFloatHistogramChunk() } else { h = tsdbutil.GenerateTestHistogram(value) - histograms = []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(timestampMs, h), + histograms = []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(timestampMs, h)), } c = chunkenc.NewHistogramChunk() } diff --git a/pkg/ruler/compat.go b/pkg/ruler/compat.go index ff9a5995b2b..afac8f1574c 100644 --- a/pkg/ruler/compat.go +++ b/pkg/ruler/compat.go @@ -49,7 +49,7 @@ type PusherAppender struct { labels []labels.Labels samples []cortexpb.Sample histogramLabels []labels.Labels - histograms []cortexpb.Histogram + histograms []cortexpb.WrappedHistogram userID string opts *storage.AppendOptions } @@ -59,9 +59,9 @@ func (a *PusherAppender) AppendHistogram(_ storage.SeriesRef, l labels.Labels, t return 0, errors.New("no histogram") } if h != nil { - a.histograms = append(a.histograms, cortexpb.HistogramToHistogramProto(t, h)) + a.histograms = append(a.histograms, cortexpb.WrappedHistogram{Histogram: cortexpb.HistogramToHistogramProto(t, h)}) } else { - a.histograms = append(a.histograms, cortexpb.FloatHistogramToHistogramProto(t, fh)) + a.histograms = append(a.histograms, cortexpb.WrappedHistogram{Histogram: cortexpb.FloatHistogramToHistogramProto(t, fh)}) } a.histogramLabels = append(a.histogramLabels, l) return 0, nil diff --git a/pkg/ruler/compat_test.go b/pkg/ruler/compat_test.go index 1d0c5d2a8b4..d22035c4b3d 100644 --- a/pkg/ruler/compat_test.go +++ b/pkg/ruler/compat_test.go @@ -142,8 +142,8 @@ func TestPusherAppendable(t *testing.T) { { TimeSeries: &cortexpb.TimeSeries{ Labels: lbls1, - Histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(120_000, testHistogram), + Histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(120_000, testHistogram)), }, }, }, @@ -160,8 +160,8 @@ func TestPusherAppendable(t *testing.T) { { TimeSeries: &cortexpb.TimeSeries{ Labels: lbls1, - Histograms: []cortexpb.Histogram{ - cortexpb.FloatHistogramToHistogramProto(120_000, testFloatHistogram), + Histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.FloatHistogramToHistogramProto(120_000, testFloatHistogram)), }, }, }, @@ -187,8 +187,8 @@ func TestPusherAppendable(t *testing.T) { { TimeSeries: &cortexpb.TimeSeries{ Labels: lbls1, - Histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(120_000, testHistogram), + Histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(120_000, testHistogram)), }, }, }, @@ -214,8 +214,8 @@ func TestPusherAppendable(t *testing.T) { { TimeSeries: &cortexpb.TimeSeries{ Labels: lbls1, - Histograms: []cortexpb.Histogram{ - cortexpb.FloatHistogramToHistogramProto(120_000, testFloatHistogram), + Histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.FloatHistogramToHistogramProto(120_000, testFloatHistogram)), }, }, }, diff --git a/pkg/util/http_test.go b/pkg/util/http_test.go index 199fa8ad06e..d2a5e128d4f 100644 --- a/pkg/util/http_test.go +++ b/pkg/util/http_test.go @@ -155,7 +155,7 @@ func TestParseProtoReader(t *testing.T) { {Value: 30, TimestampMs: 3}, }, Exemplars: []cortexpb.Exemplar{}, - Histograms: []cortexpb.Histogram{}, + Histograms: []cortexpb.WrappedHistogram{}, }, }, }, diff --git a/pkg/util/push/otlp.go b/pkg/util/push/otlp.go index 19f1ef58191..132df49018e 100644 --- a/pkg/util/push/otlp.go +++ b/pkg/util/push/otlp.go @@ -246,10 +246,10 @@ func makeExemplars(in []prompb.Exemplar) []cortexpb.Exemplar { return out } -func makeHistograms(in []prompb.Histogram) []cortexpb.Histogram { - out := make([]cortexpb.Histogram, 0, len(in)) +func makeHistograms(in []prompb.Histogram) []cortexpb.WrappedHistogram { + out := make([]cortexpb.WrappedHistogram, 0, len(in)) for _, h := range in { - out = append(out, cortexpb.HistogramPromProtoToHistogramProto(h)) + out = append(out, cortexpb.WrappedHistogram{Histogram: cortexpb.HistogramPromProtoToHistogramProto(h)}) } return out } diff --git a/pkg/util/push/push_test.go b/pkg/util/push/push_test.go index fb89bc3d640..28070a51559 100644 --- a/pkg/util/push/push_test.go +++ b/pkg/util/push/push_test.go @@ -105,9 +105,9 @@ func makeV2ReqWithSeries(num int) *cortexpb.PreallocWriteRequestV2 { }, Samples: []cortexpb.Sample{{Value: 1, TimestampMs: 10}}, Exemplars: []cortexpb.ExemplarV2{{LabelsRefs: []uint32{11, 12}, Value: 1, Timestamp: 10}}, - Histograms: []cortexpb.Histogram{ - cortexpb.HistogramToHistogramProto(10, &testHistogram), - cortexpb.FloatHistogramToHistogramProto(20, testHistogram.ToFloat(nil)), + Histograms: []cortexpb.WrappedHistogram{ + cortexpb.WrapHistogram(cortexpb.HistogramToHistogramProto(10, &testHistogram)), + cortexpb.WrapHistogram(cortexpb.FloatHistogramToHistogramProto(20, testHistogram.ToFloat(nil))), }, }, }) @@ -519,7 +519,7 @@ func Test_convertV2RequestToV1(t *testing.T) { var v2Req cortexpb.PreallocWriteRequestV2 fh := tsdbutil.GenerateTestFloatHistogram(1) - ph := cortexpb.FloatHistogramToHistogramProto(4, fh) + ph := cortexpb.WrapHistogram(cortexpb.FloatHistogramToHistogramProto(4, fh)) symbols := []string{"", "__name__", "test_metric", "b", "c", "baz", "qux", "d", "e", "foo", "bar", "f", "g", "h", "i", "Test gauge for test purposes", "Maybe op/sec who knows (:", "Test counter for test purposes"} timeseries := []cortexpb.PreallocTimeseriesV2{ @@ -551,7 +551,7 @@ func Test_convertV2RequestToV1(t *testing.T) { { TimeSeriesV2: &cortexpb.TimeSeriesV2{ LabelsRefs: []uint32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - Histograms: []cortexpb.Histogram{ph, ph}, + Histograms: []cortexpb.WrappedHistogram{ph, ph}, Exemplars: []cortexpb.ExemplarV2{{LabelsRefs: []uint32{11, 12}, Value: 1, Timestamp: 1}}, }, }, @@ -778,6 +778,29 @@ func TestHandler_remoteWrite(t *testing.T) { expectedStatus: http.StatusBadRequest, expectedBody: "TimeSeries must contain at least one sample or histogram for series {__name__=\"foo\"}", }, + { + name: "remote write v1 with oversized histogram returns 400", + createBody: func() ([]byte, bool) { + // Create a histogram that exceeds the default 16KB limit + h := cortexpb.Histogram{ + Schema: 3, + NegativeDeltas: make([]int64, 10000), + PositiveDeltas: make([]int64, 10000), + } + ts := cortexpb.TimeSeries{ + Labels: []cortexpb.LabelAdapter{{Name: "__name__", Value: "test"}}, + Histograms: []cortexpb.WrappedHistogram{{Histogram: h}}, + } + wr := cortexpb.WriteRequest{ + Timeseries: []cortexpb.PreallocTimeseries{{TimeSeries: &ts}}, + } + data, err := wr.Marshal() + require.NoError(t, err) + return data, false + }, + expectedStatus: http.StatusBadRequest, + expectedBody: "native histogram size", + }, } for _, test := range tests { @@ -1302,7 +1325,7 @@ func TestHandler_RemoteWriteV2_MetadataPoolReset(t *testing.T) { func Test_convertV2RequestToV1_DeepCopy(t *testing.T) { fh := tsdbutil.GenerateTestFloatHistogram(1) - ph := cortexpb.FloatHistogramToHistogramProto(4, fh) + ph := cortexpb.WrapHistogram(cortexpb.FloatHistogramToHistogramProto(4, fh)) v2Req := &cortexpb.PreallocWriteRequestV2{ WriteRequestV2: cortexpb.WriteRequestV2{ @@ -1317,7 +1340,7 @@ func Test_convertV2RequestToV1_DeepCopy(t *testing.T) { Exemplars: []cortexpb.ExemplarV2{ {LabelsRefs: []uint32{1, 2}, Value: 2.0, Timestamp: 1000}, }, - Histograms: []cortexpb.Histogram{ + Histograms: []cortexpb.WrappedHistogram{ ph, }, }, @@ -1354,8 +1377,8 @@ func Test_convertV2RequestToV1_PreservesStartTimestamp(t *testing.T) { Samples: []cortexpb.Sample{ {Value: 1, TimestampMs: 1000, StartTimestampMs: 100}, }, - Histograms: []cortexpb.Histogram{ - {TimestampMs: 2000, StartTimestampMs: 200}, + Histograms: []cortexpb.WrappedHistogram{ + {Histogram: cortexpb.Histogram{TimestampMs: 2000, StartTimestampMs: 200}}, }, }, }, @@ -1392,7 +1415,7 @@ func Test_convertV2RequestToV1_UsesCreatedTimestampAsFallback(t *testing.T) { LabelsRefs: []uint32{1, 2}, CreatedTimestamp: 777, Samples: []cortexpb.Sample{{Value: 1, TimestampMs: 1000}}, - Histograms: []cortexpb.Histogram{{TimestampMs: 2000}}, + Histograms: []cortexpb.WrappedHistogram{{Histogram: cortexpb.Histogram{TimestampMs: 2000}}}, }, }, }, @@ -1430,8 +1453,8 @@ func Test_convertV2RequestToV1_ExplicitStartTimestampTakesPrecedence(t *testing. Samples: []cortexpb.Sample{ {Value: 1, TimestampMs: 1000, StartTimestampMs: 100}, }, - Histograms: []cortexpb.Histogram{ - {TimestampMs: 2000, StartTimestampMs: 200}, + Histograms: []cortexpb.WrappedHistogram{ + {Histogram: cortexpb.Histogram{TimestampMs: 2000, StartTimestampMs: 200}}, }, }, },