Merge ~brad-marshall/charm-prometheus-ceph-exporter/+git/prometheus-ceph-exporter-charm:ceph-relation into ~prometheus-charmers/charm-prometheus-ceph-exporter/+git/prometheus-ceph-exporter-charm:master

Proposed by Brad Marshall
Status: Merged
Merged at revision: 2dd00a08819c9bd6dae823816bbd64e50a379217
Proposed branch: ~brad-marshall/charm-prometheus-ceph-exporter/+git/prometheus-ceph-exporter-charm:ceph-relation
Merge into: ~prometheus-charmers/charm-prometheus-ceph-exporter/+git/prometheus-ceph-exporter-charm:master
Diff against target: 504 lines (+113/-205)
9 files modified
README.md (+1/-0)
config.yaml (+9/-27)
dev/null (+0/-133)
layer.yaml (+10/-15)
metadata.yaml (+5/-1)
reactive/prometheus-ceph-exporter.py (+47/-29)
templates/ceph.conf (+19/-0)
templates/ceph.keyring (+5/-0)
templates/daemon_arguments (+17/-0)
Reviewer Review Type Date Requested Status
Barry Price Approve
Paul Gear (community) Needs Fixing
Review via email: mp+328059@code.launchpad.net

Description of the change

Add in ceph-client relationship so we no longer have to target a ceph-mon node, tidy up the code etc.

To post a comment you must log in.
Revision history for this message
Paul Gear (paulgear) wrote :

This chrm needs disentangling from the snap layer and turning into its own layer before we move forward with it.

review: Needs Fixing
Revision history for this message
Barry Price (barryprice) wrote :

