feat: Add client-side OS version filtering for Pub/Sub tasks #5023
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a client-side filtering mechanism to make ClusterFuzz bots more resilient to misrouted Pub/Sub messages. It ensures that bots only process tasks intended for their specific operating system version, preventing errors and wasted resources when tasks are sent to legacy, unfiltered subscriptions.
The Problem
When introducing new OS versions, such as Ubuntu 24.04, we create new, filtered Pub/Sub subscriptions (e.g.,
my-queue-ubuntu-24-04). However, existing bots subscribed to legacy, unfiltered queues (e.g.,my-queue) could still pull messages intended for the new OS. Since Pub/Sub subscription filters are immutable, we cannot simply update old subscriptions. This can lead to bots attempting to execute incompatible tasks, causing errors and inefficiencies.The Solution
This change implements a robust, centralized check within the task-pulling logic.
Centralized Filtering Function: A new private function,
_filter_task_for_os_mismatch, has been created insrc/clusterfuzz/_internal/base/tasks/__init__.py. This function encapsulates all the logic for OS version validation.Behavior:
base_os_versionattribute on the message with the bot'sBASE_OS_VERSIONenvironment variable.ack()) the message.Integration: This check is performed within
get_task_from_message, ensuring it is applied to all types of tasks pulled from Pub/Sub (regular,preprocess,postprocess, etc.) without code duplication.Benefits
Testing
src/clusterfuzz/_internal/tests/core/base/tasks/tasks_test.pyto validate the filtering logic.