Escapes the metric name and puts it in quotes iff the name does not conform to the legacy Prometheus character set.
(s: str, escaping: str = UNDERSCORES)
| 171 | |
| 172 | |
| 173 | def escape_metric_name(s: str, escaping: str = UNDERSCORES) -> str: |
| 174 | """Escapes the metric name and puts it in quotes iff the name does not |
| 175 | conform to the legacy Prometheus character set. |
| 176 | """ |
| 177 | if len(s) == 0: |
| 178 | return s |
| 179 | if escaping == ALLOWUTF8: |
| 180 | if not _is_valid_legacy_metric_name(s): |
| 181 | return '"{}"'.format(_escape(s, escaping, _is_legacy_metric_rune)) |
| 182 | return _escape(s, escaping, _is_legacy_metric_rune) |
| 183 | elif escaping == UNDERSCORES: |
| 184 | if _is_valid_legacy_metric_name(s): |
| 185 | return s |
| 186 | return _escape(s, escaping, _is_legacy_metric_rune) |
| 187 | elif escaping == DOTS: |
| 188 | return _escape(s, escaping, _is_legacy_metric_rune) |
| 189 | elif escaping == VALUES: |
| 190 | if _is_valid_legacy_metric_name(s): |
| 191 | return s |
| 192 | return _escape(s, escaping, _is_legacy_metric_rune) |
| 193 | return s |
| 194 | |
| 195 | |
| 196 | def escape_label_name(s: str, escaping: str = UNDERSCORES) -> str: |