+1 LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.md b/README.md
2index 2559ee3..59a0103 100644
3--- a/README.md
4+++ b/README.md
5@@ -22,6 +22,7 @@ From the MAAS host:
6 # Deploy the charm
7
8 juju deploy local:xenial/prometheus-ceph-exporter
9+ juju add-relation prometheus-ceph-exporter ceph-mon:client
10
11 To change the port, refer to the daemon_arguments provided by the snap package at:
12 /var/snap/prometheus-ceph-exporter/current/daemon_arguments
13diff --git a/bin/layer_option b/bin/layer_option
14deleted file mode 100755
15index 90dc400..0000000
16--- a/bin/layer_option
17+++ /dev/null
18@@ -1,24 +0,0 @@
19-#!/usr/bin/env python3
20-
21-import sys
22-sys.path.append('lib')
23-
24-import argparse
25-from charms.layer import options
26-
27-
28-parser = argparse.ArgumentParser(description='Access layer options.')
29-parser.add_argument('section',
30- help='the section, or layer, the option is from')
31-parser.add_argument('option',
32- help='the option to access')
33-
34-args = parser.parse_args()
35-value = options(args.section).get(args.option, '')
36-if isinstance(value, bool):
37- sys.exit(0 if value else 1)
38-elif isinstance(value, list):
39- for val in value:
40- print(val)
41-else:
42- print(value)
43diff --git a/config.yaml b/config.yaml
44index 05b882e..4cf7a63 100644
45--- a/config.yaml
46+++ b/config.yaml
47@@ -1,27 +1,9 @@
48-# Copyright 2016 Canonical Ltd.
49-#
50-# This file is part of the Snap layer for Juju.
51-#
52-# Licensed under the Apache License, Version 2.0 (the "License");
53-# you may not use this file except in compliance with the License.
54-# You may obtain a copy of the License at
55-#
56-# http://www.apache.org/licenses/LICENSE-2.0
57-#
58-# Unless required by applicable law or agreed to in writing, software
59-# distributed under the License is distributed on an "AS IS" BASIS,
60-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
61-# See the License for the specific language governing permissions and
62-# limitations under the License.
63-"options":
64- "snap_proxy":
65- "description": "HTTP/HTTPS web proxy for Snappy to use when accessing the snap\
66- \ store.\n"
67- "type": "string"
68- "default": ""
69- "snap_channel":
70- "default": "stable"
71- "type": "string"
72- "description": |
73- If install_method is set to "snap" this option controlls channel name.
74- Supported values are: "stable", "candidate", "beta" and "edge"
75+options:
76+ username:
77+ description: Username to use for ceph mons - defaults to prometheus-ceph-exporter.
78+ type: string
79+ default: "prometheus-ceph-exporter"
80+ daemon_arguments:
81+ description: Daemon arguments to pass to the exporter.
82+ type: string
83+ default: ""
84diff --git a/layer.yaml b/layer.yaml
85index a3d662a..96ddd93 100644
86--- a/layer.yaml
87+++ b/layer.yaml
88@@ -1,15 +1,10 @@
89-"options":
90- "basic":
91- "use_venv": !!bool "true"
92- "packages": []
93- "include_system_packages": !!bool "false"
94- "snap": {}
95- "prometheus-ceph-exporter": {}
96-"includes":
97-- "layer:basic"
98-- "interface:http"
99-- "layer:snap"
100-"repo": "https://git.launchpad.net/prometheus-ceph-exporter-charm"
101-"ignore":
102- "prometheus-ceph-exporter": [".*.swp"]
103-"is": "prometheus-ceph-exporter"
104+includes: ['layer:basic', 'interface:http', 'layer:snap', 'interface:ceph-client']
105+repo: 'https://git.launchpad.net/prometheus-ceph-exporter-charm'
106+ignore: ['.*.swp' ]
107+options:
108+ basic:
109+ use_venv: true
110+ include_system_packages: true
111+ snap:
112+ prometheus-ceph-exporter:
113+ channel: stable
114diff --git a/metadata.yaml b/metadata.yaml
115index e76e3ef..55f3cf5 100644
116--- a/metadata.yaml
117+++ b/metadata.yaml
118@@ -1,6 +1,6 @@
119 name: prometheus-ceph-exporter
120 summary: Ceph exporter for Prometheus
121-maintainer: Giorgio Di Guardia <giorgio.diguardia@canonical.com>
122+maintainer: Prometheus Charmers <prometheus-charmers@lists.launchpad.net>
123 description: |
124 This is an exporter that exposes information gathered from Ceph
125 for use by the Prometheus monitoring system.
126@@ -9,7 +9,11 @@ tags:
127 - prometheus
128 series:
129 - xenial
130+ - trusty
131 subordinate: false
132 provides:
133 ceph-exporter:
134 interface: http
135+requires:
136+ ceph:
137+ interface: ceph-client
138diff --git a/reactive/__init__.py b/reactive/__init__.py
139deleted file mode 100644
140index e69de29..0000000
141--- a/reactive/__init__.py
142+++ /dev/null
143diff --git a/reactive/prometheus-ceph-exporter.py b/reactive/prometheus-ceph-exporter.py
144index c6ba0c9..41e9e69 100644
145--- a/reactive/prometheus-ceph-exporter.py
146+++ b/reactive/prometheus-ceph-exporter.py
147@@ -13,7 +13,7 @@
148 # limitations under the License.
149
150 import yaml
151-import subprocess
152+import os
153
154 from charmhelpers.core import host, hookenv
155 from charmhelpers.core.templating import render
156@@ -21,37 +21,30 @@ from charms.reactive import (
157 when, when_not, set_state, remove_state
158 )
159 from charms.reactive.helpers import any_file_changed, data_changed
160-from charms.layer import snap
161+# from charms.layer import snap
162
163+from charmhelpers.fetch import (
164+ apt_install,
165+)
166
167 SNAP_NAME = 'prometheus-ceph-exporter'
168 SVC_NAME = 'snap.prometheus-ceph-exporter.ceph-exporter'
169 SNAP_DATA = '/var/snap/' + SNAP_NAME + '/current/'
170 PORT_DEF = 9128
171
172+
173 def templates_changed(tmpl_list):
174 return any_file_changed(['templates/{}'.format(x) for x in tmpl_list])
175
176
177-@when_not('ceph-exporter.installed')
178-def install_packages():
179- hookenv.status_set('maintenance', 'Installing software')
180- config = hookenv.config()
181- channel = config.get('snap_channel', 'stable')
182- snap.install(SNAP_NAME, channel=channel, force_dangerous=False)
183- set_state('ceph-exporter.do-auth-config')
184- set_state('ceph-exporter.installed')
185- set_state('ceph-exporter.do-check-reconfig')
186-
187-
188 def validate_config(filename):
189 return yaml.safe_load(open(filename))
190
191
192-@when('ceph-exporter.installed')
193+@when('snap.installed.prometheus-ceph-exporter')
194 @when('ceph-exporter.do-reconfig-yaml')
195 def write_ceph_exporter_config_yaml():
196- config = hookenv.config()
197+ # config = hookenv.config()
198 hookenv.open_port(PORT_DEF)
199 set_state('ceph-exporter.do-restart')
200 remove_state('ceph-exporter.do-reconfig-yaml')
201@@ -71,19 +64,44 @@ def check_reconfig_ceph_exporter():
202 remove_state('ceph-exporter.do-check-reconfig')
203
204
205-@when('ceph-exporter.do-auth-config')
206-def ceph_auth_config():
207- # Working around snap confinement, creating ceph user, moving conf to snap confined environment ($SNAP_DATA)
208- hookenv.status_set('maintenance', 'Creating ceph user')
209- hookenv.log('Creating exporter ceph user')
210- subprocess.check_call(['ceph', 'auth', 'add', 'client.exporter', 'mon', "allow r"])
211- hookenv.log('Creating exporter keyring file onto {}'.format(SNAP_DATA))
212- subprocess.check_call(['ceph', 'auth', 'get', 'client.exporter', '-o', SNAP_DATA + 'ceph.client.exporter.keyring'])
213- hookenv.log('Copying ceph.conf onto {}'.format(SNAP_DATA))
214- subprocess.check_call(['cp', '/etc/ceph/ceph.conf', SNAP_DATA + 'ceph.conf'])
215- hookenv.log('Modifying snap ceph.conf to point to $SNAP_DATA')
216- subprocess.check_call(['sed', '-i', 's=/etc/ceph/=' + SNAP_DATA + '=g', SNAP_DATA + 'ceph.conf'])
217- remove_state('ceph-exporter.do-auth-config')
218+@when('ceph.connected')
219+def ceph_connected(ceph_client):
220+ apt_install(['ceph-common', 'python-ceph'])
221+
222+
223+@when('ceph.available')
224+def ceph_ready(ceph_client):
225+ username = hookenv.config('username')
226+ daemon_conf = os.path.join(os.sep, SNAP_DATA, 'daemon_arguments')
227+ charm_ceph_conf = os.path.join(os.sep, SNAP_DATA, 'ceph.conf')
228+ cephx_key = os.path.join(os.sep, SNAP_DATA, 'ceph.client.%s.keyring' % (username))
229+
230+ ceph_context = {
231+ 'auth_supported': ceph_client.auth(),
232+ 'mon_hosts': ceph_client.mon_hosts(),
233+ 'service_name': username,
234+ 'ringpath': SNAP_DATA,
235+ }
236+
237+ # Write out the ceph.conf
238+ render('ceph.conf', charm_ceph_conf, ceph_context)
239+
240+ ceph_key_context = {
241+ 'key': str(ceph_client.key()),
242+ 'username': username,
243+ }
244+
245+ # Write out the cephx_key also
246+ render('ceph.keyring', cephx_key, ceph_key_context)
247+
248+ daemon_context = {
249+ 'daemon_arguments': hookenv.config('daemon_arguments'),
250+ 'username': username,
251+ }
252+
253+ # Write out the daemon.arguments file
254+ render('daemon_arguments', daemon_conf, daemon_context)
255+
256
257 @when('ceph-exporter.do-restart')
258 def restart_ceph_exporter():
259@@ -100,6 +118,6 @@ def restart_ceph_exporter():
260
261 # Relations
262 @when('ceph-exporter.started')
263-@when('ceph-exporter.available') # Relation name is "ceph-exporter"
264+@when('ceph-exporter.available') # Relation name is "ceph-exporter"
265 def configure_ceph_exporter_relation(target):
266 target.configure(PORT_DEF)
267diff --git a/reactive/snap.py b/reactive/snap.py
268deleted file mode 100644
269index d357e05..0000000
270--- a/reactive/snap.py
271+++ /dev/null
272@@ -1,133 +0,0 @@
273-# Copyright 2016 Canonical Ltd.
274-#
275-# This file is part of the Snap layer for Juju.
276-#
277-# Licensed under the Apache License, Version 2.0 (the "License");
278-# you may not use this file except in compliance with the License.
279-# You may obtain a copy of the License at
280-#
281-# http://www.apache.org/licenses/LICENSE-2.0
282-#
283-# Unless required by applicable law or agreed to in writing, software
284-# distributed under the License is distributed on an "AS IS" BASIS,
285-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
286-# See the License for the specific language governing permissions and
287-# limitations under the License.
288-'''
289-charms.reactive helpers for dealing with Snap packages.
290-'''
291-import os.path
292-import shutil
293-import subprocess
294-from textwrap import dedent
295-import time
296-
297-from charmhelpers.core import hookenv, host
298-from charms import layer
299-from charms import reactive
300-from charms.layer import snap
301-from charms.reactive import hook
302-from charms.reactive.helpers import data_changed
303-
304-
305-def install():
306- opts = layer.options('snap')
307- for snapname, snap_opts in opts.items():
308- snap.install(snapname, **snap_opts)
309- if data_changed('snap.install.opts', opts):
310- snap.connect_all()
311-
312-
313-def refresh():
314- opts = layer.options('snap')
315- for snapname, snap_opts in opts.items():
316- snap.refresh(snapname, **snap_opts)
317- snap.connect_all()
318-
319-
320-@hook('upgrade-charm')
321-def upgrade_charm():
322- refresh()
323-
324-
325-def get_series():
326- return subprocess.check_output(['lsb_release', '-sc'],
327- universal_newlines=True).strip()
328-
329-
330-def ensure_snapd():
331- # I don't use the apt layer, because that would tie this layer
332- # too closely to apt packaging. Perhaps this is a snap-only system.
333- if not shutil.which('snap'):
334- cmd = ['apt', 'install', '-y', 'snapd']
335- subprocess.check_call(cmd, universal_newlines=True)
336- # Work around lp:1628289. Remove this stanza once snapd depends
337- # on the necessary package and snaps work in lxd xenial containers
338- # without the workaround.
339- if get_series() == 'xenial' and not shutil.which('squashfuse'):
340- cmd = ['apt', 'install', '-y', 'squashfuse']
341- subprocess.check_call(cmd, universal_newlines=True)
342-
343-
344-def update_snap_proxy():
345- # This is a hack based on
346- # https://bugs.launchpad.net/layer-snap/+bug/1533899/comments/1
347- # Do it properly when Bug #1533899 is addressed.
348- # Note we can't do this in a standard reactive handler as we need
349- # to ensure proxies are configured before attempting installs or
350- # updates.
351- proxy = hookenv.config()['snap_proxy']
352- if not data_changed('snap.proxy', proxy):
353- return # Short circuit avoids unnecessary restarts.
354-
355- path = '/etc/systemd/system/snapd.service.d/snap_layer_proxy.conf'
356- if proxy:
357- create_snap_proxy_conf(path, proxy)
358- else:
359- remove_snap_proxy_conf(path)
360- subprocess.check_call(['systemctl', 'daemon-reload'],
361- universal_newlines=True)
362- time.sleep(2)
363- subprocess.check_call(['systemctl', 'restart', 'snapd.service'],
364- universal_newlines=True)
365-
366-
367-def create_snap_proxy_conf(path, proxy):
368- host.mkdir(os.path.dirname(path))
369- content = dedent('''\
370- # Managed by Juju
371- [Service]
372- Environment=http_proxy={}
373- Environment=https_proxy={}
374- ''').format(proxy, proxy)
375- host.write_file(path, content.encode())
376-
377-
378-def remove_snap_proxy_conf(path):
379- if os.path.exists(path):
380- os.remove(path)
381-
382-
383-def ensure_path():
384- # Per Bug #1662856, /snap/bin may be missing from $PATH. Fix this.
385- if '/snap/bin' not in os.environ['PATH'].split(':'):
386- os.environ['PATH'] += ':/snap/bin'
387-
388-
389-# Per https://github.com/juju-solutions/charms.reactive/issues/33,
390-# this module may be imported multiple times so ensure the
391-# initialization hook is only registered once. I have to piggy back
392-# onto the namespace of a module imported before reactive discovery
393-# to do this.
394-if not hasattr(reactive, '_snap_registered'):
395- # We need to register this to run every hook, not just during install
396- # and config-changed, to protect against race conditions. If we don't
397- # do this, then the config in the hook environment may show updates
398- # to running hooks well before the config-changed hook has been invoked
399- # and the intialization provided an opertunity to be run.
400- hookenv.atstart(hookenv.log, 'Initializing Snap Layer')
401- hookenv.atstart(ensure_snapd)
402- hookenv.atstart(ensure_path)
403- hookenv.atstart(update_snap_proxy)
404- hookenv.atstart(install)
405- reactive._snap_registered = True
406diff --git a/templates/ceph.conf b/templates/ceph.conf
407new file mode 100644
408index 0000000..91459c6
409--- /dev/null
410+++ b/templates/ceph.conf
411@@ -0,0 +1,19 @@
412+###############################################################################
413+# [ WARNING ]
414+# glance configuration file maintained by Juju
415+# local changes may be overwritten.
416+###############################################################################
417+[global]
418+{% if auth_supported -%}
419+ auth_supported = {{ auth_supported }}
420+ #keyring = /etc/ceph/$cluster.$name.keyring
421+ keyring = {{ ringpath }}ceph.client.{{ service_name }}.keyring
422+ mon host = {{ mon_hosts | join(' ') }}
423+
424+{% endif -%}
425+{% if use_syslog -%}
426+ log to syslog = {{ use_syslog }}
427+ err to syslog = {{ use_syslog }}
428+ clog to syslog = {{ use_syslog }}
429+{% endif -%}
430+
431diff --git a/templates/ceph.keyring b/templates/ceph.keyring
432new file mode 100644
433index 0000000..3781aa1
434--- /dev/null
435+++ b/templates/ceph.keyring
436@@ -0,0 +1,5 @@
437+[client.{{ username }}]
438+ key = {{ key }}
439+ caps mon = "allow r"
440+ caps osd = "allow rwx"
441+
442diff --git a/templates/daemon_arguments b/templates/daemon_arguments
443new file mode 100644
444index 0000000..bb40eef
445--- /dev/null
446+++ b/templates/daemon_arguments
447@@ -0,0 +1,17 @@
448+# Set the command-line arguments to pass to the ceph_exporter daemon
449+{% if username is defined %}
450+ARGS="-ceph.user {{ username }} {{ daemon_arguments }}"
451+{%- else -%}
452+ARGS="{{ daemon_arguments }}"
453+{% endif %}
454+
455+# Example of the commands:
456+# -ceph.config string
457+# path to ceph config file
458+# -ceph.user string
459+# Ceph user to connect to cluster. (default "admin")
460+# -telemetry.addr string
461+# host:port for ceph exporter (default ":9128")
462+# -telemetry.path string
463+# URL path for surfacing collected metrics (default "/metrics")
464+
465diff --git a/wheelhouse/Jinja2-2.9.5.tar.gz b/wheelhouse/Jinja2-2.9.5.tar.gz
466deleted file mode 100644
467index 82ae159..0000000
468Binary files a/wheelhouse/Jinja2-2.9.5.tar.gz and /dev/null differ
469diff --git a/wheelhouse/MarkupSafe-0.23.tar.gz b/wheelhouse/MarkupSafe-0.23.tar.gz
470deleted file mode 100644
471index 6b19006..0000000
472Binary files a/wheelhouse/MarkupSafe-0.23.tar.gz and /dev/null differ
473diff --git a/wheelhouse/PyYAML-3.12.tar.gz b/wheelhouse/PyYAML-3.12.tar.gz
474deleted file mode 100644
475index aabee39..0000000
476Binary files a/wheelhouse/PyYAML-3.12.tar.gz and /dev/null differ
477diff --git a/wheelhouse/Tempita-0.5.2.tar.gz b/wheelhouse/Tempita-0.5.2.tar.gz
478deleted file mode 100644
479index 755befc..0000000
480Binary files a/wheelhouse/Tempita-0.5.2.tar.gz and /dev/null differ
481diff --git a/wheelhouse/charmhelpers-0.13.0.tar.gz b/wheelhouse/charmhelpers-0.13.0.tar.gz
482deleted file mode 100644
483index c862e55..0000000
484Binary files a/wheelhouse/charmhelpers-0.13.0.tar.gz and /dev/null differ
485diff --git a/wheelhouse/charms.reactive-0.4.5.tar.gz b/wheelhouse/charms.reactive-0.4.5.tar.gz
486deleted file mode 100644
487index ff4e308..0000000
488Binary files a/wheelhouse/charms.reactive-0.4.5.tar.gz and /dev/null differ
489diff --git a/wheelhouse/netaddr-0.7.19.tar.gz b/wheelhouse/netaddr-0.7.19.tar.gz
490deleted file mode 100644
491index cc31d9d..0000000
492Binary files a/wheelhouse/netaddr-0.7.19.tar.gz and /dev/null differ
493diff --git a/wheelhouse/pip-8.1.2.tar.gz b/wheelhouse/pip-8.1.2.tar.gz
494deleted file mode 100644
495index e7a1a3c..0000000
496Binary files a/wheelhouse/pip-8.1.2.tar.gz and /dev/null differ
497diff --git a/wheelhouse/pyaml-16.12.2.tar.gz b/wheelhouse/pyaml-16.12.2.tar.gz
498deleted file mode 100644
499index 2ff0b0a..0000000
500Binary files a/wheelhouse/pyaml-16.12.2.tar.gz and /dev/null differ
501diff --git a/wheelhouse/six-1.10.0.tar.gz b/wheelhouse/six-1.10.0.tar.gz
502deleted file mode 100644
503index ac8eec5..0000000
504Binary files a/wheelhouse/six-1.10.0.tar.gz and /dev/null differ

Subscribers

People subscribed via source and target branches