-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use monitors for health check instead of custom script: (#22951)
- Updated `docker-compose.yml` to improve health checks for worker and web services, ensuring they are monitored effectively. - Introduced a new management command `monitors.py` to check the health of various services, including database and web. - Updated `Makefile-docker` to replace healthcheck with monitors - Updated `initialize.py` to ensure the database is running before proceeding with initialization. - Removed the obsolete `healthcheck.py` script in favor of the new monitoring approach. - Added tests for the new monitoring functionality to ensure reliability. TMP: better tests
- Loading branch information
Showing
14 changed files
with
377 additions
and
95 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
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
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 was deleted.
Oops, something went wrong.
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,60 @@ | ||
import time | ||
|
||
from django.core.management.base import CommandError | ||
|
||
import olympia.amo.monitors as monitors | ||
|
||
from .. import BaseDataCommand | ||
|
||
|
||
class Command(BaseDataCommand): | ||
help = 'Check a set of AMO service monitors.' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'--services', | ||
nargs='+', | ||
help='List of services to check', | ||
) | ||
parser.add_argument( | ||
'--attempts', | ||
type=int, | ||
default=5, | ||
help='Number of attempts to check the services', | ||
) | ||
|
||
def handle(self, *args, **options): | ||
attempts = options.get('attempts') | ||
services = options.get('services') | ||
|
||
self.logger.info(f'services: {services}') | ||
|
||
if not services: | ||
raise CommandError('No services specified') | ||
|
||
failing_services = services.copy() | ||
|
||
current = 0 | ||
|
||
while current < attempts: | ||
current += 1 | ||
self.logger.info(f'Checking services {services} for the {current} time') | ||
status_summary = monitors.execute_checks(services) | ||
failing_services = [ | ||
service | ||
for service, result in status_summary.items() | ||
if result['state'] is False | ||
] | ||
|
||
if len(failing_services) > 0: | ||
self.logger.error('Some services are failing: %s', failing_services) | ||
sleep_time = round(1.618**current) | ||
self.logger.info(f'Sleeping for {sleep_time} seconds') | ||
time.sleep(sleep_time) | ||
else: | ||
break | ||
|
||
if len(failing_services) > 0: | ||
raise CommandError(f'Some services are failing: {failing_services}') | ||
else: | ||
self.logger.info(f'All services are healthy {services}') |
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
Oops, something went wrong.