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
=== modified file 'README.md'
--- README.md 2016-07-20 01:50:58 +0000
+++ README.md 2016-10-05 22:27:37 +0000
@@ -10,7 +10,7 @@
10Above will automatcially configure prometheus as grafana datasource10Above will automatcially configure prometheus as grafana datasource
1111
12If admin password is not set using configuration option it is autogenerated.12If admin password is not set using configuration option it is autogenerated.
13To retried autogenerated password run:13To retrieve autogenerated password, run:
14 juju run --service grafana "scripts/get_admin_password"14 juju run --service grafana "scripts/get_admin_password"
1515
1616
1717
=== modified file 'config.yaml'
--- config.yaml 2016-07-20 02:03:04 +0000
+++ config.yaml 2016-10-05 22:27:37 +0000
@@ -91,3 +91,10 @@
91 type: string91 type: string
92 description: |92 description: |
93 Location where to put dashboard dumps93 Location where to put dashboard dumps
94 install_plugins:
95 default: ""
96 type: string
97 description: |
98 Comma separated list of locations where grafana plugin tarballs can be found.
99 Example:
100 install_plugins: http://my.company.com/packages/grafana/plugins/plugin-panel.tar.gz
94101
=== modified file 'reactive/grafana.py'
--- reactive/grafana.py 2016-07-21 02:47:36 +0000
+++ reactive/grafana.py 2016-10-05 22:27:37 +0000
@@ -7,12 +7,13 @@
7import json7import json
8import subprocess8import subprocess
9import base649import base64
10import shutil
10from charmhelpers import fetch11from charmhelpers import fetch
11from charmhelpers.core import host, hookenv, unitdata12from charmhelpers.core import host, hookenv, unitdata
12from charmhelpers.core.templating import render13from charmhelpers.core.templating import render
13from charmhelpers.contrib.charmsupport import nrpe14from charmhelpers.contrib.charmsupport import nrpe
14from charms.reactive import hook, remove_state, set_state, when, when_not15from charms.reactive import hook, remove_state, set_state, when, when_not
15from charms.reactive.helpers import any_file_changed, data_changed16from charms.reactive.helpers import any_file_changed, data_changed, is_state
1617
1718
18try:19try:
@@ -61,6 +62,41 @@
61 hookenv.status_set('active', 'Completed installing grafana')62 hookenv.status_set('active', 'Completed installing grafana')
6263
6364
65@when('grafana.installed')
66@when('config.changed.install_plugins')
67def install_plugins():
68 plugins_dir = '/var/lib/grafana/plugins/'
69
70 if os.path.exists(plugins_dir):
71 hookenv.log('Cleaning up currently installed plugins')
72 hookenv.status_set('maintenance', 'Cleaning up currently installed plugins')
73 for entry in os.listdir(plugins_dir):
74 entry_path = os.path.join(plugins_dir, entry)
75 if os.path.isfile(entry_path):
76 os.unlink(entry_path)
77 elif os.path.isdir(entry_path):
78 shutil.rmtree(entry_path)
79 hookenv.log('Completed cleaning up grafana plugins')
80 hookenv.status_set('active', 'Completed cleaning up grafana plugins')
81
82 config = hookenv.config()
83 if config.get('install_plugins', False):
84 hookenv.log('Installing plugins')
85 hookenv.status_set('maintenance', 'Installing plugins')
86 plugin_file = '/tmp/grafana-plugin.tar.gz'
87 for plugin_url in config.get('install_plugins').split(','):
88 plugin_url = plugin_url.strip()
89 hookenv.log('Downloading plugin: {!r}'.format(plugin_url))
90 with open(plugin_file, 'wb') as f:
91 r = requests.get(plugin_url, stream=True)
92 for block in r.iter_content(1024):
93 f.write(block)
94 hookenv.log('Extracting plugin: {!r}'.format(plugin_url))
95 shutil.unpack_archive(plugin_file, plugins_dir)
96 hookenv.log('Completed installing grafana plugins')
97 hookenv.status_set('active', 'Completed installing grafana plugins')
98
99
64@hook('upgrade-charm')100@hook('upgrade-charm')
65def upgrade_charm():101def upgrade_charm():
66 hookenv.status_set('maintenance', 'Forcing package update and reconfiguration on upgrade-charm')102 hookenv.status_set('maintenance', 'Forcing package update and reconfiguration on upgrade-charm')
@@ -68,7 +104,7 @@
68 remove_state('grafana.configured')104 remove_state('grafana.configured')
69105
70106
71@hook('config.changed')107@hook('config-changed')
72def config_changed():108def config_changed():
73 remove_state('grafana.configured')109 remove_state('grafana.configured')
74 config = hookenv.config()110 config = hookenv.config()
@@ -191,7 +227,7 @@
191 hookenv.status_set('maintenance', msg)227 hookenv.status_set('maintenance', msg)
192 hookenv.log(msg)228 hookenv.log(msg)
193 host.service_start(SVCNAME)229 host.service_start(SVCNAME)
194 elif any_file_changed([GRAFANA_INI]):230 elif any_file_changed([GRAFANA_INI]) or is_state('config.changed.install_plugins'):
195 msg = 'Restarting {}'.format(SVCNAME)231 msg = 'Restarting {}'.format(SVCNAME)
196 hookenv.log(msg)232 hookenv.log(msg)
197 hookenv.status_set('maintenance', msg)233 hookenv.status_set('maintenance', msg)

Subscribers

People subscribed via source and target branches