Skip to content

Commit 6b42201

Browse files
committed
add tests for global exporter label overrrides
Signed-off-by: Zen <[email protected]>
1 parent a1f69e7 commit 6b42201

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_exporter.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ def test_random_metrics(self):
3636
for metric in random_metrics:
3737
self.assertIn(f"{metric} 0", export1)
3838

39+
def test_global_labels(self):
40+
"""Ensures that lables which are defined globally are applied to all metrics"""
41+
e = Exporter(labels={"global_label": "global_value"}, no_config_file=True)
42+
random_metrics = generate_random_metric_config(10)
43+
e.config["metrics"] = random_metrics
44+
export = run(e.export())
45+
for metric in random_metrics:
46+
self.assertIn(f'{metric}{{global_label="global_value"}} 0', export)
47+
48+
def test_global_labels_override(self):
49+
"""Ensures that global labels defined in a metric's config override the global labels"""
50+
e = Exporter(labels={"global_label": "global_value"}, no_config_file=True)
51+
random_metrics = generate_random_metric_config(10)
52+
e.config["metrics"] = {
53+
**random_metrics,
54+
"test_metric": {"type": "counter", "help": "test", "labels": {"global_label": "local_value"}},
55+
}
56+
export = run(e.export())
57+
self.assertIn('test_metric{global_label="local_value"} 0', export)
58+
for metric in random_metrics:
59+
self.assertIn(f'{metric}{{global_label="global_value"}} 0', export)
60+
61+
3962
def test_append_metrics(self):
4063
"""Ensures metrics can be appended after init"""
4164
e = Exporter(no_config_file=True)

0 commit comments

Comments
 (0)