Charts: Can't Import Dashboard with a variable defined in the dashboard setting

Created on 23 Sep 2018  路  3Comments  路  Source: helm/charts

Is this a request for help?:


Is this a BUG REPORT or FEATURE REQUEST? (choose one): BUG

I'm trying to automate the process of provisioning datasources and dashboards into Grafana as much as possible. What I've done so far:

  • Installed Prometheus
  • Installed Grafana
  • Configured datasources using modifications in _values.yaml_ file (see below) - _This works as expected_
  • Added a configMap for a dashboard that _doesn't_ have a variable defined - _This works as expected_

  • Tried to add a configMap for a dashboard that _has_ a variable defined - _This has failed_

Version of Helm and Kubernetes:

$ helm version
Client: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.9.1", GitCommit:"20adb27c7c5868466912eebdf6664e7390ebe710", GitTreeState:"clean"}

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.0", GitCommit:"91e7b4fd31fcd3d5f436da26c980becec37ceefe", GitTreeState:"clean", BuildDate:"2018-07-10T08:39:07Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:05:37Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

Which chart:

grafana stable

What happened:

Trying to import a dashboard that has a variable defined fails.

Example dashboard (from grafana website): Kubernetes - SkyDNS

What you expected to happen:

Dashboard will show up as configMap
Instead, I get the following error:

$ helm install --debug --name grafana .
[debug] Created tunnel using local port: '50911'

[debug] SERVER: "127.0.0.1:50911"

[debug] Original chart version: ""
[debug] CHART PATH: /Users/omerbarel/Code/charts/stable/grafana

Error: parse error in "grafana/templates/cm-dashboard-skydns.yaml": template: grafana/templates/cm-dashboard-skydns.yaml:97: function "instance" not defined

How to reproduce it (as minimally and precisely as possible):

modify the following values in the default values.yaml file:

## Configure grafana datasources
## ref: http://docs.grafana.org/administration/provisioning/#datasources
##
datasources:
  datasources.yaml:
    apiVersion: 1
    datasources:
    - name: Prometheus
      type: prometheus
      url: http://kube-prometheus:9090
      access: proxy
      isDefault: true

## Configure grafana dashboard providers
## ref: http://docs.grafana.org/administration/provisioning/#dashboards
##
## `path` must be /var/lib/grafana/dashboards/<provider_name>
##
dashboardProviders:
  dashboardproviders.yaml:
    apiVersion: 1
    providers:
    - name: 'default'
      orgId: 1
      folder: ''
      type: file
      disableDeletion: false
      editable: true
      options:
        path: /var/lib/grafana/dashboards/default

## Reference to external ConfigMap per provider. Use provider name as key and ConfiMap name as value.
## A provider dashboards must be defined either by external ConfigMaps or in values.yaml, not in both.
## ConfigMap data example:
##
## data:
##   example-dashboard.json: |
##     RAW_JSON
##
dashboardsConfigMaps:
  default: "SkyDNS"

