Merge lp:~maxiberta/charms/trusty/grafana/layer-grafana-plugins into lp:~canonical-is-sa/charms/trusty/grafana/layer-grafana

Proposed by Maximiliano Bertacchini
Status: Work in progress
Proposed branch: lp:~maxiberta/charms/trusty/grafana/layer-grafana-plugins
Merge into: lp:~canonical-is-sa/charms/trusty/grafana/layer-grafana
Diff against target: 106 lines (+47/-4)
3 files modified
README.md (+1/-1)
config.yaml (+7/-0)
reactive/grafana.py (+39/-3)
To merge this branch: bzr merge lp:~maxiberta/charms/trusty/grafana/layer-grafana-plugins
Reviewer Review Type Date Requested Status
Maximiliano Bertacchini (community) Needs Resubmitting
Celso Providelo (community) Approve
Prometheus Charmers Pending
Canonical IS SAs Pending
Review via email: mp+307770@code.launchpad.net

Commit message

Add support for grafana plugins.

Description of the change

Add support for grafana plugins.

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) wrote :

Thanks, Maxi.

The code change looks sane, let's wait for the IS review.

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

The target branch is now in git at https://launchpad.net/grafana-charm. I don't think there is much divergence yet so patches should apply cleanly.

tbh I think this should be Juju2 and using resources rather than http urls and hosting to be setup. I don't know if Juju resources supports this use case though (iirc you can't specify a arbitrarily long list of resources, making it useless for this sort of thing)

(this is not a real review - I'm not here at the moment)

Revision history for this message
Maximiliano Bertacchini (maxiberta) wrote :

Thanks. Rebased onto lp:grafana-charm, which is indeed basically the exact same code: https://code.launchpad.net/~maxiberta/grafana-charm/+git/grafana-charm/+merge/308551.

review: Needs Resubmitting

Unmerged revisions

44. By Maximiliano Bertacchini

Add support for grafana plugins.

43. By Maximiliano Bertacchini

Fix typo that prevented the config-changed hook from running.

42. By Maximiliano Bertacchini

Fix typo in README.

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-07-20 01:50:58 +0000
3+++ README.md 2016-10-05 22:27:37 +0000
4@@ -10,7 +10,7 @@
5 Above will automatcially configure prometheus as grafana datasource
6
7 If admin password is not set using configuration option it is autogenerated.
8-To retried autogenerated password run:
9+To retrieve autogenerated password, run:
10 juju run --service grafana "scripts/get_admin_password"
11
12
13
14=== modified file 'config.yaml'
15--- config.yaml 2016-07-20 02:03:04 +0000
16+++ config.yaml 2016-10-05 22:27:37 +0000
17@@ -91,3 +91,10 @@
18 type: string
19 description: |
20 Location where to put dashboard dumps
21+ install_plugins:
22+ default: ""
23+ type: string
24+ description: |
25+ Comma separated list of locations where grafana plugin tarballs can be found.
26+ Example:
27+ install_plugins: http://my.company.com/packages/grafana/plugins/plugin-panel.tar.gz
28
29=== modified file 'reactive/grafana.py'
30--- reactive/grafana.py 2016-07-21 02:47:36 +0000
31+++ reactive/grafana.py 2016-10-05 22:27:37 +0000
32@@ -7,12 +7,13 @@
33 import json
34 import subprocess
35 import base64
36+import shutil
37 from charmhelpers import fetch
38 from charmhelpers.core import host, hookenv, unitdata
39 from charmhelpers.core.templating import render
40 from charmhelpers.contrib.charmsupport import nrpe
41 from charms.reactive import hook, remove_state, set_state, when, when_not
42-from charms.reactive.helpers import any_file_changed, data_changed
43+from charms.reactive.helpers import any_file_changed, data_changed, is_state
44
45
46 try:
47@@ -61,6 +62,41 @@
48 hookenv.status_set('active', 'Completed installing grafana')
49
50
51+@when('grafana.installed')
52+@when('config.changed.install_plugins')
53+def install_plugins():
54+ plugins_dir = '/var/lib/grafana/plugins/'
55+
56+ if os.path.exists(plugins_dir):
57+ hookenv.log('Cleaning up currently installed plugins')
58+ hookenv.status_set('maintenance', 'Cleaning up currently installed plugins')
59+ for entry in os.listdir(plugins_dir):
60+ entry_path = os.path.join(plugins_dir, entry)
61+ if os.path.isfile(entry_path):
62+ os.unlink(entry_path)
63+ elif os.path.isdir(entry_path):
64+ shutil.rmtree(entry_path)
65+ hookenv.log('Completed cleaning up grafana plugins')
66+ hookenv.status_set('active', 'Completed cleaning up grafana plugins')
67+
68+ config = hookenv.config()
69+ if config.get('install_plugins', False):
70+ hookenv.log('Installing plugins')
71+ hookenv.status_set('maintenance', 'Installing plugins')
72+ plugin_file = '/tmp/grafana-plugin.tar.gz'
73+ for plugin_url in config.get('install_plugins').split(','):
74+ plugin_url = plugin_url.strip()
75+ hookenv.log('Downloading plugin: {!r}'.format(plugin_url))
76+ with open(plugin_file, 'wb') as f:
77+ r = requests.get(plugin_url, stream=True)
78+ for block in r.iter_content(1024):
79+ f.write(block)
80+ hookenv.log('Extracting plugin: {!r}'.format(plugin_url))
81+ shutil.unpack_archive(plugin_file, plugins_dir)
82+ hookenv.log('Completed installing grafana plugins')
83+ hookenv.status_set('active', 'Completed installing grafana plugins')
84+
85+
86 @hook('upgrade-charm')
87 def upgrade_charm():
88 hookenv.status_set('maintenance', 'Forcing package update and reconfiguration on upgrade-charm')
89@@ -68,7 +104,7 @@
90 remove_state('grafana.configured')
91
92
93-@hook('config.changed')
94+@hook('config-changed')
95 def config_changed():
96 remove_state('grafana.configured')
97 config = hookenv.config()
98@@ -191,7 +227,7 @@
99 hookenv.status_set('maintenance', msg)
100 hookenv.log(msg)
101 host.service_start(SVCNAME)
102- elif any_file_changed([GRAFANA_INI]):
103+ elif any_file_changed([GRAFANA_INI]) or is_state('config.changed.install_plugins'):
104 msg = 'Restarting {}'.format(SVCNAME)
105 hookenv.log(msg)
106 hookenv.status_set('maintenance', msg)

Subscribers

People subscribed via source and target branches