@@ -39,6 +39,17 @@ func TestProtobufCodec_Encode(t *testing.T) {
39
39
}
40
40
testProtoHistogram := cortexpb .FloatHistogramToHistogramProto (1000 , testFloatHistogram )
41
41
42
+ floatHistogramWithEmptyBucket := & histogram.FloatHistogram {
43
+ CounterResetHint : 0 ,
44
+ Schema : 1 ,
45
+ ZeroThreshold : 0.01 ,
46
+ ZeroCount : 0 ,
47
+ Count : 0 ,
48
+ Sum : 1 ,
49
+ PositiveSpans : []histogram.Span {{Offset : 0 , Length : 1 }},
50
+ PositiveBuckets : []float64 {0 },
51
+ }
52
+
42
53
tests := []struct {
43
54
name string
44
55
data * v1.QueryData
@@ -287,6 +298,47 @@ func TestProtobufCodec_Encode(t *testing.T) {
287
298
},
288
299
},
289
300
},
301
+ {
302
+ name : "matrix with histogram and not cortex internal, empty bucket" ,
303
+ data : & v1.QueryData {
304
+ ResultType : parser .ValueTypeMatrix ,
305
+ Result : promql.Matrix {
306
+ promql.Series {
307
+ Histograms : []promql.HPoint {{H : floatHistogramWithEmptyBucket , T : 1000 }},
308
+ Metric : labels .FromStrings ("__name__" , "foo" ),
309
+ },
310
+ },
311
+ },
312
+ expected : & tripperware.PrometheusResponse {
313
+ Status : tripperware .StatusSuccess ,
314
+ Data : tripperware.PrometheusData {
315
+ ResultType : model .ValMatrix .String (),
316
+ Result : tripperware.PrometheusQueryResult {
317
+ Result : & tripperware.PrometheusQueryResult_Matrix {
318
+ Matrix : & tripperware.Matrix {
319
+ SampleStreams : []tripperware.SampleStream {
320
+ {
321
+ Labels : []cortexpb.LabelAdapter {
322
+ {Name : "__name__" , Value : "foo" },
323
+ },
324
+ Histograms : []tripperware.SampleHistogramPair {
325
+ {
326
+ TimestampMs : 1000 ,
327
+ Histogram : tripperware.SampleHistogram {
328
+ Count : 0 ,
329
+ Sum : 1 ,
330
+ Buckets : []* tripperware.HistogramBucket {},
331
+ },
332
+ },
333
+ },
334
+ },
335
+ },
336
+ },
337
+ },
338
+ },
339
+ },
340
+ },
341
+ },
290
342
{
291
343
name : "vector with histogram and not cortex internal" ,
292
344
data : & v1.QueryData {
@@ -376,6 +428,46 @@ func TestProtobufCodec_Encode(t *testing.T) {
376
428
},
377
429
},
378
430
},
431
+ {
432
+ name : "vector with histogram with and not cortex internal, empty bucket" ,
433
+ data : & v1.QueryData {
434
+ ResultType : parser .ValueTypeVector ,
435
+ Result : promql.Vector {
436
+ promql.Sample {
437
+ Metric : labels .FromStrings ("__name__" , "foo" ),
438
+ T : 1000 ,
439
+ H : floatHistogramWithEmptyBucket ,
440
+ },
441
+ },
442
+ },
443
+ expected : & tripperware.PrometheusResponse {
444
+ Status : tripperware .StatusSuccess ,
445
+ Data : tripperware.PrometheusData {
446
+ ResultType : model .ValVector .String (),
447
+ Result : tripperware.PrometheusQueryResult {
448
+ Result : & tripperware.PrometheusQueryResult_Vector {
449
+ Vector : & tripperware.Vector {
450
+ Samples : []tripperware.Sample {
451
+ {
452
+ Labels : []cortexpb.LabelAdapter {
453
+ {Name : "__name__" , Value : "foo" },
454
+ },
455
+ Histogram : & tripperware.SampleHistogramPair {
456
+ TimestampMs : 1000 ,
457
+ Histogram : tripperware.SampleHistogram {
458
+ Count : 0 ,
459
+ Sum : 1 ,
460
+ Buckets : []* tripperware.HistogramBucket {},
461
+ },
462
+ },
463
+ },
464
+ },
465
+ },
466
+ },
467
+ },
468
+ },
469
+ },
470
+ },
379
471
{
380
472
name : "vector with histogram and cortex internal" ,
381
473
cortexInternal : true ,
0 commit comments