Skip to content

Commit 4fc67f6

Browse files
authored
feat: Only annotate failing heartbeat calls (#399)
This will reduce the amount of APM data sent (heartbeats make up a substantial portion of requests) and also include some additional details.
1 parent fadad02 commit 4fc67f6

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

openedx/core/djangoapps/heartbeat/runchecks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def runchecks(include_extended=False):
3535
'status': is_ok,
3636
'message': message
3737
}
38-
set_custom_attribute(f"heartbeat.status.{path}", is_ok)
38+
if not is_ok:
39+
set_custom_attribute(f"heartbeat.failure.{path}", message)
3940
except ImportError as e:
4041
raise ImproperlyConfigured(f'Error importing module {module}: "{e}"') # lint-amnesty, pylint: disable=raise-missing-from
4142
except AttributeError:

openedx/core/djangoapps/heartbeat/tests/test_heartbeat.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ def test_success(self, mock_set_attribute):
2929
response = self.client.get(self.heartbeat_url + '?extended')
3030

3131
assert response.status_code == 200
32-
# Spot-checking a success
33-
mock_set_attribute.assert_any_call(
34-
'heartbeat.status.openedx.core.djangoapps.heartbeat.default_checks.check_database', True
35-
)
32+
# We only annotate failing requests
33+
mock_set_attribute.assert_not_called()
3634

3735
def test_sql_fail(self):
3836
with patch('openedx.core.djangoapps.heartbeat.default_checks.connection') as mock_connection:
@@ -50,5 +48,5 @@ def test_modulestore_fail(self, mock_set_attribute):
5048
assert response.status_code == 503
5149
# Spot-checking a failure
5250
mock_set_attribute.assert_any_call(
53-
'heartbeat.status.openedx.core.djangoapps.heartbeat.default_checks.check_modulestore', False
51+
'heartbeat.failure.openedx.core.djangoapps.heartbeat.default_checks.check_modulestore', 'msg'
5452
)

0 commit comments

Comments
 (0)