Skip to content

[Tracing] Instrument code to emit Task Execution events#4860

Merged
ViniciustCosta merged 20 commits into
masterfrom
feat/add_utask_events
Jul 10, 2025
Merged

[Tracing] Instrument code to emit Task Execution events#4860
ViniciustCosta merged 20 commits into
masterfrom
feat/add_utask_events

Conversation

@ViniciustCosta

@ViniciustCosta ViniciustCosta commented Jul 4, 2025

Copy link
Copy Markdown
Collaborator

Description

This PR instruments the code to emit TaskExecutionEvents (defined at #4857) during utasks execution (events for trusted tasks will be added in a next PR).

The implementation leverages the _MetricRecorder from utasks module, since it already wraps the execution of all task stages while also storing important metadata from the task. This enables us sending events with context for each stage, even if unhandled exceptions happen during runtime.

Events are emitted in the following cases:

  • After Preprocess executed:
    • If an exception occurs: Event: {TaskStatus=Exception, Outcome=Unhandled exception}
    • If uworker input is NOT returned: Event: {TaskStatus=Exception, Outcome=No preprocess return}
    • Else preprocess is successful: Event: {TaskStatus=Started, Outcome=None}
  • At the start of Postprocess:
    • States that main executed: Event: {TaskStatus=Postprocess Started, Outcome=<uworker_output.error_type>}
  • After Postprocess executed:
    • If an exception occurs: Event: {TaskStatus=Exception, Outcome=Unhandled exception}
    • Else postprocess finishes successfully: Event: {TaskStatus=Postprocess Completed, Outcome=<uworker_output.error_type>}

Notice that a known limitation is that we do not send events from utask main, since we currently don't have a workaround to access datastore from untrusted workers.

b/394059581

Tests

Unit tests were added to verify all the instrumented codepaths and check the correctness of the events being emitted.

Runtime tests were done by deploying to dev environment.

  • Task execution events created:
image

@ViniciustCosta ViniciustCosta changed the title [WIP][Tracing] Instrument code to emit Task Execution events [Tracing] Instrument code to emit Task Execution events Jul 7, 2025
Comment thread src/clusterfuzz/_internal/bot/tasks/utasks/__init__.py Outdated
Comment thread src/clusterfuzz/_internal/bot/tasks/utasks/__init__.py
Comment thread src/clusterfuzz/_internal/bot/tasks/utasks/__init__.py Outdated
"""Task status."""
STARTED = 'started'
FINISHED = 'finished'
MAIN_FINISHED = 'main_finished'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this being used?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I merged this before seeing this comment. It is not being used, I'll remove in a further PR

@ViniciustCosta ViniciustCosta merged commit b09508f into master Jul 10, 2025
7 checks passed
@ViniciustCosta ViniciustCosta deleted the feat/add_utask_events branch July 10, 2025 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants