@@ -146,6 +146,7 @@ def top(args):
146146 headers = [desc [0 ] for desc in cursor .description ]
147147 df = pd .DataFrame (cursor , columns = headers )
148148
149+ df ["impact" ] = df ["impact" ].apply (normalize_duration )
149150 df ["duration_p90" ] = df ["duration_p90" ].apply (normalize_duration )
150151
151152 # Find the CODEOWNERS for each test target:
@@ -171,13 +172,14 @@ def top(args):
171172 "left" , # label
172173 "decimal" , # total
173174 "decimal" , # non_success
174- "decimal" , # non_success%
175175 "decimal" , # flaky
176- "decimal" , # flaky%
177176 "decimal" , # timeout
178- "decimal" , # timeout%
179177 "decimal" , # fail
180- "decimal" , # fail%
178+ "decimal" , # non_success%
179+ "decimal" , # flaky%
180+ "decimal" , # timeout%
181+ "decimal" , # fail%
182+ "right" , # impact
181183 "right" , # duration_p90
182184 "left" , # owners
183185 ]
@@ -264,6 +266,11 @@ def direct_url_to_buildbuddy(url):
264266 print (tabulate (df [columns ], headers = "keys" , tablefmt = args .tablefmt , colalign = colalignments ))
265267
266268
269+ # argparse formatter to allow newlines in --help.
270+ class RawDefaultsFormatter (argparse .ArgumentDefaultsHelpFormatter , argparse .RawTextHelpFormatter ):
271+ pass
272+
273+
267274def main ():
268275 parser = argparse .ArgumentParser (prog = "bazel run //ci/githubstats:query --" )
269276
@@ -304,8 +311,19 @@ def main():
304311 top_parser = subparsers .add_parser (
305312 "top" ,
306313 parents = [common_parser , filter_parser ],
314+ formatter_class = RawDefaultsFormatter ,
307315 help = "Get the top non-successful / flaky / failed / timed-out tests in the last period" ,
308- formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
316+ epilog = """
317+ Examples:
318+ # Show the top 10 most flaky tests in the last week
319+ bazel run //ci/githubstats:query -- top 10 flaky% --week
320+
321+ # Show the top 5 tests on PRs where failures had the highest impact in the last week
322+ bazel run //ci/githubstats:query -- top 5 impact --prs --week
323+
324+ # Show the 100 slowest tests in the last month
325+ bazel run //ci/githubstats:query -- top 100 duration_p90 --month
326+ """ ,
309327 )
310328 top_parser .add_argument (
311329 "N" , type = int , nargs = "?" , default = 10 , help = "If specified, limits the number of tests to show"
@@ -317,16 +335,29 @@ def main():
317335 choices = [
318336 "total" ,
319337 "non_success" ,
320- "non_success%" ,
321338 "flaky" ,
322- "flaky%" ,
323339 "timeout" ,
324- "timeout%" ,
325340 "fail" ,
341+ "non_success%" ,
342+ "flaky%" ,
343+ "timeout%" ,
326344 "fail%" ,
345+ "impact" ,
327346 "duration_p90" ,
328347 ],
329- help = "COLUMN to order by and have the condition flags like --gt, --ge, etc. apply to" ,
348+ help = """COLUMN to order by and have the condition flags like --gt, --ge, etc. apply to.
349+
350+ total:\t \t Total runs in the specified period
351+ non_success:\t Number of non-successful runs in the specified period
352+ flaky:\t \t Number of flaky runs in the specified period
353+ timeout:\t Number of timed-out runs in the specified period
354+ fail:\t \t Number of failed runs in the specified period
355+ non_success%%:\t Percentage of non-successful runs in the specified period
356+ flaky%%:\t \t Percentage of flaky runs in the specified period
357+ timeout%%:\t Percentage of timed-out runs in the specified period
358+ fail%%:\t \t Percentage of failed runs in the specified period
359+ impact:\t \t non_success * duration_p90. A rough estimate on the impact of failures
360+ duration_p90:\t 90th percentile duration of all runs in the specified period""" ,
330361 )
331362
332363 condition_group = top_parser .add_mutually_exclusive_group ()
@@ -349,8 +380,13 @@ def main():
349380 last_runs_parser = subparsers .add_parser (
350381 "last" ,
351382 parents = [common_parser , filter_parser ],
383+ formatter_class = RawDefaultsFormatter ,
352384 help = "Get the last runs of the specified test in the given period" ,
353- formatter_class = argparse .ArgumentDefaultsHelpFormatter ,
385+ epilog = """
386+ Examples:
387+ # Show the last flaky runs of the rent_subnet_test in the last week
388+ bazel run //ci/githubstats:query -- last --flaky //rs/tests/nns:rent_subnet_test --week
389+ """ ,
354390 )
355391 last_runs_parser .add_argument ("--success" , action = "store_true" , help = "Include successful runs" )
356392 last_runs_parser .add_argument ("--flaky" , action = "store_true" , help = "Include flaky runs" )
0 commit comments