-
Notifications
You must be signed in to change notification settings - Fork 23
workers: add landing worker warning logs #383
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,11 @@ | |
| TreeClosed, | ||
| ) | ||
| from landoapi.models.configuration import ConfigurationKey | ||
| from landoapi.models.landing_job import LandingJob, LandingJobAction, LandingJobStatus | ||
| from landoapi.models.landing_job import ( | ||
| LandingJob, | ||
| LandingJobAction, | ||
| LandingJobStatus, | ||
| ) | ||
| from landoapi.notifications import ( | ||
| notify_user_of_bug_update_failure, | ||
| notify_user_of_landing_failure, | ||
|
|
@@ -71,6 +75,9 @@ def job_processing(worker: LandingWorker, job: LandingJob, db: SQLAlchemy): | |
|
|
||
|
|
||
| class LandingWorker(Worker): | ||
| TOO_MANY_ATTEMPTS_THRESHOLD = 10 | ||
| QUEUE_SIZE_THRESHOLD = 20 | ||
|
|
||
| @property | ||
| def STOP_KEY(self) -> ConfigurationKey: | ||
| """Return the configuration key that prevents the worker from starting.""" | ||
|
|
@@ -86,11 +93,32 @@ def __init__(self, *args, **kwargs): | |
| self.last_job_finished = None | ||
| self.refresh_enabled_repos() | ||
|
|
||
| def loop(self): | ||
| logger.debug( | ||
| f"{len(self.applicable_repos)} applicable repos: {self.applicable_repos}" | ||
| def check_landing_worker_warnings(self): | ||
| """Log messages that show various important statistics about the landing worker.""" | ||
|
|
||
| queue_size = LandingJob.query.filter( | ||
| LandingJob.status.in_(LandingJobStatus.ACTIVE_STATUSES) | ||
| ).count() | ||
| if queue_size >= self.QUEUE_SIZE_THRESHOLD: | ||
| logger.warning( | ||
| f"The landing queue size of {queue_size} exceeds threshold of " | ||
| f"{self.QUEUE_SIZE_THRESHOLD}." | ||
| ) | ||
|
|
||
| runaway_jobs = LandingJob.query.filter( | ||
| LandingJob.status.in_(LandingJobStatus.ACTIVE_STATUSES), | ||
| LandingJob.attempts >= self.TOO_MANY_ATTEMPTS_THRESHOLD, | ||
| ) | ||
|
|
||
| if runaway_jobs.count() > 0: | ||
| job = runaway_jobs.all()[0] | ||
| logger.warning( | ||
| f"Active landing job ({job}) has too many attempts ({job.attempts})" | ||
| ) | ||
|
Comment on lines
+113
to
+117
Member
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. Should we cancel the job in that case?
Contributor
Author
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. That would be a good idea, but I think it would be outside the scope of this PR since it would require us to also send a notification email. Maybe it can be done as a follow up. |
||
|
|
||
| def loop(self): | ||
| self.check_landing_worker_warnings() | ||
|
|
||
| # Check if any closed trees reopened since the beginning of this iteration | ||
| if len(self.enabled_repos) != len(self.applicable_repos): | ||
| self.refresh_enabled_repos() | ||
|
|
||
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.
Was removing this intentional?
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.
Yes, I am not sure if it is a useful thing to have in the logs constantly, since this is basically the repos in the environment variable, minus any trees that are closed. Perhaps it makes more sense to add it as a warning instead, if the two don't match?