From 66928ce826090ca2f943659bf4efd2d1eae9c669 Mon Sep 17 00:00:00 2001 From: Jake Crouch Date: Tue, 9 Jul 2019 23:43:09 -0700 Subject: [PATCH] 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 --- eden/cli/stats.py | 2 +- eden/cli/test/stats_test.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/eden/cli/stats.py b/eden/cli/stats.py index 7baec4d02b..0fa24b413e 100644 --- a/eden/cli/stats.py +++ b/eden/cli/stats.py @@ -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] diff --git a/eden/cli/test/stats_test.py b/eden/cli/test/stats_test.py index 9a2fe194e7..daa13e3b1b 100644 --- a/eden/cli/test/stats_test.py +++ b/eden/cli/test/stats_test.py @@ -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])