Merge charm-grafana:dashboards_joined into charm-grafana:master

Proposed by Joe Guo
Status: Merged
Approved by: Joe Guo
Approved revision: 6ab6bed6082347fbc5f92fa703b3118f21da60a0
Merged at revision: c632b1fde22240963c81f338208d4d226638045a
Proposed branch: charm-grafana:dashboards_joined
Merge into: charm-grafana:master
Diff against target: 36 lines (+25/-0)
1 file modified
src/reactive/ (+25/-0)
Reviewer Review Type Date Requested Status
James Hebden (community) Approve
Xav Paice Approve
Review via email:

Commit message

add dashboards-joined hook

when relate an operator based charm, e.g.: cloudstats, to grafana, this hook won't trigger:

    @when("grafana.started", "endpoint.dashboards.has_requests")
    def import_dashboards(dashboards):

So dashboard will not be imported and there is no error.

Add a normal `joined` hook, query relation data directly with key, so operator based
charm can relate to grafana and import dashboard.

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

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

Revision history for this message
Xav Paice (xavpaice) wrote :

We need to add in a @reactive.when_not("is-update-status-hook") otherwise this will fire for every update-status.

Otherwise, +1 from me.

review: Needs Fixing
Revision history for this message
Joe Guo (guoqiao) wrote :

change `when` decorators to `@hook("dashboards-relation-joined")`
So it will only be triggered when relation joined.

Revision history for this message
Xav Paice (xavpaice) wrote :


review: Approve
Revision history for this message
Joe Guo (guoqiao) wrote :

tested in local juju env, working as expected.

Revision history for this message
Joe Guo (guoqiao) wrote :

the `dashboards` arg is required by the `reactive.hook` decorator, otherwise it raised an error for missing args.
Although it's not used in code and not recommended by doc.

Revision history for this message
James Hebden (ec0) wrote :


review: Approve
Revision history for this message
Canonical IS Mergebot (canonical-is-mergebot) wrote :

Change successfully merged at revision c632b1fde22240963c81f338208d4d226638045a

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/reactive/ b/src/reactive/
2index 553238c..b0a3bff 100644
3--- a/src/reactive/
4+++ b/src/reactive/
5@@ -1157,6 +1157,31 @@ def ensure_dash_deserialized(dash):
6 return dash
10+def dashboards_joined(dashboards):
11+ hookenv.log("hook %s triggered" % hookenv.hook_name(), "INFO")
13+ remote_unit = os.environ.get('JUJU_REMOTE_UNIT', None)
14+ if not remote_unit:
15+ hookenv.log("remote_unit is None, return", "WARNING")
16+ return
18+ dashboard_str = hookenv.relation_get('dashboard', remote_unit) # json str
19+ if not dashboard_str:
20+ hookenv.log("dashboard field is empty, return", "WARNING")
21+ return
23+ dashboard = ensure_dash_deserialized(dashboard_str)
24+ name = hookenv.relation_get('name', remote_unit) # dashboard name
25+ remote_app = hookenv.remote_service_name()
27+ success, reason = import_dashboard(dashboard, remote_app=remote_app, name=name)
28+ if success:
29+ hookenv.log("import_dashboard {} success".format(name), "INFO")
30+ else:
31+ hookenv.log("import_dashboard {} failed: {}".format(name, reason), "ERROR")
34 @when("grafana.started", "endpoint.dashboards.has_requests")
35 @when_not("grafana.change-block")
36 def import_dashboards(dashboards):


People subscribed via source and target branches

to all changes: