@@ -44,7 +44,7 @@ prefix_count 405
4444 testMarshalTo (t , h , "prefix" , expected )
4545
4646 // make sure that if the +Inf bucket is manually specified it gets ignored and we have the same resutls at the end
47- h2 := NewPrometheusHistogramExt ("TestPrometheusHistogram2" , append (defaultUpperBounds , math .Inf (+ 1 )))
47+ h2 := NewPrometheusHistogramExt ("TestPrometheusHistogram2" , append (PrometheusHistogramDefaultBuckets , math .Inf (+ 1 )))
4848
4949 h .Reset ()
5050
@@ -63,46 +63,41 @@ prefix_count 405
6363 testMarshalTo (t , h2 , "prefix" , expected )
6464}
6565
66- func TestPrometheusHistogramMerge (t * testing.T ) {
67- name := `TestPrometheusHistogramMerge`
68- h := NewPrometheusHistogram (name )
69- // Write data to histogram
70- for i := 0 ; i <= 10_100 ; i += 25 { // from 0 to 10'100 ms in 25ms steps
71- h .Update (float64 (i ) * 1e-3 )
72- }
66+ func TestPrometheusHistogramLinearBuckets (t * testing.T ) {
67+ const expected string = `prefix_bucket{le="0.5"} 1
68+ prefix_bucket{le="1.5"} 2
69+ prefix_bucket{le="2.5"} 3
70+ prefix_bucket{le="3.5"} 4
71+ prefix_bucket{le="4.5"} 5
72+ prefix_bucket{le="5.5"} 6
73+ prefix_bucket{le="6.5"} 7
74+ prefix_bucket{le="7.5"} 8
75+ prefix_bucket{le="8.5"} 9
76+ prefix_bucket{le="9.5"} 10
77+ prefix_bucket{le="+Inf"} 11
78+ prefix_sum 55
79+ prefix_count 11
80+ `
81+ name := "TestPrometheusHistogramLinearBuckets"
82+ upperBounds := LinearBuckets (0.5 , 1.0 , 10 )
83+ h := NewPrometheusHistogramExt (name , upperBounds )
7384
74- b := NewPrometheusHistogram ( "test" )
75- for i := 0 ; i <= 10_100 ; i += 25 { // from 0 to 10'100 ms in 25ms steps
76- h .Update (float64 (i ) * 1e-3 )
85+ // Write data to histogram
86+ for i := 0 ; i <= 10 ; i ++ { // from 0 to 10
87+ h .Update (float64 (i ))
7788 }
7889
79- h .Merge (b )
80-
8190 // Make sure the histogram prints <prefix>_bucket on marshalTo call
82- testMarshalTo (t , h , "prefix" , `prefix_bucket{le="0.005"} 2
83- prefix_bucket{le="0.01"} 2
84- prefix_bucket{le="0.025"} 4
85- prefix_bucket{le="0.05"} 6
86- prefix_bucket{le="0.1"} 10
87- prefix_bucket{le="0.25"} 22
88- prefix_bucket{le="0.5"} 42
89- prefix_bucket{le="1"} 82
90- prefix_bucket{le="2.5"} 202
91- prefix_bucket{le="5"} 402
92- prefix_bucket{le="10"} 802
93- prefix_bucket{le="+Inf"} 810
94- prefix_sum 4090.5
95- prefix_count 810
96- ` )
91+ testMarshalTo (t , h , "prefix" , expected )
9792
93+ // Make sure we panic when the count of linear buckets is < 1
9894 func () {
9995 defer func () {
10096 if r := recover (); r == nil {
101- t .Error ( "Merge did not panic with mimatched buckets ." )
97+ t .Errorf ( "LinearBuckets should've panicked with a count of 0 ." )
10298 }
10399 }()
104- h2 := NewPrometheusHistogramExt ("TestPrometheusHistogramMerge2" , []float64 {14 })
105- h .Merge (h2 )
100+ _ = LinearBuckets (.14 , .22 , 0 )
106101 }()
107102}
108103
0 commit comments