Merge ~pjdc/prometheus-mongodb-exporter-charm/+git/prometheus-mongodb-exporter-charm:no-needless-blocked into prometheus-mongodb-exporter-charm:master

Proposed by Paul Collins
Status: Rejected
Rejected by: Haw Loeung
Proposed branch: ~pjdc/prometheus-mongodb-exporter-charm/+git/prometheus-mongodb-exporter-charm:no-needless-blocked
Merge into: prometheus-mongodb-exporter-charm:master
Diff against target: 57 lines (+21/-4)
1 file modified
reactive/prometheus_mongodb_exporter.py (+21/-4)
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Needs Fixing
Canonical IS Reviewers Pending
Review via email: mp+372231@code.launchpad.net

Commit message

ensure installation happens immediately after setting mongodb_uri to juju-db://

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Stuart Bishop (stub) wrote :

The maybe_block_on_mongodb_uri() handler may end up running before the is_mongodb_uri_usable() handler, causing a spurious blocked state.

Instead, I'd just do:

@when('config.default.mongodb_uri') # default is empty string
def block_on_no_uri():
    blocked('mongodb_uri must be set')

@when('config.changed.mongodb_uri')
def local_or_remote():
    l = mongodb_uri_is_juju_db()
    reactive.toggle_flag('prometheus-mongodb-exporter.monitor-juju-db', l)
    reactive.toggle_flag('prometheus-mongodb-exporter.monitor-remote-db', not l)

@when('prometheus-mongodb-exporter.monitor-juju-db')
@when_not('leadership.is_leader', 'leadership.set.mongodb_uri')
def wait_on_leader():
    waiting('Waiting for leader to provide mongodb credentials')

@when('prometheus-mongodb-exporter.monitor-juju-db')
@when('leadership.is_leader')
@when_not('leadership.set.mongodb_uri')
def create_juju_db_user():
    [ ... existing code ... ]

review: Needs Fixing

Unmerged commits

681810e... by Paul Collins

ensure installation happens immediately after setting mongodb_uri to juju-db://

Previously, install_prometheus_mongodb_exporter would bail when
the config item was "juju-db://" but the leader setting was empty,
because create_juju_db_user had not yet been invoked.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/prometheus_mongodb_exporter.py b/reactive/prometheus_mongodb_exporter.py
2index ae2d3d3..ec32635 100644
3--- a/reactive/prometheus_mongodb_exporter.py
4+++ b/reactive/prometheus_mongodb_exporter.py
5@@ -81,6 +81,25 @@ def maybe_monitor_juju_db():
6 remove_state('prometheus-mongodb-exporter.monitor-juju-db')
7
8
9+@when_any('config.changed.mongodb_uri', 'leadership.changed.mongodb_uri')
10+def is_mongodb_uri_usable():
11+ if get_mongodb_uri():
12+ set_state('prometheus-mongodb-exporter.mongodb_uri.usable')
13+ else:
14+ remove_state('prometheus-mongodb-exporter.mongodb_uri.usable')
15+
16+
17+@when_not('prometheus-mongodb-exporter.mongodb_uri.usable')
18+def maybe_block_on_mongodb_uri():
19+ if get_mongodb_uri():
20+ return
21+ if mongodb_uri_is_juju_db():
22+ # The config item is "juju-db://" but the leader setting is empty,
23+ # which create_juju_db_user will fix shortly; let it have its chance.
24+ return
25+ blocked('mongodb_uri must be set')
26+
27+
28 @when('prometheus-mongodb-exporter.monitor-juju-db')
29 @when('leadership.is_leader')
30 @when_not('leadership.set.mongodb_uri')
31@@ -121,6 +140,7 @@ def create_juju_db_user():
32 leader_set(mongodb_uri='mongodb://{}:{}@localhost:37017/admin'.format(username, password))
33
34
35+@when('prometheus-mongodb-exporter.mongodb_uri.usable')
36 @when_not('prometheus-mongodb-exporter.installed')
37 def install_prometheus_mongodb_exporter():
38 ''' Install the proxy application '''
39@@ -130,10 +150,6 @@ def install_prometheus_mongodb_exporter():
40
41 snap.install('prometheus-mongodb-exporter')
42
43- if not uri:
44- blocked('mongodb_uri must be set')
45- return
46-
47 # Create a systemd unit file, and open the port.
48 port = hookenv.config()['port']
49 if not sensible_port(port):
50@@ -168,6 +184,7 @@ def update_opened_port():
51 hookenv.open_port(new_port)
52
53
54+@when('prometheus-mongodb-exporter.mongodb_uri.usable')
55 @when('prometheus-mongodb-exporter.installed')
56 @when_any('config.changed', 'leadership.changed')
57 def update_daemon_args():

Subscribers

People subscribed via source and target branches