Skip to content

Add static server healtcheck ping #23178

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ services:
- ./:/data/olympia
- ./deps:/data/olympia/deps
command: make run_vite
healthcheck:
test: ["CMD-SHELL", "./manage.py monitors --services localdev_static --skip-checks"]
interval: 30s
retries: 3
start_interval: 1s

worker:
<<: *olympia
Expand Down
8 changes: 7 additions & 1 deletion src/olympia/amo/management/commands/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ def handle(self, *args, **options):
# Ensure any additional required dependencies are available before proceeding.
call_command(
'monitors',
services=['localdev_web', 'celery_worker', 'rabbitmq', 'signer'],
services=[
'localdev_web',
'localdev_static',
'celery_worker',
'rabbitmq',
'signer',
],
attempts=10,
)

Expand Down
20 changes: 20 additions & 0 deletions src/olympia/amo/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ def execute_checks(checks: list[str], verbose: bool = False):
return status_summary


def localdev_static():
"""
Used in local development environments to determine if the
local dev server is running and responding to requests.
"""
status = ''
try:
base_url = 'http://nginx'
url = urljoin(base_url, '/static/bundle/ping.txt')
response = requests.get(url)
response.raise_for_status()

if response.headers.get('X-Served-By') != 'vite':
raise ValueError('File not served by vite')
except Exception as e:
status = f'Failed to ping local dev server: {e}'
monitor_log.critical(status)
return status, None


def localdev_web():
"""
Used in local development environments to determine if the web container
Expand Down
8 changes: 7 additions & 1 deletion src/olympia/amo/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ class Commands:
monitors_database = mock.call('monitors', services=['database'])
monitors = mock.call(
'monitors',
services=['localdev_web', 'celery_worker', 'rabbitmq', 'signer'],
services=[
'localdev_web',
'localdev_static',
'celery_worker',
'rabbitmq',
'signer',
],
attempts=10,
)
migrate = mock.call('migrate', '--noinput')
Expand Down
1 change: 1 addition & 0 deletions static/ping.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
Loading