@@ -10,66 +10,40 @@ use crate::errors::{Error, Result};
10
10
use crate :: metrics:: SEPARATOR_BYTE ;
11
11
use crate :: proto:: LabelPair ;
12
12
13
- #[ cfg( not( feature = "regex" ) ) ]
14
- mod validation {
15
- fn matches_charset_without_colon ( c : char ) -> bool {
16
- c. is_ascii_alphabetic ( ) || c == '_'
17
- }
18
-
19
- fn matches_charset_with_colon ( c : char ) -> bool {
20
- matches_charset_without_colon ( c) || c == ':'
21
- }
22
-
23
- /// Equivalent to regex `^[?][?0-9]*$` where `?` denotes char set as validated by `charset_validator`.
24
- fn is_valid_ident < F : FnMut ( char ) -> bool > ( input : & str , mut charset_validator : F ) -> bool {
25
- let mut chars = input. chars ( ) ;
26
- let zeroth = chars. next ( ) ;
27
- zeroth
28
- . and_then ( |zeroth| {
29
- if charset_validator ( zeroth) {
30
- Some ( chars. all ( |c| charset_validator ( c) || c. is_digit ( 10 ) ) )
31
- } else {
32
- None
33
- }
34
- } )
35
- . unwrap_or ( false )
36
- }
37
-
38
- // Details of required format are at
39
- // https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels
40
- pub ( super ) fn is_valid_metric_name ( name : & str ) -> bool {
41
- is_valid_ident ( name, matches_charset_with_colon)
42
- }
43
-
44
- pub ( super ) fn is_valid_label_name ( name : & str ) -> bool {
45
- is_valid_ident ( name, matches_charset_without_colon)
46
- }
13
+ // [a-zA-Z_]
14
+ fn matches_charset_without_colon ( c : char ) -> bool {
15
+ c. is_ascii_alphabetic ( ) || c == '_'
47
16
}
48
17
49
- #[ cfg( feature = "regex" ) ]
50
- mod validation {
51
- use regex:: Regex ;
52
-
53
- pub ( super ) fn is_valid_metric_name ( name : & str ) -> bool {
54
- lazy_static ! {
55
- static ref VALIDATOR : Regex =
56
- Regex :: new( "^[a-zA-Z_:][a-zA-Z0-9_:]*$" ) . expect( "Regex to be valid." ) ;
57
- }
58
-
59
- VALIDATOR . is_match ( name)
60
- }
18
+ // [a-zA-Z_:]
19
+ fn matches_charset_with_colon ( c : char ) -> bool {
20
+ matches_charset_without_colon ( c) || c == ':'
21
+ }
61
22
62
- pub ( super ) fn is_valid_label_name ( name : & str ) -> bool {
63
- lazy_static ! {
64
- static ref VALIDATOR : Regex =
65
- Regex :: new( "^[a-zA-Z_][a-zA-Z0-9_]*$" ) . expect( "Regex to be valid." ) ;
66
- }
23
+ // Equivalent to regex ^[?][?0-9]*$ where ? denotes char set as validated by charset_validator
24
+ fn is_valid_ident < F : FnMut ( char ) -> bool > ( input : & str , mut charset_validator : F ) -> bool {
25
+ let mut chars = input. chars ( ) ;
26
+ let zeroth = chars. next ( ) ;
27
+ zeroth
28
+ . and_then ( |zeroth| {
29
+ if charset_validator ( zeroth) {
30
+ Some ( chars. all ( |c| charset_validator ( c) || c. is_digit ( 10 ) ) )
31
+ } else {
32
+ None
33
+ }
34
+ } )
35
+ . unwrap_or ( false )
36
+ }
67
37
68
- VALIDATOR . is_match ( name)
69
- }
38
+ // Details of required format are at
39
+ // https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels
40
+ pub ( super ) fn is_valid_metric_name ( name : & str ) -> bool {
41
+ is_valid_ident ( name, matches_charset_with_colon)
70
42
}
71
43
72
- use validation:: * ;
44
+ pub ( super ) fn is_valid_label_name ( name : & str ) -> bool {
45
+ is_valid_ident ( name, matches_charset_without_colon)
46
+ }
73
47
74
48
/// The descriptor used by every Prometheus [`Metric`](crate::core::Metric). It is essentially
75
49
/// the immutable meta-data of a metric. The normal metric implementations
0 commit comments