@@ -7,14 +7,23 @@ use opentelemetry::metrics::{Meter, MeterProvider as _};
77use opentelemetry:: KeyValue ;
88use opentelemetry:: { InstrumentationScope , Key } ;
99use opentelemetry_prometheus:: { ExporterBuilder , ResourceSelector } ;
10- use opentelemetry_sdk:: metrics:: { new_view , Aggregation , Instrument , SdkMeterProvider , Stream } ;
10+ use opentelemetry_sdk:: metrics:: SdkMeterProvider ;
1111use opentelemetry_sdk:: resource:: {
1212 EnvResourceDetector , SdkProvidedResourceDetector , TelemetryResourceDetector ,
1313} ;
1414use opentelemetry_sdk:: Resource ;
1515use opentelemetry_semantic_conventions:: resource:: { SERVICE_NAME , TELEMETRY_SDK_VERSION } ;
1616use prometheus:: { Encoder , TextEncoder } ;
1717
18+ const BOUNDARIES : & [ f64 ] = & [
19+ 0.0 , 5.0 , 10.0 , 25.0 , 50.0 , 75.0 , 100.0 , 250.0 , 500.0 , 1000.0 ,
20+ ] ;
21+
22+ const BYTES_BOUNDARIES : & [ f64 ] = & [
23+ 0.0 , 5.0 , 10.0 , 25.0 , 50.0 , 75.0 , 100.0 , 250.0 , 500.0 , 750.0 , 1000.0 , 2500.0 , 5000.0 , 7500.0 ,
24+ 10000.0 ,
25+ ] ;
26+
1827#[ ignore = "https://github.com/open-telemetry/opentelemetry-rust/pull/2224" ]
1928#[ test]
2029fn prometheus_exporter_integration ( ) {
@@ -123,6 +132,7 @@ fn prometheus_exporter_integration() {
123132 . f64_histogram( "histogram_baz" )
124133 . with_description( "a very nice histogram" )
125134 . with_unit( "By" )
135+ . with_boundaries( BOUNDARIES . to_vec( ) )
126136 . build( ) ;
127137 histogram. record( 23.0 , & attrs) ;
128138 histogram. record( 7.0 , & attrs) ;
@@ -185,6 +195,7 @@ fn prometheus_exporter_integration() {
185195 let histogram = meter
186196 . f64_histogram( "invalid.hist.name" )
187197 . with_description( "a histogram with an invalid name" )
198+ . with_boundaries( BOUNDARIES . to_vec( ) )
188199 . build( ) ;
189200 histogram. record( 23.0 , & attrs) ;
190201 } ) ,
@@ -374,18 +385,6 @@ fn prometheus_exporter_integration() {
374385 let provider = SdkMeterProvider :: builder ( )
375386 . with_resource ( res)
376387 . with_reader ( exporter)
377- . with_view (
378- new_view (
379- Instrument :: new ( ) . name ( "histogram_*" ) ,
380- Stream :: new ( ) . aggregation ( Aggregation :: ExplicitBucketHistogram {
381- boundaries : vec ! [
382- 0.0 , 5.0 , 10.0 , 25.0 , 50.0 , 75.0 , 100.0 , 250.0 , 500.0 , 1000.0 ,
383- ] ,
384- record_min_max : true ,
385- } ) ,
386- )
387- . unwrap ( ) ,
388- )
389388 . build ( ) ;
390389
391390 let scope = InstrumentationScope :: builder ( "testmeter" )
@@ -559,6 +558,7 @@ fn duplicate_metrics() {
559558 . u64_histogram( "foo" )
560559 . with_unit( "By" )
561560 . with_description( "meter histogram foo" )
561+ . with_boundaries( BYTES_BOUNDARIES . to_vec( ) )
562562 . build( ) ;
563563
564564 foo_a. record( 100 , & [ KeyValue :: new( "A" , "B" ) ] ) ;
@@ -567,6 +567,7 @@ fn duplicate_metrics() {
567567 . u64_histogram( "foo" )
568568 . with_unit( "By" )
569569 . with_description( "meter histogram foo" )
570+ . with_boundaries( BYTES_BOUNDARIES . to_vec( ) )
570571 . build( ) ;
571572
572573 foo_b. record( 100 , & [ KeyValue :: new( "A" , "B" ) ] ) ;
@@ -631,6 +632,7 @@ fn duplicate_metrics() {
631632 . u64_histogram( "bar" )
632633 . with_unit( "By" )
633634 . with_description( "meter a bar" )
635+ . with_boundaries( BYTES_BOUNDARIES . to_vec( ) )
634636 . build( ) ;
635637
636638 bar_a. record( 100 , & [ KeyValue :: new( "A" , "B" ) ] ) ;
@@ -639,6 +641,7 @@ fn duplicate_metrics() {
639641 . u64_histogram( "bar" )
640642 . with_unit( "By" )
641643 . with_description( "meter b bar" )
644+ . with_boundaries( BYTES_BOUNDARIES . to_vec( ) )
642645 . build( ) ;
643646
644647 bar_b. record( 100 , & [ KeyValue :: new( "A" , "B" ) ] ) ;
@@ -702,6 +705,7 @@ fn duplicate_metrics() {
702705 . u64_histogram( "bar" )
703706 . with_unit( "By" )
704707 . with_description( "meter histogram bar" )
708+ . with_boundaries( BYTES_BOUNDARIES . to_vec( ) )
705709 . build( ) ;
706710
707711 bar_a. record( 100 , & [ KeyValue :: new( "A" , "B" ) ] ) ;
@@ -710,6 +714,7 @@ fn duplicate_metrics() {
710714 . u64_histogram( "bar" )
711715 . with_unit( "ms" )
712716 . with_description( "meter histogram bar" )
717+ . with_boundaries( BYTES_BOUNDARIES . to_vec( ) )
713718 . build( ) ;
714719
715720 bar_b. record( 100 , & [ KeyValue :: new( "A" , "B" ) ] ) ;
@@ -759,6 +764,7 @@ fn duplicate_metrics() {
759764 . u64_histogram( "foo" )
760765 . with_unit( "By" )
761766 . with_description( "meter histogram foo" )
767+ . with_boundaries( BOUNDARIES . to_vec( ) )
762768 . build( ) ;
763769
764770 foo_histogram_a. record( 100 , & [ KeyValue :: new( "A" , "B" ) ] ) ;
0 commit comments