Merge charm-grafana:dashboard-json into charm-grafana:master

Proposed by Joe Guo
Status: Merged
Approved by: Adam Dyess
Approved revision: 5c5a449244ae995995dc6c4814d3e2e187647f62
Merged at revision: 239f891810ed9f7afee1c28de74967aa1b4c6bd8
Proposed branch: charm-grafana:dashboard-json
Merge into: charm-grafana:master
Diff against target: 63 lines (+27/-8)
2 files modified
src/lib/charms/layer/grafana.py (+26/-8)
src/wheelhouse.txt (+1/-0)
Reviewer Review Type Date Requested Status
Adam Dyess (community) Approve
James Hebden (community) Approve
Review via email: mp+391653@code.launchpad.net

Commit message

Fix LP1897843: support non-wrapped JSON data and keep backward compatibility

Currently this charm requires dashboard JSON data be wrapped like this:

    {
        "dashbaord": {<real dashboard JSON data>},
        "overwrite": true,
        "folderId": 1
    }

Actually this is a misuse of the grafana rest api structure.
Dashboard JSON data should include the real data directly.
Refer to LP1897843 for details.

This patch make the code support both formats.
Since most of our dashboard JSON file followed the wrong pattern, we
have to keep backward compatibility until grafana charm upgraded in all clouds.

LP: #1897843

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

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

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

See comments inline

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

log removed and re-pushed.

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

LGTM

review: Approve
Revision history for this message
Adam Dyess (addyess) wrote :

LGTM2

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

Change successfully merged at revision 239f891810ed9f7afee1c28de74967aa1b4c6bd8

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/lib/charms/layer/grafana.py b/src/lib/charms/layer/grafana.py
index ecd8c69..009c812 100644
--- a/src/lib/charms/layer/grafana.py
+++ b/src/lib/charms/layer/grafana.py
@@ -132,7 +132,7 @@ def post_dashboard(name, dashboard):
132 )132 )
133133
134134
135def import_dashboard(dashboard, remote_app=None, name=None):135def import_dashboard(dashboard, remote_app=None, name=None, overwrite=True):
136 """Process and import a dashboard.136 """Process and import a dashboard.
137137
138 Will update dashboard title if the dashboard is provided over a remote138 Will update dashboard title if the dashboard is provided over a remote
@@ -146,16 +146,34 @@ def import_dashboard(dashboard, remote_app=None, name=None):
146 :param remote_app: name of remote app for dashes provided over relation146 :param remote_app: name of remote app for dashes provided over relation
147 :param remote_model: if dash is provided over CMR, name of remote model147 :param remote_model: if dash is provided over CMR, name of remote model
148 :param name: dash internal name148 :param name: dash internal name
149 :param overwrite: if True, overwrite existing dashboard with same id
149 :return: None150 :return: None
150 """151 """
151 dashboard["dashboard"]["title"] = compute_dash_title(152 if "dashboard" in dashboard:
152 dashboard["dashboard"].get("title"), remote_app153 # bug LP1897843: dashboard json data is wrapped in {"dashboard": {<data>}}
153 )154 dashboard["dashboard"]["title"] = compute_dash_title(
155 dashboard["dashboard"].get("title"), remote_app
156 )
154157
155 dashboard["folderId"] = ensure_and_get_dash_folder(dashboard.get("source_model"))158 dashboard["folderId"] = ensure_and_get_dash_folder(
156 if name is None:159 dashboard.get("source_model")
157 name = dashboard["dashboard"].get("title") or "Untitled"160 )
158 return post_dashboard(name, dashboard)161 if name is None:
162 name = dashboard["dashboard"].get("title") or "Untitled"
163 return post_dashboard(name, dashboard)
164 else:
165 # correct data
166 dashboard["title"] = compute_dash_title(dashboard.get("title"), remote_app)
167
168 folder_id = ensure_and_get_dash_folder(dashboard.get("source_model"))
169 data = {
170 "dashboard": dashboard,
171 "folderId": folder_id,
172 "overwrite": overwrite,
173 }
174 if name is None:
175 name = dashboard.get("title") or "Untitled"
176 return post_dashboard(name, data)
159177
160178
161def get_cmd_output(cmd, shell=False):179def get_cmd_output(cmd, shell=False):
diff --git a/src/wheelhouse.txt b/src/wheelhouse.txt
index ffdadef..ebe0ec6 100644
--- a/src/wheelhouse.txt
+++ b/src/wheelhouse.txt
@@ -1,2 +1,3 @@
1setuptools
1requests2requests
2jsondiff3jsondiff

Subscribers

No one subscribed via source and target branches