this charm requires dashboard json files to nest data under key `dashboard` by mistake

Bug #1897843 reported by Joe Guo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Grafana Charm
High
Joe Guo

Bug Description

this charm requires dashboard json files to nest data under key `dashboard` by mistake

According to grafana JSON model doc[0], dashboard JSON is supposed to be in following format:

{
  "id": null,
  "uid": "cLV5GDCkz",
  "title": "New dashboard",
  "tags": [],
  "style": "dark",
  "timezone": "browser",
  "editable": true,
  "hideControls": false,
  "graphTooltip": 1,
  "panels": [...],
  ...
}

All the dashboard json files you can download from official website https://grafana.com/grafana/dashboards are in this format.

However, in function `lib/charms/layer/grafana.py:import_dashboard`:

    def import_dashboard(dashboard, remote_app=None, name=None):
        ...
        dashboard["dashboard"]["title"] = compute_dash_title(
            dashboard["dashboard"].get("title"), remote_app
        )

        dashboard["folderId"] = ensure_and_get_dash_folder(dashboard.get("source_model"))
        if name is None:
            name = dashboard["dashboard"].get("title") or "Untitled"
        return post_dashboard(name, dashboard)

It's assuming the dashboard JSON nests data under key `dashboard`.
This function is used by both the dashboard relation and `import-dashboard` action.
And most of the dashboard json files in our charms follow that requirement, to comply with grafana-charm.

It seems this mistake is caused by a misread of grafana rest api[1]:
it does requires data to be wrapped under key `dashboard`:

{
    "dashboard": {
        "id": 104,
        "panels": [...],
        ...
     },
     "overwrite": true,
     "folderId": "xxx",
     ...
}

But that's for rest api request only, not meant for json file content.

The consequences of this bug:

dashboard json files in our charms are not compatible with official ones, we have a extra `dashboard` wrapper
if we try to import a correct/official dashboard, we will get keyerror in log:

tracer: ++ queue handler reactive/grafana.py:549:wipe_nrpe_checks
unit-grafana-0: 09:57:15 INFO unit.grafana/0.juju-log Invoking reactive handler: reactive/grafana.py:549:wipe_nrpe_checks
unit-grafana-0: 09:57:15 INFO unit.grafana/0.juju-log Invoking reactive handler: hooks/relations/http/provides.py:15:broken:website
unit-grafana-0: 09:57:18 INFO unit.grafana/0.juju-log DEPRECATION WARNING: Function action_get is being removed : moved to function_get()
unit-grafana-0: 09:57:19 DEBUG unit.grafana/0.import-dashboard Traceback (most recent call last):
unit-grafana-0: 09:57:19 DEBUG unit.grafana/0.import-dashboard File "/var/lib/juju/agents/unit-grafana-0/charm/actions/import-dashboard", line 40, in <module>
unit-grafana-0: 09:57:19 DEBUG unit.grafana/0.import-dashboard import_dashboard(d)
unit-grafana-0: 09:57:19 DEBUG unit.grafana/0.import-dashboard File "/var/lib/juju/agents/unit-grafana-0/charm/lib/charms/layer/grafana.py", line 149, in import_dashboard
unit-grafana-0: 09:57:19 DEBUG unit.grafana/0.import-dashboard dashboard["dashboard"].get("title"), remote_app
unit-grafana-0: 09:57:19 DEBUG unit.grafana/0.import-dashboard KeyError: 'dashboard'
unit-prometheus2-0: 09:57:29 INFO unit.prometheus2/0.juju-log Reactive main running for hook update-status
unit-prometheus2-0: 09:57:29 DEBUG unit.prometheus2/0.juju-log tracer>
tracer: set flag config.default.snap_proxy

[0]: https://grafana.com/docs/grafana/latest/reference/dashboard/#dashboard-json
[1]: https://grafana.com/docs/grafana/latest/http_api/dashboard/#create--update-dashboard

Related branches

Joe Guo (guoqiao)
Changed in charm-grafana:
importance: Undecided → High
Joe Guo (guoqiao)
Changed in charm-grafana:
status: New → In Progress
assignee: nobody → Joe Guo (guoqiao)
Alvaro Uria (aluria)
Changed in charm-grafana:
milestone: none → 20.10
status: In Progress → Fix Committed
Linda Guo (lihuiguo)
Changed in charm-grafana:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers