-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Robustness improvements to datadog_diagnostics plugin (#723)
- Add `DATADOG_DIAGNOSTICS_ENABLE` for quick disable if needed - Limit spans with `DATADOG_DIAGNOSTICS_MAX_SPANS` (default 100) - Fix scope of member variables - Add unit tests Manual testing: - Modify `common.djangoapps.student.views.dashboard.student_dashboard` in edx-platform to call `import time; time.sleep(10)` at the start of the view. - Start server and log - Visit /dashboard - While the browser is waiting, quickly make a small edit to an edx-platform file, causing an autoreload. - Confirm that spans are logged.
- Loading branch information
Showing
5 changed files
with
92 additions
and
6 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
Empty file.
51 changes: 51 additions & 0 deletions
51
edx_arch_experiments/datadog_diagnostics/tests/test_app.py
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,51 @@ | ||
""" | ||
Tests for plugin app. | ||
""" | ||
|
||
from unittest.mock import patch | ||
|
||
from django.test import TestCase | ||
|
||
from .. import apps | ||
|
||
|
||
class FakeSpan: | ||
"""A fake Span instance that just carries a span_id.""" | ||
def __init__(self, span_id): | ||
self.span_id = span_id | ||
|
||
def _pprint(self): | ||
return f"span_id={self.span_id}" | ||
|
||
|
||
class TestMissingSpanProcessor(TestCase): | ||
"""Tests for MissingSpanProcessor.""" | ||
|
||
@patch.object(apps, 'DATADOG_DIAGNOSTICS_MAX_SPANS', new=3) | ||
def test_metrics(self): | ||
proc = apps.MissingSpanProcessor() | ||
ids = [2, 4, 6, 8, 10] | ||
|
||
for span_id in ids: | ||
proc.on_span_start(FakeSpan(span_id)) | ||
|
||
assert {(sk, sv.span_id) for sk, sv in proc.open_spans.items()} == {(2, 2), (4, 4), (6, 6)} | ||
assert proc.spans_started == 5 | ||
assert proc.spans_finished == 0 | ||
|
||
for span_id in ids: | ||
proc.on_span_finish(FakeSpan(span_id)) | ||
|
||
assert proc.open_spans.keys() == set() | ||
assert proc.spans_started == 5 | ||
assert proc.spans_finished == 5 | ||
|
||
@patch('edx_arch_experiments.datadog_diagnostics.apps.log.info') | ||
@patch('edx_arch_experiments.datadog_diagnostics.apps.log.error') | ||
def test_logging(self, mock_log_error, mock_log_info): | ||
proc = apps.MissingSpanProcessor() | ||
proc.on_span_start(FakeSpan(17)) | ||
proc.shutdown(0) | ||
|
||
mock_log_info.assert_called_once_with("Spans created = 1; spans finished = 0") | ||
mock_log_error.assert_called_once_with("Span created but not finished: span_id=17") |