@@ -43,12 +43,12 @@ var (
4343 Schema : 2 ,
4444 ZeroThreshold : 1e-128 ,
4545 ZeroCount : 0 ,
46- Count : 0 ,
46+ Count : 3 ,
4747 Sum : 20 ,
4848 PositiveSpans : []histogram.Span {{Offset : 0 , Length : 1 }},
4949 PositiveBuckets : []int64 {1 },
5050 NegativeSpans : []histogram.Span {{Offset : 0 , Length : 1 }},
51- NegativeBuckets : []int64 {- 1 },
51+ NegativeBuckets : []int64 {2 },
5252 }
5353
5454 writeRequestFixture = & prompb.WriteRequest {
9090 Help : "Test counter for test purposes" ,
9191 }
9292
93+ testHistogramCustomBuckets = histogram.Histogram {
94+ Schema : histogram .CustomBucketsSchema ,
95+ Count : 16 ,
96+ Sum : 20 ,
97+ PositiveSpans : []histogram.Span {{Offset : 1 , Length : 2 }},
98+ PositiveBuckets : []int64 {10 , - 4 }, // Means 10 observations for upper bound 1.0 and 6 for upper bound +Inf.
99+ CustomValues : []float64 {0.1 , 1.0 }, // +Inf is implied.
100+ }
101+
93102 // writeV2RequestFixture represents the same request as writeRequestFixture,
94103 // but using the v2 representation, plus includes writeV2RequestSeries1Metadata and writeV2RequestSeries2Metadata.
95104 // NOTE: Use TestWriteV2RequestFixture and copy the diff to regenerate if needed.
@@ -104,9 +113,14 @@ var (
104113 HelpRef : 15 , // Symbolized writeV2RequestSeries1Metadata.Help.
105114 UnitRef : 16 , // Symbolized writeV2RequestSeries1Metadata.Unit.
106115 },
107- Samples : []writev2.Sample {{Value : 1 , Timestamp : 10 }},
108- Exemplars : []writev2.Exemplar {{LabelsRefs : []uint32 {11 , 12 }, Value : 1 , Timestamp : 10 }},
109- Histograms : []writev2.Histogram {writev2 .FromIntHistogram (10 , & testHistogram ), writev2 .FromFloatHistogram (20 , testHistogram .ToFloat (nil ))},
116+ Samples : []writev2.Sample {{Value : 1 , Timestamp : 10 }},
117+ Exemplars : []writev2.Exemplar {{LabelsRefs : []uint32 {11 , 12 }, Value : 1 , Timestamp : 10 }},
118+ Histograms : []writev2.Histogram {
119+ writev2 .FromIntHistogram (10 , & testHistogram ),
120+ writev2 .FromFloatHistogram (20 , testHistogram .ToFloat (nil )),
121+ writev2 .FromIntHistogram (30 , & testHistogramCustomBuckets ),
122+ writev2 .FromFloatHistogram (40 , testHistogramCustomBuckets .ToFloat (nil )),
123+ },
110124 CreatedTimestamp : 1 , // CT needs to be lower than the sample's timestamp.
111125 },
112126 {
@@ -117,14 +131,40 @@ var (
117131 HelpRef : 17 , // Symbolized writeV2RequestSeries2Metadata.Help.
118132 // No unit.
119133 },
120- Samples : []writev2.Sample {{Value : 2 , Timestamp : 20 }},
121- Exemplars : []writev2.Exemplar {{LabelsRefs : []uint32 {13 , 14 }, Value : 2 , Timestamp : 20 }},
122- Histograms : []writev2.Histogram {writev2 .FromIntHistogram (30 , & testHistogram ), writev2 .FromFloatHistogram (40 , testHistogram .ToFloat (nil ))},
134+ Samples : []writev2.Sample {{Value : 2 , Timestamp : 20 }},
135+ Exemplars : []writev2.Exemplar {{LabelsRefs : []uint32 {13 , 14 }, Value : 2 , Timestamp : 20 }},
136+ Histograms : []writev2.Histogram {
137+ writev2 .FromIntHistogram (50 , & testHistogram ),
138+ writev2 .FromFloatHistogram (60 , testHistogram .ToFloat (nil )),
139+ writev2 .FromIntHistogram (70 , & testHistogramCustomBuckets ),
140+ writev2 .FromFloatHistogram (80 , testHistogramCustomBuckets .ToFloat (nil )),
141+ },
123142 },
124143 },
125144 }
126145)
127146
147+ func TestHistogramFixtureValid (t * testing.T ) {
148+ for _ , ts := range writeRequestFixture .Timeseries {
149+ for _ , h := range ts .Histograms {
150+ if h .IsFloatHistogram () {
151+ require .NoError (t , h .ToFloatHistogram ().Validate ())
152+ } else {
153+ require .NoError (t , h .ToIntHistogram ().Validate ())
154+ }
155+ }
156+ }
157+ for _ , ts := range writeV2RequestFixture .Timeseries {
158+ for _ , h := range ts .Histograms {
159+ if h .IsFloatHistogram () {
160+ require .NoError (t , h .ToFloatHistogram ().Validate ())
161+ } else {
162+ require .NoError (t , h .ToIntHistogram ().Validate ())
163+ }
164+ }
165+ }
166+ }
167+
128168func TestWriteV2RequestFixture (t * testing.T ) {
129169 // Generate dynamically writeV2RequestFixture, reusing v1 fixture elements.
130170 st := writev2 .NewSymbolTable ()
@@ -141,9 +181,14 @@ func TestWriteV2RequestFixture(t *testing.T) {
141181 HelpRef : st .Symbolize (writeV2RequestSeries1Metadata .Help ),
142182 UnitRef : st .Symbolize (writeV2RequestSeries1Metadata .Unit ),
143183 },
144- Samples : []writev2.Sample {{Value : 1 , Timestamp : 10 }},
145- Exemplars : []writev2.Exemplar {{LabelsRefs : exemplar1LabelRefs , Value : 1 , Timestamp : 10 }},
146- Histograms : []writev2.Histogram {writev2 .FromIntHistogram (10 , & testHistogram ), writev2 .FromFloatHistogram (20 , testHistogram .ToFloat (nil ))},
184+ Samples : []writev2.Sample {{Value : 1 , Timestamp : 10 }},
185+ Exemplars : []writev2.Exemplar {{LabelsRefs : exemplar1LabelRefs , Value : 1 , Timestamp : 10 }},
186+ Histograms : []writev2.Histogram {
187+ writev2 .FromIntHistogram (10 , & testHistogram ),
188+ writev2 .FromFloatHistogram (20 , testHistogram .ToFloat (nil )),
189+ writev2 .FromIntHistogram (30 , & testHistogramCustomBuckets ),
190+ writev2 .FromFloatHistogram (40 , testHistogramCustomBuckets .ToFloat (nil )),
191+ },
147192 CreatedTimestamp : 1 ,
148193 },
149194 {
@@ -153,9 +198,14 @@ func TestWriteV2RequestFixture(t *testing.T) {
153198 HelpRef : st .Symbolize (writeV2RequestSeries2Metadata .Help ),
154199 // No unit.
155200 },
156- Samples : []writev2.Sample {{Value : 2 , Timestamp : 20 }},
157- Exemplars : []writev2.Exemplar {{LabelsRefs : exemplar2LabelRefs , Value : 2 , Timestamp : 20 }},
158- Histograms : []writev2.Histogram {writev2 .FromIntHistogram (30 , & testHistogram ), writev2 .FromFloatHistogram (40 , testHistogram .ToFloat (nil ))},
201+ Samples : []writev2.Sample {{Value : 2 , Timestamp : 20 }},
202+ Exemplars : []writev2.Exemplar {{LabelsRefs : exemplar2LabelRefs , Value : 2 , Timestamp : 20 }},
203+ Histograms : []writev2.Histogram {
204+ writev2 .FromIntHistogram (50 , & testHistogram ),
205+ writev2 .FromFloatHistogram (60 , testHistogram .ToFloat (nil )),
206+ writev2 .FromIntHistogram (70 , & testHistogramCustomBuckets ),
207+ writev2 .FromFloatHistogram (80 , testHistogramCustomBuckets .ToFloat (nil )),
208+ },
159209 },
160210 },
161211 Symbols : st .Symbols (),
0 commit comments