File tree 3 files changed +26
-0
lines changed
3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
23
23
- Prometheus exporters are now configured via ` init ` function (#89 )
24
24
- Updated examples to call ` init ` function (#94 )
25
25
- Updated ` docker compose ` / ` tilt ` config in repo to include grafana with our dashboards (#94 )
26
+ - ` Objective ` s will now emit a warning when name contains characters other than alphanumeric and dash (#99 )
26
27
27
28
### Deprecated
28
29
Original file line number Diff line number Diff line change
1
+ import logging
2
+
1
3
from enum import Enum
4
+ from re import match
2
5
from typing import Optional , Tuple
3
6
4
7
@@ -89,3 +92,9 @@ def __init__(
89
92
self .name = name
90
93
self .success_rate = success_rate
91
94
self .latency = latency
95
+
96
+ # Check that name only contains alphanumeric characters and hyphens
97
+ if match (r"^[\w-]+$" , name ) is None :
98
+ logging .getLogger ().warning (
99
+ f"Objective name '{ name } ' contains invalid characters. Only alphanumeric characters and hyphens are allowed."
100
+ )
Original file line number Diff line number Diff line change
1
+ import logging
2
+
3
+ from autometrics .objectives import Objective
4
+
5
+
6
+ def test_objective_name_warning (caplog ):
7
+ """Test that a warning is logged when an objective name contains invalid characters."""
8
+ caplog .set_level (logging .WARNING )
9
+ caplog .clear ()
10
+ Objective ("Incorrect name." )
11
+ assert len (caplog .records ) == 1
12
+ assert caplog .records [0 ].levelname == "WARNING"
13
+ assert "contains invalid characters" in caplog .records [0 ].message
14
+ caplog .clear ()
15
+ Objective ("correct-name-123" )
16
+ assert len (caplog .records ) == 0
You can’t perform that action at this time.
0 commit comments