-
Notifications
You must be signed in to change notification settings - Fork 587
feat(tasks): Implement OS-based task routing logic #4995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hunsche
wants to merge
5
commits into
master
Choose a base branch
from
feat/pubsub-os-filtering
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
69bf81d
feat: Add OS-based routing logic for tasks
hunsche 58f491f
refactor(tests): Improve readability of task queue selection tests
hunsche 1fbd6c6
refactor: Use specific queue suffix generation
hunsche 79704ae
style: Apply yapf formatting
hunsche a99cbf2
refactor: Temporarily remove OS version ENV
hunsche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,9 +123,16 @@ def default_queue_suffix(): | |
logs.info(f'QUEUE_OVERRIDE is [{queue_override}]. ' | ||
f'Platform is {environment.platform()}') | ||
if queue_override: | ||
return queue_suffix_for_platform(queue_override) | ||
platform = queue_override | ||
else: | ||
platform = environment.platform() | ||
|
||
platform_suffix = queue_suffix_for_platform(platform) | ||
base_os_version = environment.get_value('BASE_OS_VERSION') | ||
if base_os_version and 'LINUX' in platform.upper(): | ||
platform_suffix = f'{platform_suffix}-{base_os_version}' | ||
|
||
return queue_suffix_for_platform(environment.platform()) | ||
return platform_suffix | ||
|
||
|
||
def regular_queue(prefix=JOBS_PREFIX): | ||
|
@@ -296,7 +303,13 @@ def get_postprocess_task(): | |
# wasting our precious non-linux bots on generic postprocess tasks. | ||
if not environment.platform().lower() == 'linux': | ||
return None | ||
pubsub_puller = PubSubPuller(POSTPROCESS_QUEUE) | ||
|
||
queue_name = POSTPROCESS_QUEUE | ||
base_os_version = environment.get_value('BASE_OS_VERSION') | ||
if base_os_version: | ||
queue_name = f'{queue_name}-{base_os_version}' | ||
|
||
pubsub_puller = PubSubPuller(queue_name) | ||
logs.info('Pulling from postprocess queue') | ||
messages = pubsub_puller.get_messages(max_messages=1) | ||
if not messages: | ||
|
@@ -312,7 +325,12 @@ def allow_all_tasks(): | |
|
||
|
||
def get_preprocess_task(): | ||
pubsub_puller = PubSubPuller(PREPROCESS_QUEUE) | ||
queue_name = PREPROCESS_QUEUE | ||
base_os_version = environment.get_value('BASE_OS_VERSION') | ||
if base_os_version: | ||
queue_name = f'{queue_name}-{base_os_version}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
|
||
pubsub_puller = PubSubPuller(queue_name) | ||
messages = pubsub_puller.get_messages(max_messages=1) | ||
if not messages: | ||
return None | ||
|
@@ -587,7 +605,12 @@ def get_task_from_message(message, queue=None, can_defer=True, | |
def get_utask_mains() -> List[PubSubTask]: | ||
"""Returns a list of tasks for preprocessing many utasks on this bot and then | ||
running the uworker_mains in the same batch job.""" | ||
pubsub_puller = PubSubPuller(UTASK_MAIN_QUEUE) | ||
queue_name = UTASK_MAIN_QUEUE | ||
base_os_version = environment.get_value('BASE_OS_VERSION') | ||
if base_os_version: | ||
queue_name = f'{queue_name}-{base_os_version}' | ||
|
||
pubsub_puller = PubSubPuller(queue_name) | ||
messages = pubsub_puller.get_messages_time_limited(MAX_UTASKS, | ||
UTASK_QUEUE_PULL_SECONDS) | ||
return handle_multiple_utask_main_messages(messages, UTASK_MAIN_QUEUE) | ||
|
@@ -758,6 +781,18 @@ def add_task(command, | |
if not job: | ||
raise Error(f'Job {job_type} not found.') | ||
|
||
# Determine base_os_version. | ||
base_os_version = job.base_os_version | ||
if job.is_external(): | ||
oss_fuzz_project = data_types.OssFuzzProject.get_by_id(job.project) | ||
if oss_fuzz_project and oss_fuzz_project.base_os_version: | ||
base_os_version = oss_fuzz_project.base_os_version | ||
|
||
if base_os_version: | ||
if extra_info is None: | ||
extra_info = {} | ||
extra_info['base_os_version'] = base_os_version | ||
|
||
if job.is_external(): | ||
external_tasks.add_external_task(command, argument, job) | ||
return | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be an static configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. In this case, the dynamic approach is needed so the bot can be aware of its own OS environment. The BASE_OS_VERSION is set at the infrastructure level (in the Docker image), allowing each worker to correctly identify which filtered queue it should pull from.