In addition, create the following conifgMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: SkyDNS
  labels:
    app: {{ template "grafana.name" . }}
    chart: {{ template "grafana.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  skydns.json: |
    {
      "__inputs": [
        {
          "name": "Prometheus",
          "label": "prometheus-k8s",
          "description": "",
          "type": "datasource",
          "pluginId": "prometheus",
          "pluginName": "Prometheus"
        }
      ],
      "__requires": [
        {
          "type": "grafana",
          "id": "grafana",
          "name": "Grafana",
          "version": "4.5.2"
        },
        {
          "type": "panel",
          "id": "graph",
          "name": "Graph",
          "version": ""
        },
        {
          "type": "datasource",
          "id": "prometheus",
          "name": "Prometheus",
          "version": "1.0.0"
        }
      ],
      "annotations": {
        "list": []
      },
      "description": "Dashboard for Kubernetes kube-dns service that uses SkyDNS",
      "editable": true,
      "gnetId": 3152,
      "graphTooltip": 1,
      "hideControls": false,
      "id": null,
      "links": [],
      "refresh": false,
      "rows": [
        {
          "collapse": false,
          "height": 250,
          "panels": [
            {
              "aliasColors": {},
              "bars": false,
              "dashLength": 10,
              "dashes": false,
              "datasource": "Prometheus",
              "fill": 1,
              "id": 1,
              "legend": {
                "alignAsTable": true,
                "avg": true,
                "current": true,
                "max": true,
                "min": false,
                "rightSide": true,
                "show": true,
                "total": false,
                "values": true
              },
              "lines": true,
              "linewidth": 1,
              "links": [],
              "nullPointMode": "null",
              "percentage": false,
              "pointradius": 5,
              "points": false,
              "renderer": "flot",
              "seriesOverrides": [],
              "spaceLength": 10,
              "span": 12,
              "stack": false,
              "steppedLine": false,
              "targets": [
                {
                  "expr": "rate(skydns_skydns_dns_cachemiss_count_total{instance=~\"$instance\"}[5m])",
                  "format": "time_series",
                  "interval": "",
                  "intervalFactor": 2,
                  "legendFormat": "{{instance}}",
                  "metric": "skydns_skydns_dns_cachemiss_count_total",
                  "refId": "A",
                  "step": 40
                }
              ],
              "thresholds": [],
              "timeFrom": null,
              "timeShift": null,
              "title": "Cachemiss Rate",
              "tooltip": {
                "shared": true,
                "sort": 0,
                "value_type": "individual"
              },
              "type": "graph",
              "xaxis": {
                "buckets": null,
                "mode": "time",
                "name": null,
                "show": true,
                "values": []
              },
              "yaxes": [
                {
                  "format": "short",
                  "label": null,
                  "logBase": 1,
                  "max": null,
                  "min": null,
                  "show": true
                },
                {
                  "format": "short",
                  "label": null,
                  "logBase": 1,
                  "max": null,
                  "min": null,
                  "show": true
                }
              ]
            }
          ],
          "repeat": null,
          "repeatIteration": null,
          "repeatRowId": null,
          "showTitle": false,
          "title": "Dashboard Row",
          "titleSize": "h6"
        },
        {
          "collapse": false,
          "height": 250,
          "panels": [
            {
              "aliasColors": {},
              "bars": false,
              "dashLength": 10,
              "dashes": false,
              "datasource": "Prometheus",
              "fill": 1,
              "id": 2,
              "legend": {
                "alignAsTable": true,
                "avg": true,
                "current": true,
                "max": true,
                "min": false,
                "rightSide": true,
                "show": true,
                "total": false,
                "values": true
              },
              "lines": true,
              "linewidth": 1,
              "links": [],
              "nullPointMode": "null",
              "percentage": false,
              "pointradius": 5,
              "points": false,
              "renderer": "flot",
              "seriesOverrides": [],
              "spaceLength": 10,
              "span": 12,
              "stack": false,
              "steppedLine": false,
              "targets": [
                {
                  "expr": "rate(skydns_skydns_dns_error_count_total{instance=~\"$instance\"}[5m])",
                  "format": "time_series",
                  "intervalFactor": 2,
                  "legendFormat": "{{instance}}",
                  "metric": "skydns_skydns_dns_error_count_total",
                  "refId": "A",
                  "step": 40
                }
              ],
              "thresholds": [],
              "timeFrom": null,
              "timeShift": null,
              "title": "Error Count Rate",
              "tooltip": {
                "shared": true,
                "sort": 0,
                "value_type": "individual"
              },
              "type": "graph",
              "xaxis": {
                "buckets": null,
                "mode": "time",
                "name": null,
                "show": true,
                "values": []
              },
              "yaxes": [
                {
                  "format": "short",
                  "label": null,
                  "logBase": 1,
                  "max": null,
                  "min": null,
                  "show": true
                },
                {
                  "format": "short",
                  "label": null,
                  "logBase": 1,
                  "max": null,
                  "min": null,
                  "show": true
                }
              ]
            }
          ],
          "repeat": null,
          "repeatIteration": null,
          "repeatRowId": null,
          "showTitle": false,
          "title": "Dashboard Row",
          "titleSize": "h6"
        },
        {
          "collapse": false,
          "height": 250,
          "panels": [
            {
              "aliasColors": {},
              "bars": false,
              "dashLength": 10,
              "dashes": false,
              "datasource": "Prometheus",
              "fill": 1,
              "id": 3,
              "legend": {
                "avg": false,
                "current": false,
                "max": false,
                "min": false,
                "show": true,
                "total": false,
                "values": false
              },
              "lines": true,
              "linewidth": 1,
              "links": [],
              "nullPointMode": "null",
              "percentage": false,
              "pointradius": 5,
              "points": false,
              "renderer": "flot",
              "seriesOverrides": [],
              "spaceLength": 10,
              "span": 6,
              "stack": false,
              "steppedLine": false,
              "targets": [
                {
                  "expr": "rate(skydns_skydns_dns_request_count_total{instance=~\"$instance\"}[5m])",
                  "format": "time_series",
                  "interval": "",
                  "intervalFactor": 2,
                  "legendFormat": "{{instance}}",
                  "metric": "skydns_skydns_dns_request_count_total",
                  "refId": "A",
                  "step": 60
                }
              ],
              "thresholds": [],
              "timeFrom": null,
              "timeShift": null,
              "title": "Request",
              "tooltip": {
                "shared": true,
                "sort": 0,
                "value_type": "individual"
              },
              "type": "graph",
              "xaxis": {
                "buckets": null,
                "mode": "time",
                "name": null,
                "show": true,
                "values": []
              },
              "yaxes": [
                {
                  "format": "short",
                  "label": null,
                  "logBase": 1,
                  "max": null,
                  "min": null,
                  "show": true
                },
                {
                  "format": "short",
                  "label": null,
                  "logBase": 1,
                  "max": null,
                  "min": null,
                  "show": true
                }
              ]
            },
            {
              "aliasColors": {},
              "bars": false,
              "dashLength": 10,
              "dashes": false,
              "datasource": "Prometheus",
              "fill": 1,
              "id": 4,
              "legend": {
                "avg": false,
                "current": false,
                "max": false,
                "min": false,
                "show": true,
                "total": false,
                "values": false
              },
              "lines": true,
              "linewidth": 1,
              "links": [],
              "nullPointMode": "null",
              "percentage": false,
              "pointradius": 5,
              "points": false,
              "renderer": "flot",
              "seriesOverrides": [],
              "spaceLength": 10,
              "span": 6,
              "stack": false,
              "steppedLine": false,
              "targets": [
                {
                  "expr": "sum(skydns_skydns_dns_request_duration_seconds_sum{instance=~\"$instance\"}) by (system)",
                  "format": "time_series",
                  "interval": "",
                  "intervalFactor": 2,
                  "legendFormat": "{{system}}",
                  "metric": "skydns_skydns_dns_request_duration_seconds_sum",
                  "refId": "A",
                  "step": 60
                }
              ],
              "thresholds": [],
              "timeFrom": null,
              "timeShift": null,
              "title": "Request Duration Seconds",
              "tooltip": {
                "shared": true,
                "sort": 0,
                "value_type": "individual"
              },
              "type": "graph",
              "xaxis": {
                "buckets": null,
                "mode": "time",
                "name": null,
                "show": true,
                "values": []
              },
              "yaxes": [
                {
                  "format": "short",
                  "label": null,
                  "logBase": 1,
                  "max": null,
                  "min": null,
                  "show": true
                },
                {
                  "format": "short",
                  "label": null,
                  "logBase": 1,
                  "max": null,
                  "min": null,
                  "show": true
                }
              ]
            }
          ],
          "repeat": null,
          "repeatIteration": null,
          "repeatRowId": null,
          "showTitle": false,
          "title": "Dashboard Row",
          "titleSize": "h6"
        }
      ],
      "schemaVersion": 14,
      "style": "dark",
      "tags": [
        "K8s",
        "DNS"
      ],
      "templating": {
        "list": [
          {
            "allValue": null,
            "current": {},
            "datasource": "Prometheus",
            "hide": 0,
            "includeAll": true,
            "label": null,
            "multi": false,
            "name": "instance",
            "options": [],
            "query": "label_values(skydns_skydns_dns_cachemiss_count_total, instance)",
            "refresh": 1,
            "regex": "",
            "sort": 0,
            "tagValuesQuery": "",
            "tags": [],
            "tagsQuery": "",
            "type": "query",
            "useTags": false
          }
        ]
      },
      "time": {
        "from": "now-12h",
        "to": "now"
      },
      "timepicker": {
        "collapse": false,
        "enable": true,
        "notice": false,
        "now": true,
        "refresh_intervals": [
          "5s",
          "10s",
          "30s",
          "1m",
          "5m",
          "15m",
          "30m",
          "1h",
          "2h",
          "1d"
        ],
        "status": "Stable",
        "time_options": [
          "5m",
          "15m",
          "1h",
          "6h",
          "12h",
          "24h",
          "2d",
          "7d",
          "30d"
        ],
        "type": "timepicker"
      },
      "timezone": "browser",
      "title": "Kubernetes - SkyDNS",
      "version": 3
    }

Anything else we need to know:
I understand this maybe more of a _Helm_ problem than a _Grafana_ problem. However, I opened this with regards to Grafana since this is more in the context of a _dashboard import process_ so I thought it's more relevant here

Thank you for any input or assistance on that process
Omer

Most helpful comment

Hi
No, this didn't work. I had to import it as .json config:
For future readers, this is what I did:

  • Created configMap that imports the .json file as config:
apiVersion: v1
kind: ConfigMap
metadata:
  name: all-nodes-dashboard
  labels:
    app: {{ template "grafana.name" . }}
    chart: {{ template "grafana.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
{{ (.Files.Glob "dashboards/all-nodes_rev1.json").AsConfig | indent 2 }}
  • Modified the main chart values.yaml:
dashboardProviders:
  dashboardproviders.yaml:
    apiVersion: 1
    providers:
    - name: 'ds1'
      orgId: 1
      folder: ''
      type: file
      disableDeletion: false
      editable: true
      options:
        path: /var/lib/grafana/dashboards/ds1
    - name: 'ds2'
      orgId: 1
      folder: ''
      type: file
      disableDeletion: false
      editable: true
      options:
        path: /var/lib/grafana/dashboards/ds2

dashboardsConfigMaps:
  ds1: "all-nodes-dashboard"
  ds2: "skydns"

And now I have the 2 dashboards in grafana when it loads

All 3 comments

Can't you just use the import job?

dashboards:
  default:
    Sky-dns:
      gnetId: 3152
      revision: 2
      datasource: Prometheus

Hi
No, this didn't work. I had to import it as .json config:
For future readers, this is what I did:

  • Created configMap that imports the .json file as config:
apiVersion: v1
kind: ConfigMap
metadata:
  name: all-nodes-dashboard
  labels:
    app: {{ template "grafana.name" . }}
    chart: {{ template "grafana.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
{{ (.Files.Glob "dashboards/all-nodes_rev1.json").AsConfig | indent 2 }}
  • Modified the main chart values.yaml:
dashboardProviders:
  dashboardproviders.yaml:
    apiVersion: 1
    providers:
    - name: 'ds1'
      orgId: 1
      folder: ''
      type: file
      disableDeletion: false
      editable: true
      options:
        path: /var/lib/grafana/dashboards/ds1
    - name: 'ds2'
      orgId: 1
      folder: ''
      type: file
      disableDeletion: false
      editable: true
      options:
        path: /var/lib/grafana/dashboards/ds2

dashboardsConfigMaps:
  ds1: "all-nodes-dashboard"
  ds2: "skydns"

And now I have the 2 dashboards in grafana when it loads

thanks @jungopro, this works for me!

One thing I would emphasize, the ".json" to import into a configmap must be in the chart but not the templates directory. I had to scratch my head for awhile to notice that!

Was this page helpful?
0 / 5 - 0 ratings