@@ -20,21 +20,29 @@ use crate::metrics::{
2020use super :: noop:: NoopSyncInstrument ;
2121
2222// maximum length of instrument name
23+ #[ cfg( not( feature = "experimental_metrics_disable_name_validation" ) ) ]
2324const INSTRUMENT_NAME_MAX_LENGTH : usize = 255 ;
25+
2426// maximum length of instrument unit name
2527const INSTRUMENT_UNIT_NAME_MAX_LENGTH : usize = 63 ;
28+
29+ // Characters allowed in instrument name
2630#[ cfg( not( feature = "experimental_metrics_disable_name_validation" ) ) ]
2731const INSTRUMENT_NAME_ALLOWED_NON_ALPHANUMERIC_CHARS : [ char ; 4 ] = [ '_' , '.' , '-' , '/' ] ;
2832
29- // instrument validation error strings
33+ // instrument name validation error strings
34+ #[ cfg( not( feature = "experimental_metrics_disable_name_validation" ) ) ]
3035const INSTRUMENT_NAME_EMPTY : & str = "instrument name must be non-empty" ;
36+ #[ cfg( not( feature = "experimental_metrics_disable_name_validation" ) ) ]
3137const INSTRUMENT_NAME_LENGTH : & str = "instrument name must be less than 256 characters" ;
3238#[ cfg( not( feature = "experimental_metrics_disable_name_validation" ) ) ]
3339const INSTRUMENT_NAME_INVALID_CHAR : & str =
3440 "characters in instrument name must be ASCII and belong to the alphanumeric characters, '_', '.', '-' and '/'" ;
3541#[ cfg( not( feature = "experimental_metrics_disable_name_validation" ) ) ]
3642const INSTRUMENT_NAME_FIRST_ALPHABETIC : & str =
3743 "instrument name must start with an alphabetic character" ;
44+
45+ // instrument unit validation error strings
3846const INSTRUMENT_UNIT_LENGTH : & str = "instrument unit must be less than 64 characters" ;
3947const INSTRUMENT_UNIT_INVALID_CHAR : & str = "characters in instrument unit must be ASCII" ;
4048
@@ -584,20 +592,8 @@ fn validate_bucket_boundaries(boundaries: &[f64]) -> MetricResult<()> {
584592// }
585593
586594#[ cfg( feature = "experimental_metrics_disable_name_validation" ) ]
587- fn validate_instrument_name ( name : & str ) -> MetricResult < ( ) > {
588- if name. is_empty ( ) {
589- return Err ( MetricError :: InvalidInstrumentConfiguration (
590- INSTRUMENT_NAME_EMPTY ,
591- ) ) ;
592- }
593- if name. len ( ) > INSTRUMENT_NAME_MAX_LENGTH {
594- return Err ( MetricError :: InvalidInstrumentConfiguration (
595- INSTRUMENT_NAME_LENGTH ,
596- ) ) ;
597- }
598-
599- // No name restrictions when name validation is disabled,
600- // except for empty names and length
595+ fn validate_instrument_name ( _name : & str ) -> MetricResult < ( ) > {
596+ // No name restrictions when name validation is disabled
601597 Ok ( ( ) )
602598}
603599
@@ -707,12 +703,15 @@ mod tests {
707703 use crate :: metrics:: MetricError ;
708704
709705 use super :: {
710- validate_instrument_name, validate_instrument_unit, INSTRUMENT_NAME_EMPTY ,
711- INSTRUMENT_NAME_LENGTH , INSTRUMENT_UNIT_INVALID_CHAR , INSTRUMENT_UNIT_LENGTH ,
706+ validate_instrument_name, validate_instrument_unit, INSTRUMENT_UNIT_INVALID_CHAR ,
707+ INSTRUMENT_UNIT_LENGTH ,
712708 } ;
713709
714710 #[ cfg( not( feature = "experimental_metrics_disable_name_validation" ) ) ]
715- use super :: { INSTRUMENT_NAME_FIRST_ALPHABETIC , INSTRUMENT_NAME_INVALID_CHAR } ;
711+ use super :: {
712+ INSTRUMENT_NAME_EMPTY , INSTRUMENT_NAME_FIRST_ALPHABETIC , INSTRUMENT_NAME_INVALID_CHAR ,
713+ INSTRUMENT_NAME_LENGTH ,
714+ } ;
716715
717716 #[ test]
718717 #[ cfg( not( feature = "experimental_metrics_disable_name_validation" ) ) ]
@@ -763,12 +762,12 @@ mod tests {
763762 ( "_startWithNoneAlphabet" , "" ) ,
764763 ( "utf8char锈" , "" ) ,
765764 ( "a" . repeat( 255 ) . leak( ) , "" ) ,
766- ( "a" . repeat( 256 ) . leak( ) , INSTRUMENT_NAME_LENGTH ) ,
765+ ( "a" . repeat( 256 ) . leak( ) , "" ) ,
767766 ( "invalid name" , "" ) ,
768767 ( "allow/slash" , "" ) ,
769768 ( "allow_under_score" , "" ) ,
770769 ( "allow.dots.ok" , "" ) ,
771- ( "" , INSTRUMENT_NAME_EMPTY ) ,
770+ ( "" , "" ) ,
772771 ( "\\ allow\\ slash /sec" , "" ) ,
773772 ( "\\ allow\\ $$slash /sec" , "" ) ,
774773 ( "Total $ Count" , "" ) ,
0 commit comments