-
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: Preliminary version of Waffle config watcher
This still needs to be hooked up to Slack. - New app `edx_arch_experiments.config_watcher.ConfigWatcher` - New dependency on django-waffle - Dependency upgrade
- Loading branch information
Showing
13 changed files
with
122 additions
and
44 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
Empty file.
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,16 @@ | ||
""" | ||
App for reporting configuration changes to Slack for operational awareness. | ||
""" | ||
|
||
from django.apps import AppConfig | ||
|
||
class ConfigWatcherApp(AppConfig): | ||
""" | ||
Django application to report configuration changes to operators. | ||
""" | ||
name = 'edx_arch_experiments.config_watcher' | ||
|
||
def ready(self): | ||
from .signals import receivers # pylint: disable=import-outside-toplevel | ||
|
||
receivers.connect_receivers() |
Empty file.
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,65 @@ | ||
""" | ||
Signal receivers for the config watcher. | ||
Call ``connect_receivers`` to initialize. | ||
""" | ||
|
||
import waffle.models | ||
from django.db.models import signals | ||
from django.dispatch import receiver | ||
|
||
|
||
def _report_waffle_change(model_short_name, instance, created, fields): | ||
verb = "created" if created else "updated" | ||
state_desc = ", ".join(f"{field}={repr(getattr(instance, field))}" for field in fields) | ||
print(f"⚡⚡⚡ Waffle {model_short_name} {instance.name!r} was {verb}. New config: {state_desc}") | ||
|
||
|
||
def _report_waffle_delete(model_short_name, instance): | ||
print(f"💥💥💥 Waffle {model_short_name} {instance.name!r} was deleted") | ||
|
||
|
||
_WAFFLE_MODELS_TO_OBSERVE = [ | ||
{ | ||
'model': waffle.models.Flag, | ||
'short_name': 'flag', | ||
'fields': ['everyone', 'percent', 'superusers', 'staff', 'authenticated', 'note', 'languages'], | ||
}, | ||
{ | ||
'model': waffle.models.Switch, | ||
'short_name': 'switch', | ||
'fields': ['active', 'note'], | ||
}, | ||
{ | ||
'model': waffle.models.Sample, | ||
'short_name': 'sample', | ||
'fields': ['percent', 'note'], | ||
}, | ||
] | ||
|
||
|
||
def _register_waffle_observation(*, model, short_name, fields): | ||
""" | ||
Register a Waffle model for observation. | ||
Args: | ||
model (class): The model class to monitor | ||
short_name (str): A short descriptive name for an instance of the model, e.g. "flag" | ||
fields (list): Names of fields to report on in the Slack message | ||
""" | ||
@receiver(signals.post_save, sender=model) | ||
def log_waffle_change(*args, instance, created, **kwargs): | ||
_report_waffle_change(short_name, instance, created, fields) | ||
|
||
@receiver(signals.post_delete, sender=model) | ||
def log_waffle_change(*args, instance, **kwargs): | ||
_report_waffle_delete(short_name, instance) | ||
|
||
|
||
def connect_receivers(): | ||
""" | ||
Initialize application's receivers. | ||
""" | ||
for config in _WAFFLE_MODELS_TO_OBSERVE: | ||
# Pass config to function to capture value properly. | ||
_register_waffle_observation(**config) |
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
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
Oops, something went wrong.