Swarming: Adds CountTasks endpoint & Refactors swarming Prpc request#5277
Swarming: Adds CountTasks endpoint & Refactors swarming Prpc request#5277IvanBM18 wants to merge 13 commits into
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 :)
| self.assertEqual(unscheduled, []) | ||
| self.mock_api.push_task.assert_not_called() | ||
|
|
||
| def test_create_utask_main_jobs_exception(self): |
There was a problem hiding this comment.
We should have a test for what happens when the API raises an exception we can catch.
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