@@ -279,13 +279,17 @@ def assert_stats_results(self, results):
279279 results ["partitioned_yesterday" ]["max_partition_delta" ].days , 2
280280 )
281281
282- def assert_stats_prometheus_outfile (self , prom_file ):
282+ def parse_prometheus_outfile (self , prom_file ):
283283 lines = prom_file .split ("\n " )
284284 metrics = {}
285285 for line in lines :
286286 if not line .startswith ("#" ) and len (line ) > 0 :
287287 key , value = line .split (" " )
288288 metrics [key ] = value
289+ return metrics
290+
291+ def assert_stats_prometheus_outfile (self , prom_file ):
292+ metrics = self .parse_prometheus_outfile (prom_file )
289293
290294 for table in ["partitioned_last_week" , "partitioned_yesterday" , "other" ]:
291295 self .assertIn (f'partition_total{{table="{ table } "}}' , metrics )
@@ -303,7 +307,7 @@ def assert_stats_prometheus_outfile(self, prom_file):
303307 def test_stats_cli_flag (self ):
304308 args = PARSER .parse_args (["--mariadb" , str (fake_exec ), "stats" ])
305309 results = stats_cmd (args )
306- self . assert_stats_results ( results )
310+ assert results == {}
307311
308312 def test_stats_yaml (self ):
309313 with tempfile .NamedTemporaryFile (
@@ -314,7 +318,9 @@ def test_stats_yaml(self):
314318 mariadb: { str (fake_exec )}
315319 prometheus_stats: { stats_outfile .name }
316320 tables:
317- unused:
321+ other:
322+ partitioned_last_week:
323+ partitioned_yesterday:
318324 """
319325 insert_into_file (tmpfile , yaml )
320326 args = PARSER .parse_args (["--config" , tmpfile .name , "stats" ])
@@ -324,6 +330,36 @@ def test_stats_yaml(self):
324330 self .assert_stats_results (results )
325331 self .assert_stats_prometheus_outfile (stats_outfile .read ())
326332
333+ def test_stats_yaml_ignore_unconfigured_tables (self ):
334+ with tempfile .NamedTemporaryFile (
335+ mode = "w+" , encoding = "UTF-8"
336+ ) as stats_outfile , tempfile .NamedTemporaryFile () as tmpfile :
337+ yaml = f"""
338+ partitionmanager:
339+ mariadb: { str (fake_exec )}
340+ prometheus_stats: { stats_outfile .name }
341+ tables:
342+ other:
343+ """
344+ insert_into_file (tmpfile , yaml )
345+ args = PARSER .parse_args (["--config" , tmpfile .name , "stats" ])
346+
347+ results = stats_cmd (args )
348+
349+ assert list (results .keys ()) == ["other" ]
350+
351+ out_data = stats_outfile .read ()
352+
353+ metrics = self .parse_prometheus_outfile (out_data )
354+ assert list (metrics .keys ()) == [
355+ 'partition_total{table="other"}' ,
356+ 'partition_time_remaining_until_partition_overrun{table="other"}' ,
357+ 'partition_age_of_retained_partitions{table="other"}' ,
358+ 'partition_mean_delta_seconds{table="other"}' ,
359+ 'partition_max_delta_seconds{table="other"}' ,
360+ "partition_last_run_timestamp{}" ,
361+ ]
362+
327363
328364class TestConfig (unittest .TestCase ):
329365 def test_cli_tables_override_yaml (self ):
0 commit comments