From 20af0728cf2574bae2a4b712944622cefad261bd Mon Sep 17 00:00:00 2001 From: Zen Date: Thu, 21 Nov 2024 16:38:53 -0600 Subject: [PATCH] ensure editing lables within metrics doesn't affect global labels Signed-off-by: Zen --- tests/test_exporter.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_exporter.py b/tests/test_exporter.py index ceb668d..8133c08 100644 --- a/tests/test_exporter.py +++ b/tests/test_exporter.py @@ -58,6 +58,18 @@ def test_global_labels_override(self): for metric in random_metrics: self.assertIn(f'{metric}{{global_label="global_value"}} 0', export) + def test_edited_metric_labels(self): + """Test that editing labels on an added metric do not affect global labels""" + test_labels = {"label1": "value1", "label2": "value2"} + e = Exporter(no_config_file=True, labels=test_labels) + random_metrics = generate_random_metric_config(10) + e.config["metrics"] = random_metrics + e.metrics = [] + e.export_config_metrics() # Generate metrics from the config + for metric in e.metrics: + self.assertEqual(metric.labels, test_labels) + metric.labels = {"asdf": str(uuid4())} + self.assertEqual(e.labels, test_labels) def test_append_metrics(self): """Ensures metrics can be appended after init"""