Skip to content

Commit

Permalink
add tests for global exporter label overrrides
Browse files Browse the repository at this point in the history
Signed-off-by: Zen <[email protected]>
  • Loading branch information
desultory committed Nov 21, 2024
1 parent a1f69e7 commit 6b42201
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ def test_random_metrics(self):
for metric in random_metrics:
self.assertIn(f"{metric} 0", export1)

def test_global_labels(self):
"""Ensures that lables which are defined globally are applied to all metrics"""
e = Exporter(labels={"global_label": "global_value"}, no_config_file=True)
random_metrics = generate_random_metric_config(10)
e.config["metrics"] = random_metrics
export = run(e.export())
for metric in random_metrics:
self.assertIn(f'{metric}{{global_label="global_value"}} 0', export)

def test_global_labels_override(self):
"""Ensures that global labels defined in a metric's config override the global labels"""
e = Exporter(labels={"global_label": "global_value"}, no_config_file=True)
random_metrics = generate_random_metric_config(10)
e.config["metrics"] = {
**random_metrics,
"test_metric": {"type": "counter", "help": "test", "labels": {"global_label": "local_value"}},
}
export = run(e.export())
self.assertIn('test_metric{global_label="local_value"} 0', export)
for metric in random_metrics:
self.assertIn(f'{metric}{{global_label="global_value"}} 0', export)


def test_append_metrics(self):
"""Ensures metrics can be appended after init"""
e = Exporter(no_config_file=True)
Expand Down

0 comments on commit 6b42201

Please sign in to comment.