1
- use opentelemetry:: metrics:: Unit ;
2
1
use std:: borrow:: Cow ;
3
2
4
3
const NON_APPLICABLE_ON_PER_UNIT : [ & str ; 8 ] = [ "1" , "d" , "h" , "min" , "s" , "ms" , "us" , "ns" ] ;
5
4
6
- pub ( crate ) fn get_unit_suffixes ( unit : & Unit ) -> Option < Cow < ' static , str > > {
5
+ pub ( crate ) fn get_unit_suffixes ( unit : & str ) -> Option < Cow < ' static , str > > {
7
6
// no unit return early
8
- if unit. as_str ( ) . is_empty ( ) {
7
+ if unit. is_empty ( ) {
9
8
return None ;
10
9
}
11
10
12
11
// direct match with known units
13
- if let Some ( matched) = get_prom_units ( unit. as_str ( ) ) {
12
+ if let Some ( matched) = get_prom_units ( unit) {
14
13
return Some ( Cow :: Borrowed ( matched) ) ;
15
14
}
16
15
@@ -20,7 +19,7 @@ pub(crate) fn get_unit_suffixes(unit: &Unit) -> Option<Cow<'static, str>> {
20
19
// e.g
21
20
// "test/y" => "per_year"
22
21
// "km/s" => "kilometers_per_second"
23
- if let Some ( ( first, second) ) = unit. as_str ( ) . split_once ( '/' ) {
22
+ if let Some ( ( first, second) ) = unit. split_once ( '/' ) {
24
23
return match (
25
24
NON_APPLICABLE_ON_PER_UNIT . contains ( & first) ,
26
25
get_prom_units ( first) ,
@@ -193,9 +192,8 @@ mod tests {
193
192
// annotations
194
193
( "{request}" , None ) ,
195
194
] ;
196
- for ( unit_str, expected_suffix) in test_cases {
197
- let unit = Unit :: new ( unit_str) ;
198
- assert_eq ! ( get_unit_suffixes( & unit) , expected_suffix) ;
195
+ for ( unit, expected_suffix) in test_cases {
196
+ assert_eq ! ( get_unit_suffixes( unit) , expected_suffix) ;
199
197
}
200
198
}
201
199
}
0 commit comments