Swarming: Adds CountTasks endpoint & Refactors swarming Prpc request#5277
Conversation
Xeicker
left a comment
There was a problem hiding this comment.
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
d45af03 to
562ec1b
Compare
562ec1b to
57886fc
Compare
Xeicker
left a comment
There was a problem hiding this comment.
Other than some nits changes LGTM
Co-authored-by: Titouan Rigoudy <titouan@chromium.org>
|
|
||
| if not creds.token: | ||
| creds.refresh(requests.Request()) | ||
| token = self._get_token() |
There was a problem hiding this comment.
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.
| body=message_body) | ||
|
|
||
| response = self._make_request(_COUNT_TASKS_ENDPOINT, message_body) | ||
| logs.info('[Swarming] Response from CountTasks', response=response) |
There was a problem hiding this comment.
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!
letitz
left a comment
There was a problem hiding this comment.
LGTM % adding one last test. Outstanding comments are left for @javanlacerda's consideration :)
## Overview `SwarmingService` and other remote task services will now be instantiated in `RemoteTaskGate` based on the their feature flag. Now the `SwarmingService` will crash horribly at startup, this is done to avoid happing an api instances that does nothing, and a swarming service that just fails when called, with this new logic we make sure that all parts work as expected and if they dont.... well we just wont be able to fully schedule on envs where swarming is enabled. ### Background This PR comes from a discussion & agreement to a required change from [this review](#5277 (comment)) ## Changes - Raises an exception at `SwarmingService` constructor if the swarming config was not found - Updated `RemoteTaskGate` to conditionally instantiate services based on the linked feature flag. - This safeguards envs where the swarming feature flag is not enabled. - Added unit tests & updated a lot of them for the remote task gate changes.
As part of the Swarming backpressure initiative, we needed to launch request to the prpc's
swarming.v2.Task/CountTasksendpoint 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
api.pyfile in the swarming module.__init__.pytoapi.pyinit.pyservice.pyto useSwarmingAPIdirectly.SwarmingAPIto handle the prpc request logic such as token/auth logic, swarming config handling, and any other request logicTests