-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interface for retrieving alerting config from charmed AlertManager (
#14) This commit allows the charm to retrieve a configuration string from the alertmanager charm. The configuration string is a JSON string that this charm converts to a dict that is then inserted to another dict that ultimately gets serialized into a YAML-formatted prometheus config file. While this charm is agnostic to the contents of the JSON string, in AlertManager's current iteration, it uses the `kube_sd_configs` method so that Prometheus can quickly detect changes in the number of AlertManager pods without waiting for any Juju events.
- Loading branch information
1 parent
1ca7454
commit 8ef5661
Showing
10 changed files
with
280 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.idea | ||
.tox | ||
.orig | ||
*.egg-info | ||
**/__pycache__ | ||
.coverage | ||
|
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
Submodule operator
updated
25 files
+0 −6 | .readthedocs.yaml | |
+1 −1 | .travis.yml | |
+88 −89 | README.md | |
+1 −13 | docs/conf.py | |
+0 −0 | docs/contents.rst | |
+1 −5 | docs/requirements.txt | |
+0 −2 | ops/__init__.py | |
+156 −141 | ops/charm.py | |
+21 −19 | ops/framework.py | |
+0 −185 | ops/lib/__init__.py | |
+45 −127 | ops/main.py | |
+73 −336 | ops/model.py | |
+77 −147 | ops/testing.py | |
+0 −4 | requirements-dev.txt | |
+0 −1 | requirements.txt | |
+12 −44 | setup.py | |
+38 −44 | test/charms/test_main/src/charm.py | |
+18 −21 | test/test_charm.py | |
+123 −83 | test/test_framework.py | |
+1 −39 | test/test_helpers.py | |
+0 −25 | test/test_infra.py | |
+0 −487 | test/test_lib.py | |
+38 −130 | test/test_main.py | |
+439 −404 | test/test_model.py | |
+4 −183 | test/test_testing.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
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,55 @@ | ||
import json | ||
import logging | ||
|
||
logger = logging.getLogger() | ||
|
||
from ops.framework import ( | ||
EventSource, | ||
Object, | ||
ObjectEvents, | ||
) | ||
from ops.framework import EventBase | ||
from adapters.framework import FrameworkAdapter | ||
|
||
|
||
class NewAlertManagerRelationEvent(EventBase): | ||
|
||
def __init__(self, handle, remote_data): | ||
super().__init__(handle) | ||
self.data = dict(remote_data) | ||
|
||
# The Operator Framework will serialize and deserialize this event object | ||
# as it passes it to the charm. The following snapshot and restore methos | ||
# ensure that our underlying data don't get lost along the way. | ||
|
||
def snapshot(self): | ||
return json.dumps(self.data) | ||
|
||
def restore(self, snapshot): | ||
self.data = json.loads(snapshot) | ||
|
||
|
||
class AlertManagerEvents(ObjectEvents): | ||
new_relation = EventSource(NewAlertManagerRelationEvent) | ||
|
||
|
||
class AlertManagerInterface(Object): | ||
on = AlertManagerEvents() | ||
|
||
def __init__(self, charm, relation_name): | ||
super().__init__(charm, relation_name) | ||
|
||
self.fw_adapter = FrameworkAdapter(self.framework) | ||
self.relation_name = relation_name | ||
|
||
self.fw_adapter.observe(charm.on[relation_name].relation_changed, | ||
self.on_relation_changed) | ||
|
||
def on_relation_changed(self, event): | ||
remote_data = event.relation.data[event.unit] | ||
logging.debug( | ||
"Received remote_data: {}".format(dict(remote_data)) | ||
) | ||
|
||
logger.debug("Emitting new_relation event") | ||
self.on.new_relation.emit(remote_data) |
Oops, something went wrong.