Stats Prefix Check

Summary: Fix for issue where "eden stats hgimporter" raises a KeyError. Makes get_counter_table check that the prefix of the key matches before adding it to the table. Previously running get_counter_table(counters, ["hg_importer"], ["count"]) would try to find the non-existent key journal.fbsource.count.60 since its suffix matched "count" and it wasn't matching prefixes.

Reviewed By: strager

Differential Revision: D16167338

fbshipit-source-id: 68ba032463a41c12050874c0f9f08722c52c9d36
This commit is contained in:
Jake Crouch 2019-07-09 23:43:09 -07:00 committed by Facebook Github Bot
parent d22e987f67
commit 66928ce826
2 changed files with 3 additions and 1 deletions

View File

@ -501,7 +501,7 @@ def get_counter_table(counters: DiagInfoCounters, prefix: List, suffix: List) ->
for key in counters:
tags = key.split(".")
if tags[-len(suffix) :] == suffix:
if tags[-len(suffix) :] == suffix and tags[0 : len(prefix)] == prefix:
TIME_SUFFIXES = (".60", ".600", ".3600", "")
row_name = ".".join(tags[len(prefix) : -len(suffix)])
table[row_name] = [counters[key + suffix] for suffix in TIME_SUFFIXES]

View File

@ -118,6 +118,7 @@ class HgImporterStatsTest(unittest.TestCase):
"hg_importer.cat_file.count.3600": 9,
"hg_importer.cat_file.count.60": 1,
"hg_importer.cat_file.count.600": 7,
"journal.fbsource.count": 22,
}
table = get_counter_table(counters, ["hg_importer"], ["count"])
self.assertEqual(table.get("cat_file"), [1, 7, 9, 10])
@ -128,6 +129,7 @@ class HgImporterStatsTest(unittest.TestCase):
"hg_importer.dog_file.count.3600": 90,
"hg_importer.dog_file.count.60": 10,
"hg_importer.dog_file.count.600": 70,
"journal.fbsource.count": 33,
}
table = get_counter_table(counters, ["hg_importer"], ["count"])
self.assertEqual(table.get("dog_file"), [10, 70, 90, 100])