Skip to content

Swarming: Adds CountTasks endpoint & Refactors swarming Prpc request#5277

Open
IvanBM18 wants to merge 13 commits into
masterfrom
feature/swarming/count_task_requests
Open

Swarming: Adds CountTasks endpoint & Refactors swarming Prpc request#5277
IvanBM18 wants to merge 13 commits into
masterfrom
feature/swarming/count_task_requests

Conversation

@IvanBM18
Copy link
Copy Markdown
Collaborator

@IvanBM18 IvanBM18 commented May 14, 2026

As part of the Swarming backpressure initiative, we needed to launch request to the prpc's swarming.v2.Task/CountTasks endpoint so we can calculate the amount of fuzz tasks needed to schedule, to achieve this i moved the prpc request logic to its own module so that we can reuse code and keep responsibilities in separate files.

Changes

  • Created a new api.py file in the swarming module.
    • Moved the request logic from __init__.py to api.py
    • Removed push_swarming_task from init.py
    • Updated service.py to use SwarmingAPI directly.
    • Created a new class SwarmingAPI to handle the prpc request logic such as token/auth logic, swarming config handling, and any other request logic
  • Created new unit tests for this api and Updated existing unit tests.

Tests

  • Created unit tests for the new api & endpoint
  • Scheduled swarming jobs to verify that the refactor didn't broke the existing swarming logic

@IvanBM18 IvanBM18 requested a review from a team as a code owner May 14, 2026 23:05
@IvanBM18 IvanBM18 changed the title feature/swarming/count task requests Swarming: Adds CountTasks endpoint & Refactors swarming Prpc request May 14, 2026
Copy link
Copy Markdown
Collaborator

@Xeicker Xeicker left a comment

Choose a reason for hiding this comment

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

For future PRs, when you move code and then add functionality it is a good practice to do each of those steps in separate commits for an easier review

Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated
Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated
Comment thread src/clusterfuzz/_internal/swarming/api.py
Comment thread src/clusterfuzz/_internal/swarming/api.py
Comment thread src/clusterfuzz/_internal/tests/core/swarming/swarming_test.py
@IvanBM18 IvanBM18 self-assigned this May 15, 2026
@IvanBM18 IvanBM18 added the swarming Changes related to the clusterfuzz-swarming integration label May 15, 2026
@IvanBM18 IvanBM18 force-pushed the feature/swarming/count_task_requests branch from d45af03 to 562ec1b Compare May 15, 2026 20:20
@IvanBM18 IvanBM18 force-pushed the feature/swarming/count_task_requests branch from 562ec1b to 57886fc Compare May 15, 2026 21:17
@IvanBM18 IvanBM18 requested a review from Xeicker May 15, 2026 21:41
Copy link
Copy Markdown
Collaborator

@Xeicker Xeicker left a comment

Choose a reason for hiding this comment

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

Other than some nits changes LGTM

Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated
Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated
Comment thread src/clusterfuzz/_internal/protos/swarming.proto
@IvanBM18 IvanBM18 marked this pull request as draft May 18, 2026 22:10
Comment thread src/clusterfuzz/_internal/protos/swarming.proto
Comment thread src/clusterfuzz/_internal/swarming/__init__.py Outdated
Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated
Comment thread src/clusterfuzz/_internal/swarming/service.py Outdated
Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated
Comment thread src/clusterfuzz/_internal/tests/core/swarming/api_test.py Outdated
Comment thread src/clusterfuzz/_internal/tests/core/swarming/api_test.py Outdated
Comment thread src/clusterfuzz/_internal/tests/core/swarming/api_test.py Outdated
Comment thread src/clusterfuzz/_internal/tests/core/swarming/service_test.py Outdated
Comment thread src/clusterfuzz/_internal/tests/core/swarming/swarming_test.py
IvanBM18 and others added 2 commits May 19, 2026 12:29
Co-authored-by: Titouan Rigoudy <titouan@chromium.org>
Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated

if not creds.token:
creds.refresh(requests.Request())
token = self._get_token()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

IIUC this means we'll make requests with no tokens if we fail to get a token, which is bound to fail? ISTM we should bail out and not make a request if we cannot get an auth token for it.

I would either expose to callers that SwarmingApi methods might raise either GoogleAuthError or RequestException, or wrap those in a new exception type here: SwarmingError and let the caller deal with that.

Edit: I see your comment on the test, that this will show up as 401 errors. I still find it a bit surprising to ask the system to do something we know will fail, but I must admit it works. I'll let @javanlacerda decide how he feels about it.

Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated
Comment thread src/clusterfuzz/_internal/swarming/service.py Outdated
Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated
body=message_body)

response = self._make_request(_COUNT_TASKS_ENDPOINT, message_body)
logs.info('[Swarming] Response from CountTasks', response=response)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would expect that debug-level logs are not logged in production, and only enabled if requested specifically somehow (environment variable?) during e.g. local testing. Anyway, thanks for considering it!

Comment thread src/clusterfuzz/_internal/swarming/service.py Outdated
Comment thread src/clusterfuzz/_internal/swarming/service.py Outdated
Comment thread src/clusterfuzz/_internal/tests/core/swarming/api_test.py Outdated
Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated
@IvanBM18 IvanBM18 marked this pull request as ready for review May 21, 2026 16:08
Copy link
Copy Markdown
Collaborator

@letitz letitz left a comment

Choose a reason for hiding this comment

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

LGTM % adding one last test. Outstanding comments are left for @javanlacerda's consideration :)

self.assertEqual(unscheduled, [])
self.mock_api.push_task.assert_not_called()

def test_create_utask_main_jobs_exception(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should have a test for what happens when the API raises an exception we can catch.

Comment thread src/clusterfuzz/_internal/swarming/api.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

swarming Changes related to the clusterfuzz-swarming integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants