weaveworks / grafanalib

Python library for building Grafana dashboards
Apache License 2.0
1.86k stars 309 forks source link

The "mappings" values in the Panel object belong under "fieldConfig" -> "defaults" not as a key of the Panel #573

Open grantsohn opened 1 year ago

grantsohn commented 1 year ago

Look at https://play.grafana.org/d/000000012/grafana-play-home?orgId=1# and then download or view the dashboard as JSON.

    {
      "datasource": {
        ...
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            ...
          },
          "mappings": [],
          "thresholds": {
            ...
          },
          "unit": "short"
        },
        "overrides": [
          ...
        ]
      },

Search for "mappings". You will see that "mappings" belongs to "fieldConfig" -> "defaults" but your code https://github.com/weaveworks/grafanalib/blob/main/grafanalib/core.py#L3179 is placing "mappings" under the Panel dict. This is preventing the mappings from being rendered in the panel.

What you expected to happen?

mappings is supposed to work.

What happened?

mappings are not being applied to the panel.

How to reproduce it?

Download any dashboard and look for "mappings".