@@ -15,6 +15,7 @@ def _init_legacy_validation() -> bool:
15
15
16
16
17
17
def get_legacy_validation () -> bool :
18
+ """Return the current status of the legacy validation setting."""
18
19
global _legacy_validation
19
20
return _legacy_validation
20
21
@@ -32,6 +33,10 @@ def enable_legacy_validation():
32
33
33
34
34
35
def _validate_metric_name (name : str ) -> None :
36
+ """Raises ValueError if the provided name is not a valid metric name.
37
+
38
+ This check uses the global legacy validation setting to determine the validation scheme.
39
+ """
35
40
if not name :
36
41
raise ValueError ("metric name cannot be empty" )
37
42
global _legacy_validation
@@ -45,11 +50,15 @@ def _validate_metric_name(name: str) -> None:
45
50
46
51
47
52
def _is_valid_legacy_metric_name (name : str ) -> bool :
53
+ """Returns true if the provided metric name conforms to the legacy validation scheme."""
48
54
return METRIC_NAME_RE .match (name ) is not None
49
55
50
56
51
57
def _validate_metric_label_name_token (tok : str ) -> None :
52
- """Check validity of a parsed label name token. UTF-8 names must be quoted."""
58
+ """Raises ValueError if a parsed label name token is invalid.
59
+
60
+ UTF-8 names must be quoted.
61
+ """
53
62
if not tok :
54
63
raise ValueError ("invalid label name token " + tok )
55
64
global _legacy_validation
@@ -65,6 +74,10 @@ def _validate_metric_label_name_token(tok: str) -> None:
65
74
66
75
67
76
def _validate_labelname (l ):
77
+ """Raises ValueError if the provided name is not a valid label name.
78
+
79
+ This check uses the global legacy validation setting to determine the validation scheme.
80
+ """
68
81
if get_legacy_validation ():
69
82
if not METRIC_LABEL_NAME_RE .match (l ):
70
83
raise ValueError ('Invalid label metric name: ' + l )
@@ -80,12 +93,17 @@ def _validate_labelname(l):
80
93
81
94
82
95
def _is_valid_legacy_labelname (l : str ) -> bool :
96
+ """Returns true if the provided label name conforms to the legacy validation scheme."""
83
97
if METRIC_LABEL_NAME_RE .match (l ) is None :
84
98
return False
85
99
return RESERVED_METRIC_LABEL_NAME_RE .match (l ) is None
86
100
87
101
88
102
def _validate_labelnames (cls , labelnames ):
103
+ """Raises ValueError if any of the provided names is not a valid label name.
104
+
105
+ This check uses the global legacy validation setting to determine the validation scheme.
106
+ """
89
107
labelnames = tuple (labelnames )
90
108
for l in labelnames :
91
109
_validate_labelname (l )
@@ -95,6 +113,7 @@ def _validate_labelnames(cls, labelnames):
95
113
96
114
97
115
def _validate_exemplar (exemplar ):
116
+ """Raises ValueError if the exemplar is invalid."""
98
117
runes = 0
99
118
for k , v in exemplar .items ():
100
119
_validate_labelname (k )
0 commit comments