@@ -309,22 +309,11 @@ def _file_issue(testcase, issue_tracker, throttler):
309309 return filed
310310
311311
312- untriaged_testcase_count = {}
313-
314-
315- def _increment_untriaged_testcase_count (testcase : data_types .Testcase ):
316- identifier = (testcase .job_type , testcase .platform )
317- if identifier not in untriaged_testcase_count :
318- untriaged_testcase_count [identifier ] = 0
319- untriaged_testcase_count [identifier ] += 1
320-
321-
322312def _emit_untriaged_testcase_age_metric (testcase : data_types .Testcase ):
323313 """Emmits a metric to track age of untriaged testcases."""
324314 if not testcase .timestamp :
325315 return
326316
327- _increment_untriaged_testcase_count (testcase )
328317 logs .info (f'Emiting UNTRIAGED_TESTCASE_AGE for testcase { testcase .key .id ()} '
329318 f'(age = { testcase .get_age_in_seconds ()} )' )
330319 monitoring_metrics .UNTRIAGED_TESTCASE_AGE .add (
@@ -335,16 +324,6 @@ def _emit_untriaged_testcase_age_metric(testcase: data_types.Testcase):
335324 })
336325
337326
338- def _emit_untriaged_testcase_count_metric ():
339- for (job , platform ) in untriaged_testcase_count :
340- monitoring_metrics .UNTRIAGED_TESTCASE_COUNT .set (
341- untriaged_testcase_count [(job , platform )],
342- labels = {
343- 'job' : job ,
344- 'platform' : platform ,
345- })
346-
347-
348327def main ():
349328 """Files bugs."""
350329 try :
@@ -367,6 +346,8 @@ def main():
367346
368347 throttler = Throttler ()
369348
349+ untriaged_testcases = 0
350+
370351 for testcase_id in data_handler .get_open_testcase_id_iterator ():
371352 logs .info (f'Triaging { testcase_id } ' )
372353 try :
@@ -395,6 +376,7 @@ def main():
395376 if testcase .get_metadata ('progression_pending' ):
396377 logs .info (f'Skipping testcase { testcase_id } , progression pending' )
397378 _emit_untriaged_testcase_age_metric (testcase )
379+ untriaged_testcases += 1
398380 continue
399381
400382 # If the testcase has a bug filed already, no triage is needed.
@@ -414,6 +396,7 @@ def main():
414396 # finished.
415397 if not critical_tasks_completed :
416398 _emit_untriaged_testcase_age_metric (testcase )
399+ untriaged_testcases += 1
417400 logs .info (
418401 f'Skipping testcase { testcase_id } , critical tasks still pending.' )
419402 continue
@@ -431,12 +414,14 @@ def main():
431414 if not testcase .group_id and not dates .time_has_expired (
432415 testcase .timestamp , hours = data_types .MIN_ELAPSED_TIME_SINCE_REPORT ):
433416 _emit_untriaged_testcase_age_metric (testcase )
417+ untriaged_testcases += 1
434418 logs .info (f'Skipping testcase { testcase_id } , pending grouping.' )
435419 continue
436420
437421 if not testcase .get_metadata ('ran_grouper' ):
438422 # Testcase should be considered by the grouper first before filing.
439423 _emit_untriaged_testcase_age_metric (testcase )
424+ untriaged_testcases += 1
440425 logs .info (f'Skipping testcase { testcase_id } , pending grouping.' )
441426 continue
442427
@@ -463,10 +448,13 @@ def main():
463448 # Clean up old triage messages that would be not applicable now.
464449 testcase .delete_metadata (TRIAGE_MESSAGE_KEY , update_testcase = False )
465450
451+ # A testcase is untriaged, until immediately before a bug is opened
452+ _emit_untriaged_testcase_age_metric (testcase )
453+ untriaged_testcases += 1
454+
466455 # File the bug first and then create filed bug metadata.
467456 if not _file_issue (testcase , issue_tracker , throttler ):
468457 logs .info (f'Issue filing failed for testcase id { testcase_id } ' )
469- _emit_untriaged_testcase_age_metric (testcase )
470458 continue
471459
472460 _create_filed_bug_metadata (testcase )
@@ -475,7 +463,8 @@ def main():
475463 logs .info ('Filed new issue %s for testcase %d.' % (testcase .bug_information ,
476464 testcase_id ))
477465
478- _emit_untriaged_testcase_count_metric ()
466+ monitoring_metrics .UNTRIAGED_TESTCASE_COUNT .set (
467+ untriaged_testcases , labels = {})
479468
480469 logs .info ('Triage testcases succeeded.' )
481470 return True
0 commit comments