Skip to content

Commit

Permalink
Retroactive reviews from #4481
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorguidi committed Dec 23, 2024
1 parent db280ad commit ffb37cc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 39 deletions.
44 changes: 9 additions & 35 deletions src/clusterfuzz/_internal/common/testcase_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,59 +31,33 @@


def emit_testcase_triage_duration_metric(testcase_id: int, step: str):
'''Finds out if a testcase is fuzzer generated or manually uploaded,
and emits the TESTCASE_UPLOAD_TRIAGE_DURATION metric.'''
testcase_upload_metadata = get_testcase_upload_metadata(testcase_id)
if not testcase_upload_metadata:
logs.warning(f'No upload metadata found for testcase {testcase_id},'
' failed to emit TESTCASE_UPLOAD_TRIAGE_DURATION metric.')
return
if not testcase_upload_metadata.timestamp:
logs.warning(
f'No timestamp for testcase {testcase_upload_metadata.testcase_id},'
' failed to emit TESTCASE_UPLOAD_TRIAGE_DURATION metric.')
return
assert step in [
'analyze_launched', 'analyze_completed', 'minimize_completed',
'regression_completed', 'impact_completed', 'issue_updated'
]

"""Finds out if a testcase is fuzzer generated or manually uploaded,
and emits the TESTCASE_TRIAGE_DURATION metric."""
testcase = data_handler.get_testcase_by_id(testcase_id)

if not testcase:
logs.warning(f'No testcase found with id {testcase_id},'
' failed to emit TESTCASE_UPLOAD_TRIAGE_DURATION metric.')
' failed to emit TESTCASE_TRIAGE_DURATION metric.')
return

if not testcase.job_type:
logs.warning(f'No job_type associated to testcase {testcase_id},'
' failed to emit TESTCASE_UPLOAD_TRIAGE_DURATION metric.')
' failed to emit TESTCASE_TRIAGE_DURATION metric.')
return

from_fuzzer = not get_testcase_upload_metadata(testcase_id)
testcase_age_in_hours = testcase.get_age_in_seconds() / (60*60)

assert step in [
'analyze_launched', 'analyze_completed', 'minimize_completed',
'regression_completed', 'impact_completed', 'issue_updated'
]

if not testcase.get_age_in_seconds():
logs.warning(f'No timestamp associated to testcase {testcase_id},'
' failed to emit TESTCASE_UPLOAD_TRIAGE_DURATION metric.')
return

testcase_age_in_hours = testcase.get_age_in_seconds() / 3600

logs.info('Emiting TESTCASE_UPLOAD_TRIAGE_DURATION metric for testcase '
logs.info('Emiting TESTCASE_TRIAGE_DURATION metric for testcase '
f'{testcase_id} (age = {testcase_age_in_hours} hours.) '
'in step {step}.')
f'in step {step}, from_fuzzer: {from_fuzzer}.')

monitoring_metrics.TESTCASE_UPLOAD_TRIAGE_DURATION.add(
monitoring_metrics.TESTCASE_TRIAGE_DURATION.add(
testcase_age_in_hours,
labels={
'job': testcase.job_type,
'step': step,
'origin': 'fuzzer' if from_fuzzer else 'manually_uploaded'
'from_fuzzer': from_fuzzer
})


Expand Down
2 changes: 0 additions & 2 deletions src/clusterfuzz/_internal/datastore/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,6 @@ def get_created_time(self) -> ndb.DateTimeProperty:

def get_age_in_seconds(self):
current_time = datetime.datetime.utcnow()
if not self.get_created_time():
return None
testcase_age = current_time - self.get_created_time()
return testcase_age.total_seconds()

Expand Down
4 changes: 2 additions & 2 deletions src/clusterfuzz/_internal/metrics/monitoring_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
],
)

TESTCASE_UPLOAD_TRIAGE_DURATION = monitor.CumulativeDistributionMetric(
TESTCASE_TRIAGE_DURATION = monitor.CumulativeDistributionMetric(
'uploaded_testcase_analysis/triage_duration_secs',
description=('Time elapsed between testcase upload and completion'
' of relevant tasks in the testcase upload lifecycle.'
Expand All @@ -241,7 +241,7 @@
field_spec=[
monitor.StringField('step'),
monitor.StringField('job'),
monitor.StringField('origin'),
monitor.BooleanField('from_fuzzer'),
],
)

Expand Down

0 comments on commit ffb37cc

Please sign in to comment.