Merge lp:~jacekn/charms/trusty/prometheus/storage-fixes into lp:~canonical-is-sa/charms/trusty/prometheus/layer-prometheus

Proposed by Jacek Nykis
Status: Merged
Approved by: Chris Stratford
Approved revision: 17
Merged at revision: 17
Proposed branch: lp:~jacekn/charms/trusty/prometheus/storage-fixes
Merge into: lp:~canonical-is-sa/charms/trusty/prometheus/layer-prometheus
Diff against target: 81 lines (+15/-20)
3 files modified
README.md (+4/-0)
metadata.yaml (+1/-6)
reactive/prometheus.py (+10/-14)
To merge this branch: bzr merge lp:~jacekn/charms/trusty/prometheus/storage-fixes
Reviewer Review Type Date Requested Status
Chris Stratford (community) Approve
Review via email: mp+297474@code.launchpad.net

Description of the change

Remove redundant metrics-block storge from metadata.yaml and rename metrics-filesystem to metrics. Fix and storage support

To post a comment you must log in.
Revision history for this message
Chris Stratford (chris-gondolin) wrote :

Failures in subprocess.check_call() aren't caught, but I guess a stacktrace may be enough, so +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.md'
2--- README.md 2016-02-17 11:51:35 +0000
3+++ README.md 2016-06-15 15:23:18 +0000
4@@ -5,6 +5,10 @@
5
6 ## How to deploy the charm
7
8+To deploy with storage support and use 13GB volume for metrics:
9+
10+juju deploy --storage metrics=13G local:xenial/prometheus prometheus
11+
12 ## Development
13
14 Explicitly set `JUJU_REPOSITORY`:
15
16=== modified file 'metadata.yaml'
17--- metadata.yaml 2016-04-13 16:13:22 +0000
18+++ metadata.yaml 2016-06-15 15:23:18 +0000
19@@ -23,14 +23,9 @@
20 alertmanager-service:
21 interface: http
22 storage:
23- metrics-filesystem:
24+ metrics:
25 type: filesystem
26 description: Storage for prometheus data
27 location: /srv/prometheus
28 multiple:
29 range: 0-1
30- metrics-block:
31- type: block
32- description: Storage for prometheus data
33- multiple:
34- range: 0-1
35
36=== modified file 'reactive/prometheus.py'
37--- reactive/prometheus.py 2016-04-13 15:58:16 +0000
38+++ reactive/prometheus.py 2016-06-15 15:23:18 +0000
39@@ -32,25 +32,22 @@
40
41
42 # TODO: once there's reactive support for storage hooks, convert off @hook()
43-@hook('metrics-{filesystem,block}-storage-attached')
44+@hook('metrics-storage-attached')
45 def configure_storage():
46+ # Storage hooks always run before install so we don't have to worry
47+ # about states here
48 storage_path = subprocess.check_output(
49 ['storage-get', 'location']).decode().strip()
50 kv = unitdata.kv()
51 kv.set('storage-path', storage_path)
52 runtime_args('-storage.local.path', storage_path)
53- set_state('storage.configured')
54- set_state('prometheus.do-check-reconfig')
55-
56-
57-def set_datadir_perms():
58- datadir = unitdata.kv().get('storage-path', False)
59- if not datadir:
60- # No juju storage attached, use defaults from package
61- return
62- users = [i for i in pwd.getpwall() if i.pw_name == 'nobody']
63- if len(users) == 1:
64- os.lchown(datadir, users[0].pw_uid, users[0].pw_gid)
65+
66+ subprocess.check_call(['addgroup', '--system', 'prometheus'])
67+ subprocess.check_call(['adduser', '--system', '--home', storage_path, '--ingroup', 'prometheus',
68+ '--shell', '/bin/false', '--no-create-home',
69+ '--gecos', 'Prometheus daemon', 'prometheus'])
70+ users = [i for i in pwd.getpwall() if i.pw_name == 'prometheus']
71+ os.lchown(storage_path, users[0].pw_uid, users[0].pw_gid)
72
73
74 @when('prometheus.do-install')
75@@ -154,7 +151,6 @@
76 hookenv.status_set('maintenance', 'Waiting for basenode to run')
77 return
78 hookenv.status_set('maintenance', 'Configuring software')
79- set_datadir_perms()
80 install_packages()
81 set_state('prometheus.do-check-reconfig')
82

Subscribers

People subscribed via source and target branches

to all changes: