46
46
from opentelemetry .sdk ._metrics .point import (
47
47
AggregationTemporality ,
48
48
Gauge ,
49
+ Histogram ,
49
50
Metric ,
50
51
Sum ,
51
52
)
@@ -152,9 +153,20 @@ def setUp(self):
152
153
153
154
self .metrics = {
154
155
"sum_int" : _generate_sum ("sum_int" , 33 ),
155
- "sum_float " : _generate_sum ("sum_float " , 2.98 ),
156
+ "sum_double " : _generate_sum ("sum_double " , 2.98 ),
156
157
"gauge_int" : _generate_gauge ("gauge_int" , 9000 ),
157
- "gauge_float" : _generate_gauge ("gauge_float" , 52.028 ),
158
+ "gauge_double" : _generate_gauge ("gauge_double" , 52.028 ),
159
+ "histogram" : _generate_metric (
160
+ "histogram" ,
161
+ Histogram (
162
+ time_unix_nano = 1641946016139533244 ,
163
+ start_time_unix_nano = 1641946016139533244 ,
164
+ bucket_counts = [1 , 4 ],
165
+ sum = 67 ,
166
+ explicit_bounds = [10.0 , 20.0 ],
167
+ aggregation_temporality = AggregationTemporality .DELTA ,
168
+ ),
169
+ ),
158
170
}
159
171
160
172
def tearDown (self ):
@@ -367,7 +379,7 @@ def test_translate_sum_int(self):
367
379
actual = self .exporter ._translate_data ([self .metrics ["sum_int" ]])
368
380
self .assertEqual (expected , actual )
369
381
370
- def test_translate_sum_float (self ):
382
+ def test_translate_sum_double (self ):
371
383
expected = ExportMetricsServiceRequest (
372
384
resource_metrics = [
373
385
pb2 .ResourceMetrics (
@@ -386,7 +398,7 @@ def test_translate_sum_float(self):
386
398
),
387
399
metrics = [
388
400
pb2 .Metric (
389
- name = "sum_float " ,
401
+ name = "sum_double " ,
390
402
unit = "s" ,
391
403
description = "foo" ,
392
404
sum = pb2 .Sum (
@@ -422,7 +434,7 @@ def test_translate_sum_float(self):
422
434
]
423
435
)
424
436
# pylint: disable=protected-access
425
- actual = self .exporter ._translate_data ([self .metrics ["sum_float " ]])
437
+ actual = self .exporter ._translate_data ([self .metrics ["sum_double " ]])
426
438
self .assertEqual (expected , actual )
427
439
428
440
def test_translate_gauge_int (self ):
@@ -480,7 +492,7 @@ def test_translate_gauge_int(self):
480
492
actual = self .exporter ._translate_data ([self .metrics ["gauge_int" ]])
481
493
self .assertEqual (expected , actual )
482
494
483
- def test_translate_gauge_float (self ):
495
+ def test_translate_gauge_double (self ):
484
496
expected = ExportMetricsServiceRequest (
485
497
resource_metrics = [
486
498
pb2 .ResourceMetrics (
@@ -499,7 +511,7 @@ def test_translate_gauge_float(self):
499
511
),
500
512
metrics = [
501
513
pb2 .Metric (
502
- name = "gauge_float " ,
514
+ name = "gauge_double " ,
503
515
unit = "s" ,
504
516
description = "foo" ,
505
517
gauge = pb2 .Gauge (
@@ -532,5 +544,66 @@ def test_translate_gauge_float(self):
532
544
]
533
545
)
534
546
# pylint: disable=protected-access
535
- actual = self .exporter ._translate_data ([self .metrics ["gauge_float" ]])
547
+ actual = self .exporter ._translate_data ([self .metrics ["gauge_double" ]])
548
+ self .assertEqual (expected , actual )
549
+
550
+ def test_translate_histogram (self ):
551
+ expected = ExportMetricsServiceRequest (
552
+ resource_metrics = [
553
+ pb2 .ResourceMetrics (
554
+ resource = OTLPResource (
555
+ attributes = [
556
+ KeyValue (key = "a" , value = AnyValue (int_value = 1 )),
557
+ KeyValue (
558
+ key = "b" , value = AnyValue (bool_value = False )
559
+ ),
560
+ ]
561
+ ),
562
+ instrumentation_library_metrics = [
563
+ pb2 .InstrumentationLibraryMetrics (
564
+ instrumentation_library = InstrumentationLibrary (
565
+ name = "first_name" , version = "first_version"
566
+ ),
567
+ metrics = [
568
+ pb2 .Metric (
569
+ name = "histogram" ,
570
+ unit = "s" ,
571
+ description = "foo" ,
572
+ histogram = pb2 .Histogram (
573
+ data_points = [
574
+ pb2 .HistogramDataPoint (
575
+ attributes = [
576
+ KeyValue (
577
+ key = "a" ,
578
+ value = AnyValue (
579
+ int_value = 1
580
+ ),
581
+ ),
582
+ KeyValue (
583
+ key = "b" ,
584
+ value = AnyValue (
585
+ bool_value = True
586
+ ),
587
+ ),
588
+ ],
589
+ start_time_unix_nano = 1641946016139533244 ,
590
+ time_unix_nano = 1641946016139533244 ,
591
+ count = 5 ,
592
+ bucket_counts = [1 , 4 ],
593
+ explicit_bounds = [10.0 , 20.0 ],
594
+ exemplars = [],
595
+ flags = pb2 .DataPointFlags .FLAG_NONE ,
596
+ )
597
+ ],
598
+ aggregation_temporality = AggregationTemporality .DELTA ,
599
+ ),
600
+ )
601
+ ],
602
+ )
603
+ ],
604
+ )
605
+ ]
606
+ )
607
+ # pylint: disable=protected-access
608
+ actual = self .exporter ._translate_data ([self .metrics ["histogram" ]])
536
609
self .assertEqual (expected , actual )
0 commit comments