Merge ~mattyw/prometheus-charm:01-configure-rules into prometheus-charm:master

Proposed by Matthew Williams
Status: Merged
Merged at revision: 166479c1c040ff5f0745cab1018bff5cf5ffd640
Proposed branch: ~mattyw/prometheus-charm:01-configure-rules
Merge into: prometheus-charm:master
Diff against target: 39 lines (+2/-5)
1 file modified
reactive/prometheus.py (+2/-5)
Reviewer Review Type Date Requested Status
Jacek Nykis (community) Approve
Casey Marshall (community) Approve
Review via email: mp+330996@code.launchpad.net

Commit message

prometheus.py: The configure_rules function needs to be called immediately, rather than scheduling for later, the rules for state execution are non deterministic, but we require this to be called before promtool validates them

Description of the change

This is a follow on from https://code.launchpad.net/~mattyw/prometheus-charm/+git/prometheus-charm/+merge/330833

The change in this pr fixes a similar issue where deploying the charm with an initial config setting for custom-rules would cause and install hook error.

cat cfg.yaml
prometheus:
    custom-rules: {}

$ juju deploy --config cfg.yaml cs:prometheus

This was because the configure_rules function (where the file is written) would not be called as the check_reconfig_prometheus() sets the prometheus.do-install during install hook execution which means the configure_rules() function is never called (thanks to a when_not). Meaning that when promtool is called as part of write_prometheus_config_yml, the rules file has never been written (and we get the error described in the above link)

After examining the states it became clear that actually calling the function directly rather than setting states would be a much clearer way of executing this function in the right place, as state execution ordering is not defined in charms.reactive

To post a comment you must log in.
Revision history for this message
Casey Marshall (cmars) wrote :

LGTM

review: Approve
Revision history for this message
Jacek Nykis (jacekn) wrote :

Merged, composed and pushed to the edge channel.
final tests are running now and once they complete I'll release to stable

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/prometheus.py b/reactive/prometheus.py
2index ff8a2b1..31f54df 100644
3--- a/reactive/prometheus.py
4+++ b/reactive/prometheus.py
5@@ -61,8 +61,6 @@ def daemon_args():
6 return sorted(args_list)
7
8
9-@when('prometheus.do-reconfig-rules')
10-@when_not('prometheus.do-install')
11 def configure_rules():
12 config = hookenv.config()
13 # Static rules provided as config options
14@@ -112,7 +110,6 @@ def configure_rules():
15 with open(PROMETHEUS_RULES_CRON, 'w') as f:
16 f.write('{} root {} &>/dev/null\n'.format(schedule, REFRESH_RULES_SCRIPT))
17 set_state('prometheus.do-reconfig-yml')
18- remove_state('prometheus.do-reconfig-rules')
19
20
21 def remove_external_rules():
22@@ -430,7 +427,7 @@ def check_reconfig_prometheus():
23 hookenv.log('One of options affecting daemon args has changed, scheduling reconfiguration')
24 set_state('prometheus.do-reconfig-def')
25 if any(config.changed(opt) for opt in rules_change_opts):
26- set_state('prometheus.do-reconfig-rules')
27+ configure_rules()
28 if any(config.changed(opt) for opt in yml_change_opts):
29 set_state('prometheus.do-reconfig-yml')
30 if any((
31@@ -446,7 +443,7 @@ def check_reconfig_prometheus():
32 hookenv.log('Daemon flags template changed, scheduling reconfiguration')
33 set_state('prometheus.do-reconfig-def')
34 if templates_changed([REFRESH_RULES_SCRIPT_TMPL]):
35- set_state('prometheus.do-reconfig-rules')
36+ configure_rules()
37 # Cron can update rules on disk, update-status hook can trigger config update
38 if kv.get('prometheus.rule_files') != get_rule_files():
39 kv.set('prometheus.rule_files', get_rule_files())

Subscribers

People subscribed via source and target branches