@@ -36,6 +36,30 @@ def test_random_metrics(self):
3636 for metric in random_metrics :
3737 self .assertIn (f"{ metric } 0" , export1 )
3838
39+ def test_append_metrics (self ):
40+ """Ensures metrics can be appended after init"""
41+ e = Exporter (no_config_file = True )
42+ random_metrics_a = generate_random_metric_config (10 )
43+ random_metrics_b = generate_random_metric_config (10 )
44+ all_metrics = {** random_metrics_a , ** random_metrics_b }
45+ e .config ["metrics" ] = random_metrics_a
46+ export1 = run (e .export ())
47+ e .config ["metrics" ].update (random_metrics_b )
48+ export2 = run (e .export ())
49+ self .assertNotEqual (export1 , export2 )
50+ for metric in all_metrics :
51+ self .assertIn (f"{ metric } 0" , export2 )
52+
53+ def test_metric_filter (self ):
54+ """Ensure metrics can be filtered by label"""
55+ e = Exporter (config_file = "tests/test_config.toml" )
56+ label_filter = {"label1" : "value1" }
57+ export = run (e .export (label_filter = label_filter ))
58+ self .assertEqual (
59+ export ,
60+ '# TYPE test_metric_with_labels untyped\n test_metric_with_labels{label1="value1",label2="value2"} 300\n ' ,
61+ )
62+
3963
4064@loggify
4165class TestExporterAsync (AioHTTPTestCase ):
@@ -55,7 +79,7 @@ async def test_exporter(self):
5579 self .assertEqual (text , expected_response )
5680
5781 async def test_filter (self ):
58- """Test the exporter server by sending a request to the /metrics endpoint"""
82+ """Test the exporter webserver filter by sending a request with args to the /metrics endpoint"""
5983 expected_response = await self .exporter .export (label_filter = {"label1" : "value1" })
6084 async with self .client .get ("/metrics?label1=value1" ) as response :
6185 self .assertEqual (response .status , 200 )
0 commit comments