-
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: Enable ConfigWatcher in CMS; prefix Slack messages with IDA name (
#537) Introduces `CONFIG_WATCHER_SERVER_NAME` to support messaging from multiple services. Also: - Add a README for the plugin. - Add start of unit tests in ConfigWatcher - Soft-import waffle The new unit tests were failing because waffle isn't actually a declared dependency, so we switch to `import_string`. This also moves us closer to being able to configure the plugin app entirely using Django settings (rather than a hardcoded model dict).
- Loading branch information
Showing
6 changed files
with
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ConfigWatcher | ||
############# | ||
|
||
Plugin app that can report on changes to Django model instances via logging and optionally Slack messages. The goal is to help operators who are investigating an outage or other sudden change in behavior by allowing them to easily determine what has changed recently. | ||
|
||
Currently specialized to observe Waffle flags, switches, and samples, but could be expanded to other models. | ||
|
||
See ``.signals.receivers`` for available settings and ``/setup.py`` for IDA plugin configuration. |
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
48 changes: 48 additions & 0 deletions
48
edx_arch_experiments/config_watcher/signals/tests/test_receivers.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,48 @@ | ||
""" | ||
Test ConfigWatcher signal receivers (main code). | ||
""" | ||
|
||
import json | ||
from contextlib import ExitStack | ||
from unittest.mock import call, patch | ||
|
||
import ddt | ||
from django.test import TestCase, override_settings | ||
|
||
from edx_arch_experiments.config_watcher.signals import receivers | ||
|
||
|
||
@ddt.ddt | ||
class TestConfigWatcherReceivers(TestCase): | ||
|
||
@ddt.unpack | ||
@ddt.data( | ||
( | ||
None, None, None, | ||
), | ||
( | ||
'https://localhost', None, "test message", | ||
), | ||
( | ||
'https://localhost', 'my-ida', "[my-ida] test message", | ||
), | ||
) | ||
def test_send_to_slack(self, slack_url, service_name, expected_message): | ||
"""Check that message prefixing is performed as expected.""" | ||
# This can be made cleaner in Python 3.10 | ||
with ExitStack() as stack: | ||
patches = [ | ||
patch('urllib.request.Request'), | ||
patch('urllib.request.urlopen'), | ||
patch.object(receivers, 'CONFIG_WATCHER_SLACK_WEBHOOK_URL', slack_url), | ||
patch.object(receivers, 'CONFIG_WATCHER_SERVICE_NAME', service_name), | ||
] | ||
(mock_req, _, _, _) = [stack.enter_context(cm) for cm in patches] | ||
receivers._send_to_slack("test message") | ||
|
||
if expected_message is None: | ||
mock_req.assert_not_called() | ||
else: | ||
assert mock_req.called_once() | ||
(call_args, call_kwargs) = mock_req.call_args_list[0] | ||
assert json.loads(call_kwargs['data'])['text'] == expected_message |
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