Repository navigation
Add support to track the duration of fuzz task steps - #5555
brun0-matheus wants to merge 14 commits into
Conversation
ViniciustCosta
left a comment
There was a problem hiding this comment.
Let's do the bad_build_check metric in a separate PR and only add the time tracker structure and plumbing needed for the metrics in this one, so it's easier to review.
| except: | ||
| success = False | ||
| raise | ||
| finally: |
There was a problem hiding this comment.
Are there cases when the same step runs more than once (loops, retries)? Right now it warns and overwrites. Should durations be summed instead?
There was a problem hiding this comment.
Yes, there are. In this case I opted to make a tracker for each loop (as in PR #5569). Maybe summing it up is a simpler solution.
As a matter of fact, I opted for the first solution (make a tracker for each loop) in order to get the stats for TestcaseRun, but later on (PR #5571) I had to do the same for blackbox fuzzing, so now I don't think it's the best solution anymore.
There was a problem hiding this comment.
Done, now the time measurements are accumulated.
There was a problem hiding this comment.
Hmmm with this accumulation, stats holds the total per session, but the metric still gets one sample per call in Cloud Monitorign.
For steps inside loops, BQ (session total) and CM (per-iteration distribution) will mean different things. We could send the total once per step at the end.
In any case, please document it in the metric description.
There was a problem hiding this comment.
Ah, yes, that's intended, I forgot to add a comment explaining this. Sending the total once the steps end is a little bit difficult to do because of the following reasons:
1 - you need to define an extra method to mark the step as finished. This can add to confusion if you track the same step after you marked it as finished.
2 - you can't easily define success. If you had 5 steps, 4 were successful and 1 wasn't, what do you do?
Also, by sending the measurements in each step you gain granularity, so I don't see any problem in doing this.
There was a problem hiding this comment.
I updated the metric description to include this scenario.
There was a problem hiding this comment.
Makes sense to me! As we discussed offline, we might need to revisit that since some steps can loop over more than 100 iterations.
- Not sure if that's a problem, we can guarantee consistency in the code itself.
- Yeah, that's a good point, not sure the most correct approach here.
Done, now the bad build check PR is #5574. |
| 'name': 'steps_duration', | ||
| 'type': 'RECORD', | ||
| 'mode': 'NULLABLE', | ||
| 'fields': _STEPS_DURATION_FIELDS |
There was a problem hiding this comment.
Won't this break the JobRun load since STEPS_DURATION_FIELDS is empty for now?
Maybe we should leve the BQ schema field to be add it in the first real step.
There was a problem hiding this comment.
I will rerun the tests in the dev environment once we're done with reviewing, so let's see if this breaks.
| except: | ||
| success = False | ||
| raise | ||
| finally: |
There was a problem hiding this comment.
Hmmm with this accumulation, stats holds the total per session, but the metric still gets one sample per call in Cloud Monitorign.
For steps inside loops, BQ (session total) and CM (per-iteration distribution) will mean different things. We could send the total once per step at the end.
In any case, please document it in the metric description.
dc65638 to
167fbe0
Compare
Bug: b/577973994
Overview
Instruments the code to be able to easily emit metrics related to the duration of each fuzz_task step. The metrics are emitted both to Cloud Monitoring (using only a combination of fuzzer name and job, to keep the cardinality low) and Big Query.
Changes
TimeStatTracker, which is a reusable context manager that measures the time spent in its code context, saving it to a local dictionary (used to send the measurements toFuzzTaskOutputprotobuf later on) and emitting it to a supplied Cloud Monitoring metric.fuzz_task_steps_durationtoFuzzTaskOutputprotobuf, which is a map of string to interval duration, which allows to easily extend the code to support additional steps.has_fieldmethod in Metric, in order to make sure the metric supplied toTimeStatTrackerhas the correct fields.FUZZ_TASK_STEPS_DURATIONmetric in Cloud Monitoring. It contains the same labels asFUZZING_SESSION_DURATION, with the addition of thestepandsuccesslabels.fuzz_task_steps_durationfield in the JobRun schema (BigQuery), which contains the duration of all steps. Currently it only contains thebad_build_checkduration.load_bigquery_statstest. Now it uses the schema defined infuzzer_stats.py, avoiding duplicated code.Tests
Additional unit tests created. I ran tests in the dev environment with the bad_build check implemented.
Evidence that the CloudMonitoring metric is being tracked: https://screenshot.corp.google.com/2u8b1d3psrv68.
Evidence that the BigQuery metric is being tracked: https://screenshot-v2.corp.google.com/73759kq0eje1o.