Raises ValueError if the provided name is not a valid label name. This check uses the global legacy validation setting to determine the validation scheme.
(l)
| 73 | |
| 74 | |
| 75 | def _validate_labelname(l): |
| 76 | """Raises ValueError if the provided name is not a valid label name. |
| 77 | |
| 78 | This check uses the global legacy validation setting to determine the validation scheme. |
| 79 | """ |
| 80 | if get_legacy_validation(): |
| 81 | if not METRIC_LABEL_NAME_RE.match(l): |
| 82 | raise ValueError('Invalid label metric name: ' + l) |
| 83 | if RESERVED_METRIC_LABEL_NAME_RE.match(l): |
| 84 | raise ValueError('Reserved label metric name: ' + l) |
| 85 | else: |
| 86 | try: |
| 87 | l.encode('utf-8') |
| 88 | except UnicodeDecodeError: |
| 89 | raise ValueError('Invalid label metric name: ' + l) |
| 90 | if RESERVED_METRIC_LABEL_NAME_RE.match(l): |
| 91 | raise ValueError('Reserved label metric name: ' + l) |
| 92 | |
| 93 | |
| 94 | def _is_valid_legacy_labelname(l: str) -> bool: |
no test coverage detected