-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PTFE-1738 introducing job that will warn about leaks (#606)
- Loading branch information
Showing
5 changed files
with
99 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
|
||
from redis_om import NotFoundError | ||
|
||
from runner_manager import RunnerGroup | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def runner_leaks(pk: str) -> bool: | ||
""" | ||
Job that will look for leaks in the runner group | ||
and for now it will just log the runner's name that | ||
could be considered as a leak. | ||
returns: | ||
bool: True if a leak was found, False otherwise | ||
""" | ||
|
||
try: | ||
group: RunnerGroup = RunnerGroup.get(pk) | ||
except NotFoundError: | ||
log.error(f"Runner group {pk} not found") | ||
return False | ||
backend_runners = group.backend.list() | ||
group_runners = group.get_runners() | ||
if len(backend_runners) > len(group_runners): | ||
log.warning(f"Runner group {pk} has leaks") | ||
for runner in backend_runners: | ||
if runner not in group_runners: | ||
log.warning(f"Runner {runner} could be considered as a leak") | ||
return True | ||
else: | ||
return False |
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from rq import Queue | ||
|
||
from runner_manager import RunnerGroup | ||
from runner_manager.clients.github import GitHub | ||
from runner_manager.jobs.leaks import runner_leaks | ||
from runner_manager.models.runner import Runner, RunnerStatus | ||
|
||
|
||
def test_leak_job(runner_group: RunnerGroup, queue: Queue, github: GitHub, monkeypatch): | ||
runner_group.save() | ||
runner = runner_group.create_runner(github) | ||
assert runner in runner_group.get_runners() | ||
runner.status = RunnerStatus.online | ||
runner.busy = True | ||
runner.save() | ||
job = queue.enqueue( | ||
runner_leaks, | ||
runner_group.pk, | ||
) | ||
# No leaks were found | ||
assert job.return_value() is False | ||
fake_runner: Runner = Runner( | ||
name="fake_runner", | ||
instance_id="fake_instance_id", | ||
busy=False, | ||
status=RunnerStatus.offline, | ||
runner_group_id=runner_group.id, | ||
) | ||
monkeypatch.setattr( | ||
"runner_manager.backend.base.BaseBackend.list", | ||
lambda self: [runner, fake_runner], | ||
) | ||
job = queue.enqueue( | ||
runner_leaks, | ||
runner_group.pk, | ||
) | ||
# fake_runner is a leak since it is not in the group | ||
assert job.return_value() is True | ||
|
||
|
||
def test_leak_job_group_not_found(queue: Queue, github: GitHub): | ||
job = queue.enqueue( | ||
runner_leaks, | ||
"fake_id", | ||
) | ||
assert job.return_value() is False |
This file contains 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