grafana / helm-charts

Apache License 2.0
1.67k stars 2.29k forks source link

Grafana Dashboard Provisioning Error: "Dashboard title cannot be empty" Despite Correct JSON Format and File Mounting #3224

Open robronayne opened 4 months ago

robronayne commented 4 months ago

Issue Summary

I am experiencing an issue with deploying a Grafana dashboard using Helm in a Kubernetes environment. Despite correctly formatting and mounting the JSON file for a dashboard, Grafana fails to load the dashboard, reporting that the "Dashboard title cannot be empty".

Environment

Kubernetes Cluster: K3S Raspberry Pi cluster Grafana Deployment: Using Helm Namespace: monitoring

Problem Details

The problem appears to be that Grafana fails to recognize the dashboard JSON file, even though it is correctly formatted and placed in the correct directory.

Configurations

grafana/templates/grafana-dashboards.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-dashboards
  namespace: monitoring
  labels:
    grafana_dashboard: "1"
data:
  pi-cluster-health.json: |-
    {{ .Files.Get "dashboards/pi-cluster-health.json" | indent 4 }}

grafana/dashboards/grafana-dashboards.yaml

{
    "dashboard": {
        "id": null,
        "title": "Raspberry Pi Cluster Health",
        "panels": [
            {
                "type": "graph",
                "title": "CPU Usage",
                "targets": [
                    {
                        "expr": "100 - (avg by(instance) (rate(node_cpu_seconds_total{mode='idle'}[5m])) * 100)",
                        "legendFormat": "{{`{{ instance }}`}}",
                        "refId": "A"
                    }
                ],
                "yaxes": [
                    {
                        "format": "percent",
                        "label": "CPU Usage",
                        "min": 0,
                        "max": 100
                    }
                ],
                "xaxis": {
                    "show": true
                },
                "gridPos": {
                    "h": 9,
                    "w": 12,
                    "x": 0,
                    "y": 0
                }
            }
        ],
        "schemaVersion": 16,
        "version": 0,
        "refresh": "5s"
    }
}

Verification Steps

ConfigMap Verification

Verified that the ConfigMap is correctly created and contains the JSON:

kubectl get configmap grafana-dashboards -n monitoring -o yaml

Output:

apiVersion: v1
data:
  pi-cluster-health.json: |-
    {
      "dashboard": {
        "id": null,
        "title": "Raspberry Pi Cluster Health",
        ...
    }

File Verification in Pod

Verified that the JSON file is correctly mounted in the Grafana pod:

kubectl exec -it <grafana-pod> -n monitoring -- /bin/sh
cat /var/lib/grafana/dashboards/pi-cluster-health.json

Output:

{
  "dashboard": {
    "id": null,
    "title": "Raspberry Pi Cluster Health",
    ...
}

Grafana Logs

Checked Grafana logs for errors:

kubectl logs -l app=grafana -n monitoring

Output:

logger=provisioning.dashboard type=file name=default t=2024-07-11T02:33:51.503463709Z level=error msg="failed to load dashboard from " file=/var/lib/grafana/dashboards/pi-cluster-health.json error="Dashboard title cannot be empty"

Observations

Despite the JSON file being correctly formatted and placed, Grafana logs indicate that the "Dashboard title cannot be empty". The title is clearly defined in the JSON file.

Request for Help

I am seeking assistance to resolve this issue where Grafana fails to recognize and load the dashboard JSON file, even though it is correctly formatted and placed in the specified directory. Any insights or solutions would be greatly appreciated.

MateuszBedkowski commented 3 months ago

Hey, I think I found the solution. I had similar problem but I took it out of the nesting, if you know what I mean...

Basically I just started with curly bracket: "{" and then started with "title" etc. (there is no dashboard field) and end the config with "}". After that I've started container and I've got my dashboard.

Please try that:

{ "id": null, "title": "Raspberry Pi Cluster Health", "panels": [ { "type": "graph", "title": "CPU Usage", "targets": [ { "expr": "100 - (avg by(instance) (rate(node_cpu_seconds_total{mode='idle'}[5m])) * 100)", "legendFormat": "{{{{ instance }}}}", "refId": "A" } ], "yaxes": [ { "format": "percent", "label": "CPU Usage", "min": 0, "max": 100 } ], "xaxis": { "show": true }, "gridPos": { "h": 9, "w": 12, "x": 0, "y": 0 } } ], "schemaVersion": 16, "version": 0, "refresh": "5s" }