Skip to content

Commit d778250

Browse files
committed
Add dummy waffle switch to test healthcheck e2e in any environment
1 parent a3c51ae commit d778250

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Generated by Django 4.2.20 on 2025-03-19 12:40
2+
3+
from django.db import migrations
4+
5+
from olympia.core.db.migrations import CreateWaffleSwitch
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('amo', '0001_initial'),
12+
]
13+
14+
operations = [
15+
CreateWaffleSwitch('dummy-monitor-fails'),
16+
]

src/olympia/amo/monitors.py

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from django_statsd.clients import statsd
1313
from kombu import Connection
1414
from PIL import Image
15+
import waffle
1516

1617
import olympia.core.logger
1718
from olympia.amo.models import use_primary_db
@@ -33,6 +34,10 @@ def execute_checks(checks: list[str], verbose: bool = False):
3334
status_summary[check]['results'] = results
3435
return status_summary
3536

37+
def dummy_monitor():
38+
if waffle.switch_is_active('dummy-monitor-fails'):
39+
return 'Dummy monitor failed', None
40+
return '', None
3641

3742
def localdev_web():
3843
"""

src/olympia/amo/tests/test_views.py

+14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import pytest
1717
from lxml import etree
1818
from pyquery import PyQuery as pq
19+
from waffle.testutils import override_switch
1920

2021
from olympia import amo, core
2122
from olympia.access import acl
@@ -401,6 +402,19 @@ def test_front_heartbeat_failure(self):
401402
assert response.status_code >= 500
402403
assert response.json()['database']['status'] == 'boom'
403404

405+
def test_front_heartbeat_dummy_monitor_failure(self):
406+
url = reverse('amo.front_heartbeat')
407+
response = self.client.get(url)
408+
409+
assert response.status_code == 200
410+
assert response.json()['dummy_monitor']['state'] == True
411+
412+
with override_switch('dummy-monitor-fails', True):
413+
response = self.client.get(url)
414+
415+
assert response.status_code >= 500
416+
assert response.json()['dummy_monitor']['status'] == 'Dummy monitor failed'
417+
404418
def test_services_heartbeat_success(self):
405419
response = self.client.get(reverse('amo.services_heartbeat'))
406420
assert response.status_code == 200

src/olympia/amo/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def front_heartbeat(request):
4747
'elastic',
4848
'path',
4949
'database',
50+
'dummy_monitor',
5051
]
5152
)
5253

0 commit comments

Comments
 (0)