Commit b5863ff
authored
feat: Add client-side OS version filtering for Pub/Sub tasks (#5023)
## 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.
1. **Centralized Filtering Function:** A new private function,
`_filter_task_for_os_mismatch`, has been created in
`src/clusterfuzz/_internal/base/tasks/__init__.py`. This function
encapsulates all the logic for OS version validation.
2. **Behavior:**
- When a bot pulls a message, this function compares the
`base_os_version` attribute on the message with the bot's
`BASE_OS_VERSION` environment variable.
- If a mismatch is detected, the function logs a warning and immediately
**acknowledges (`ack()`)** the message.
- Acknowledging the message permanently removes it from that
subscription, effectively skipping it for the current bot. This assumes
the message was also correctly delivered to another, properly filtered
subscription for processing.
- If the OS versions match, or if either the bot or the message does not
have an OS version specified, the task is processed as usual.
3. **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
- **Resilience:** Bots are now resilient to misrouted messages and will
not fail on incompatible tasks.
- **Cleanliness:** The logic is centralized in a single, well-documented
function, improving code maintainability.
- **Forward-Compatibility:** This provides a safety net for future OS
migrations and ensures that legacy bots can coexist with newer ones
without issue.
### Testing
- Added comprehensive unit tests in
`src/clusterfuzz/_internal/tests/core/base/tasks/tasks_test.py` to
validate the filtering logic.
- Tests cover all scenarios:
- OS mismatch (message is skipped and acked).
- OS match (message is processed).
- Bot has an OS, but the message does not (message is processed).
- Message has an OS, but the bot does not (message is processed).
- All new and existing tests pass.1 parent f50c6ce commit b5863ff
File tree
2 files changed
+117
-28
lines changed- src/clusterfuzz/_internal
- base/tasks
- tests/core/base/tasks
2 files changed
+117
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
585 | 585 | | |
586 | 586 | | |
587 | 587 | | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
588 | 625 | | |
589 | 626 | | |
590 | 627 | | |
591 | 628 | | |
592 | 629 | | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
593 | 634 | | |
594 | 635 | | |
595 | 636 | | |
| |||
Lines changed: 76 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
258 | 277 | | |
259 | | - | |
| 278 | + | |
| 279 | + | |
260 | 280 | | |
261 | 281 | | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
268 | 285 | | |
269 | 286 | | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
276 | 291 | | |
277 | 292 | | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
283 | 296 | | |
284 | 297 | | |
285 | 298 | | |
286 | 299 | | |
287 | | - | |
| 300 | + | |
| 301 | + | |
288 | 302 | | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
293 | 308 | | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
298 | 345 | | |
299 | | - | |
| 346 | + | |
| 347 | + | |
300 | 348 | | |
301 | 349 | | |
302 | 350 | | |
| |||
0 commit comments