@@ -36,6 +36,7 @@ func TestPrometheusExporter(t *testing.T) {
36
36
options []Option
37
37
expectedFile string
38
38
disableUTF8 bool
39
+ checkMetricFamilies func (t testing.TB , dtos []* dto.MetricFamily )
39
40
}{
40
41
{
41
42
name : "counter" ,
@@ -172,6 +173,51 @@ func TestPrometheusExporter(t *testing.T) {
172
173
gauge .Add (ctx , - .25 , opt )
173
174
},
174
175
},
176
+ {
177
+ name : "expontential histogram" ,
178
+ expectedFile : "testdata/exponential_histogram.txt" ,
179
+ checkMetricFamilies : func (t testing.TB , mfs []* dto.MetricFamily ) {
180
+ var hist * dto.MetricFamily
181
+
182
+ for _ , mf := range mfs {
183
+ if * mf .Name == `exponential_histogram_baz_bytes` {
184
+ hist = mf
185
+ break
186
+ }
187
+ }
188
+
189
+ if hist == nil {
190
+ t .Fatal ("expected to find histogram" )
191
+ }
192
+
193
+ m := hist .GetMetric ()[0 ].Histogram
194
+
195
+ require .Equal (t , 236.0 , * m .SampleSum )
196
+ require .Equal (t , uint64 (4 ), * m .SampleCount )
197
+ require .Equal (t , []int64 {1 , - 1 , 1 , - 1 , 2 }, m .PositiveDelta )
198
+ require .Equal (t , uint32 (5 ), * m .PositiveSpan [0 ].Length )
199
+ require .Equal (t , int32 (3 ), * m .PositiveSpan [0 ].Offset )
200
+
201
+ },
202
+ recordMetrics : func (ctx context.Context , meter otelmetric.Meter ) {
203
+ // NOTE(GiedriusS): there is no text format for exponential (native)
204
+ // histograms so we don't expect any output.
205
+ opt := otelmetric .WithAttributes (
206
+ attribute .Key ("A" ).String ("B" ),
207
+ attribute .Key ("C" ).String ("D" ),
208
+ )
209
+ histogram , err := meter .Float64Histogram (
210
+ "exponential_histogram_baz" ,
211
+ otelmetric .WithDescription ("a very nice histogram" ),
212
+ otelmetric .WithUnit ("By" ),
213
+ )
214
+ require .NoError (t , err )
215
+ histogram .Record (ctx , 23 , opt )
216
+ histogram .Record (ctx , 7 , opt )
217
+ histogram .Record (ctx , 101 , opt )
218
+ histogram .Record (ctx , 105 , opt )
219
+ },
220
+ },
175
221
{
176
222
name : "histogram" ,
177
223
expectedFile : "testdata/histogram.txt" ,
@@ -470,6 +516,9 @@ func TestPrometheusExporter(t *testing.T) {
470
516
}
471
517
472
518
for _ , tc := range testCases {
519
+ if tc .name != `expontential histogram` {
520
+ continue
521
+ }
473
522
t .Run (tc .name , func (t * testing.T ) {
474
523
if tc .disableUTF8 {
475
524
model .NameValidationScheme = model .LegacyValidation
@@ -508,7 +557,14 @@ func TestPrometheusExporter(t *testing.T) {
508
557
metric.Stream {Aggregation : metric.AggregationExplicitBucketHistogram {
509
558
Boundaries : []float64 {0 , 5 , 10 , 25 , 50 , 75 , 100 , 250 , 500 , 1000 },
510
559
}},
511
- )),
560
+ ),
561
+ metric .NewView (
562
+ metric.Instrument {Name : "exponential_histogram_*" },
563
+ metric.Stream {Aggregation : metric.AggregationBase2ExponentialHistogram {
564
+ MaxSize : 10 ,
565
+ }},
566
+ ),
567
+ ),
512
568
)
513
569
meter := provider .Meter (
514
570
"testmeter" ,
@@ -524,6 +580,15 @@ func TestPrometheusExporter(t *testing.T) {
524
580
525
581
err = testutil .GatherAndCompare (registry , file )
526
582
require .NoError (t , err )
583
+
584
+ if tc .checkMetricFamilies == nil {
585
+ return
586
+ }
587
+
588
+ mfs , err := registry .Gather ()
589
+ require .NoError (t , err )
590
+
591
+ tc .checkMetricFamilies (t , mfs )
527
592
})
528
593
}
529
594
}
0 commit comments