Merge ~ballot/charm-prometheus-alertmanager/+git/charm-prometheus-alertmanager:log-level into charm-prometheus-alertmanager:master

Proposed by Benjamin Allot
Status: Superseded
Proposed branch: ~ballot/charm-prometheus-alertmanager/+git/charm-prometheus-alertmanager:log-level
Merge into: charm-prometheus-alertmanager:master
Diff against target: 103 lines (+61/-0)
3 files modified
src/config.yaml (+6/-0)
src/reactive/alertmanager.py (+14/-0)
src/tests/unit/test_reactive_alertmanager.py (+41/-0)
Reviewer Review Type Date Requested Status
Drew Freiberger (community) Needs Fixing
BootStack Reviewers Pending
Review via email: mp+395874@code.launchpad.net

This proposal has been superseded by a proposal from 2021-01-27.

Commit message

Add the log-level config item

In order to easily debug, configuring the log-level of alertmanager can be handy.
The old default value of info (if not specified) is kept so an upgrade won't be bothered by the change.

To post a comment you must log in.
Revision history for this message
Drew Freiberger (afreiberger) wrote :

I'd like to see this charm go into a blocked state for an incorrectly configured log level value, and would appreciate seeing the values accepted for log-level in the config.yaml description.

I am also concerned that this change when upgrade-charm runs will restart the service (which is typically frowned upon) even if no configuration change is expected. Maybe the default should be a blank string, which equates to not setting a --log.level, which should keep the config file from being updated and the service from restarting based on service context change.

review: Needs Fixing
6037fcc... by Benjamin Allot

Set status to blocked upon wrong log-level

Addressed some review items:
* Provide the list of valid log-level in the config description
* Set the charm status to block in case of an invalid value
* Adapt the test accordingly

Unmerged commits

6037fcc... by Benjamin Allot

Set status to blocked upon wrong log-level

Addressed some review items:
* Provide the list of valid log-level in the config description
* Set the charm status to block in case of an invalid value
* Adapt the test accordingly

4a4132c... by Benjamin Allot

Add the log-level config item

In order to easily debug, configuring the log-level of alertmanager can
be handy.
The old default value of info (if not specified) is kept so an upgrade
won't be bothered by the change.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/config.yaml b/src/config.yaml
index 5c7bf30..fe0c1b1 100644
--- a/src/config.yaml
+++ b/src/config.yaml
@@ -9,6 +9,12 @@ options:
9 type: int9 type: int
10 default: 909310 default: 9093
11 description: "Alertmanager listening port"11 description: "Alertmanager listening port"
12 log-level:
13 type: string
14 default: ""
15 description: |
16 Loggging level used for alertmanager.
17 Valid values are "error", "warn", "info" and "debug".
12 external_url:18 external_url:
13 default: ""19 default: ""
14 type: string20 type: string
diff --git a/src/reactive/alertmanager.py b/src/reactive/alertmanager.py
index e67f0e0..ef36c5d 100644
--- a/src/reactive/alertmanager.py
+++ b/src/reactive/alertmanager.py
@@ -18,6 +18,7 @@ ALERTMANAGER_YML = "/var/snap/prometheus-alertmanager/current/alertmanager.yml"
18ALERTMANAGER_DEF = "/var/snap/prometheus-alertmanager/current/daemon_arguments"18ALERTMANAGER_DEF = "/var/snap/prometheus-alertmanager/current/daemon_arguments"
19ALERTMANAGER_YML_TMPL = "alertmanager.yml.j2"19ALERTMANAGER_YML_TMPL = "alertmanager.yml.j2"
20ALERTMANAGER_DEF_TMPL = "daemon_arguments.j2"20ALERTMANAGER_DEF_TMPL = "daemon_arguments.j2"
21LOG_LEVELS = ["debug", "error", "info", "warn"]
2122
2223
23def templates_changed(tmpl_list):24def templates_changed(tmpl_list):
@@ -121,8 +122,21 @@ def write_alertmanager_config_yml():
121def write_alertmanager_config_def():122def write_alertmanager_config_def():
122 config = hookenv.config()123 config = hookenv.config()
123 port = config.get("port", "9093")124 port = config.get("port", "9093")
125 log_level = config.get("log-level")
126 if log_level:
127 if log_level in LOG_LEVELS:
128 runtime_args("--log.level", "{}".format(log_level))
129 else:
130 hookenv.status_set(
131 "blocked",
132 "log-level {} is unknown."
133 " Pick one of the following value: {}".format(
134 log_level, ",".join(LOG_LEVELS))
135 )
136 return
124 check_ports(port)137 check_ports(port)
125 runtime_args("--web.listen-address", ":{}".format(port))138 runtime_args("--web.listen-address", ":{}".format(port))
139
126 if config.get("external_url", False):140 if config.get("external_url", False):
127 vars = {141 vars = {
128 "private_address": hookenv.unit_get("private-address"),142 "private_address": hookenv.unit_get("private-address"),
diff --git a/src/tests/unit/test_reactive_alertmanager.py b/src/tests/unit/test_reactive_alertmanager.py
index 98ff2f1..3655c0c 100644
--- a/src/tests/unit/test_reactive_alertmanager.py
+++ b/src/tests/unit/test_reactive_alertmanager.py
@@ -176,6 +176,47 @@ class TestPrometheusContext(unittest.TestCase):
176 contents, "ARGS=.*-web.listen.address :{}.*".format(fake_port)176 contents, "ARGS=.*-web.listen.address :{}.*".format(fake_port)
177 )177 )
178178
179 def test_log_level_configs(self, mock_get_peers, mock_hookenv_config, *args):
180 config = self.def_config
181 fake_port = "9876"
182 fake_ext_url = "http://foo:1234/bar"
183 config.update({
184 "port": fake_port,
185 "external_url": fake_ext_url,
186 "log-level": "debug",
187 })
188 mock_hookenv_config.return_value = config
189 alertmanager.write_alertmanager_config_yml()
190 alertmanager.write_alertmanager_config_def()
191 # Verify etc/default/alertmanager has --log.level
192 with open(self.cfg_def) as fh:
193 contents = fh.read()
194 self.assertRegex(contents, "ARGS=.*--log.level debug.*")
195
196 def test_bad_log_level_configs(
197 self, mock_get_peers, mock_hookenv_config, mock_hookenv_unit_get,
198 mock_valudate_config, mock_data_changed,
199 mock_host_service_running, mock_host_service_restart,
200 mock_hookenv_status_set, *args
201 ):
202 config = self.def_config
203 fake_port = "9876"
204 fake_ext_url = "http://foo:1234/bar"
205 config.update({
206 "port": fake_port,
207 "external_url": fake_ext_url,
208 "log-level": "dummylevel",
209 })
210 mock_hookenv_config.return_value = config
211 alertmanager.write_alertmanager_config_yml()
212 alertmanager.write_alertmanager_config_def()
213 # Verify charm status is blocked
214 mock_hookenv_status_set.assert_called_with(
215 "blocked",
216 "log-level dummylevel is unknown."
217 " Pick one of the following value: debug,error,info,warn"
218 )
219
179 @mock.patch("reactive.alertmanager.remove_state")220 @mock.patch("reactive.alertmanager.remove_state")
180 def test_install_packages_conditionally_called(221 def test_install_packages_conditionally_called(
181 self,222 self,

Subscribers

People subscribed via source and target branches

to all changes: