Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dashboards.<name>.file creates empty ConfigMap #27

Open
mozai opened this issue Sep 23, 2020 · 9 comments
Open

dashboards.<name>.file creates empty ConfigMap #27

mozai opened this issue Sep 23, 2020 · 9 comments

Comments

@mozai
Copy link

mozai commented Sep 23, 2020

In the documentation for Import dashboards it gives this example for importing a file from local filesystem (near the values.yaml file, I would assume).

dashboards:
  default:
    custom-dashboard:
      # This is a path to a file inside the dashboards directory inside the chart directory
      file: dashboards/custom-dashboard.json

When trying this myself with helm2 and helm3, it results in a ConfigMap with empty values.

Below are the steps I took when trying to use this feature of the helmchart.

dashboards:
  default:
    Prometheus:
      datasource: default
      gnetId: 2
      revision: 2
    empty-dashboard:
      file: dashboards/empty-dashboard.json
    prometheus-alerts-firing:
      file: dashboards/prometheus-alerts-firing.json

empty-dashboard.json is just {} which is a copy of the example "dashboards/custom-dashboard.json" already in this git repository.

$ wc -c values.yaml dashboards/empty-dashboard.json dashboards/prometheus-alerts-firing.json
 6852 values.yaml
    3 dashboards/empty-dashboard.json
24251 dashboards/prometheus-alerts-firing.json

Launching helm install --dry-run grafana grafana/grafana -f values.yaml --debug shows the ConfigMap that would be sent to the cluster would have empty values for the dashboards, instead of the file contents.

---
# Source: grafana/templates/dashboards-json-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: grafana-dashboards-default
  namespace: default
  labels:
    helm.sh/chart: grafana-5.6.7
    app.kubernetes.io/name: grafana
    app.kubernetes.io/instance: grafana
    app.kubernetes.io/version: "7.1.5"
    app.kubernetes.io/managed-by: Helm
    dashboard-provider: default
data:
  empty-dashboard.json:
    ""
  prometheus-alerts-firing.json:
    ""

If I install this without the --dry-run the ConfigMap I find is indeed empty, and grafana complains about being unable to load these dashboards.

Bizarrely, if I add custom-dashboard: {file: dashboards/custom-dashboard.json} exactly as it appears in the example documentation, this results in a non-empty ConfigMap, even though there is no such file "dashboards/custom-dashboard.json" on my local filesystem.

Maybe the {{.Files.Get "filename"}} in the template cannot access files outside of the helmchart package itself?

@dry4ng
Copy link

dry4ng commented Oct 28, 2020

Same issue here.

@tzouin
Copy link

tzouin commented Nov 3, 2020

Even using a dashboard id i have an empty configmap

  dashboards:
    default:
      sample-dashboard:
        datasource: default
        gnetId: 11056
        revision: 1
#kubectl describe  cm/prometheus-stack-grafana-dashboards-default -n monitoring
Name:         prometheus-stack-grafana-dashboards-default
Namespace:    monitoring
Labels:       app.kubernetes.io/instance=prometheus-stack
              app.kubernetes.io/managed-by=Helm
              app.kubernetes.io/name=grafana
              app.kubernetes.io/version=7.2.1
              dashboard-provider=default
              helm.sh/chart=grafana-5.8.16
Annotations:  meta.helm.sh/release-name: prometheus-stack
              meta.helm.sh/release-namespace: monitoring

Data
====
Events:  <none>

@benc-uk
Copy link

benc-uk commented Dec 6, 2020

Same
I can't see any way to import dashboards using the dashboards: value

And I'm really struggling to create a config map holding the dashboard defintion, as I'm using Helm and the {{ and }} sequences are causing a nightmare

unguiculus added a commit to unguiculus/grafana-helm-charts that referenced this issue Dec 9, 2020
unguiculus added a commit to unguiculus/grafana-helm-charts that referenced this issue Dec 10, 2020
@uvw
Copy link

uvw commented Dec 12, 2020

I only used sidecar provisioning provided by this chart before. But today, I just wanted to install a minimal Grafana instance without sidecars and with a few file and imported dashboards. I spent like an hour figuring out what’s going on 😒

File-based dashboards:

@mozai, I believe you are right about the template not being able to access files outside of the chart package: there is an old open issue in the Helm repo.
As for bizarre dashboards/custom-dashboard.json, I guess it works because this file is part of the chart itself. I am wondering if this feature ever worked as intended.

On the bright side, sidecar-injected dashboards and datasources seem to be working great.

Imported dashboards (gnetId):

@tzouin, I think your issue is different. There is another config map containing a generated script to download gnetId dashboards. The config map should be named after the helm release you installed (likely, configmaps/prometheus-stack-grafana).

The reason it did not work is that the chart does not define a default dashboard provider. I had to define a matching provider in values as well, e.g.:

dashboardProviders:
  dashboardproviders.yaml:
    apiVersion: 1
    providers:
    - name: istio
      orgId: 1
      folder: Istio
      type: file
      options:
        path: /var/lib/grafana/dashboards/istio
dashboards:
  istio: # this key should match the provider name above
    mesh:
      gnetId: 7639
      revision: 43
      datasource: default
    #...

@tzouin
Copy link

tzouin commented Feb 15, 2021

@uvw i missed your answer but that's it ! Thanks you

@slavonicsniper
Copy link

Same issue here.

@g-linville
Copy link

I see there have been no comments on here in a while, and I mentioned this over on #764, but one way you can work around this is using --set-file to basically just inject the JSON into the values without maintaining an enormous values file:

helm install releasename grafana/grafana -f my_values.yaml --set-file dashboards.default.dashboard-name.json=my-dashboard.json

@muzammil360
Copy link

muzammil360 commented Dec 29, 2023

@uvw, thanks for the detailed comment above. It was really useful to me. As per your advice, I am trying to add a dashboard using sidecar approach. The dashboard is added to grafana but I am unable to over-ride the datasource.

Here is how i was able to over-ride the datasource for opensource dashboards. But when it comes to sidecar, It doesn't seem to be able to take in datasource. Any suggestions will be welcome!

    dashboards:
      default:
        kubernetes-monitoring-dashboard:
          gnetId: 12740 # https://grafana.com/grafana/dashboards/12740-kubernetes-monitoring/
          revision: 1
          datasource: MydatasourceName  

@LozanoMatheus
Copy link

LozanoMatheus commented Apr 6, 2024

I think this ticket is duplicated with the #2596.

As far as I could debug, it seems the ConfigMap that reads the file, is actually only checking for the file in the Helm package. So, it only reads this file.

If you clone this repo and try to deploy locally, like

helm upgrade \
    --atomic \
    --timeout 2m \
    --cleanup-on-fail \
    --force \
    --install grafana \
    -f values.yaml \
    ./

Then it will work fine, but if you point it to grafana/grafana then it only gets the file that comes with the Helm package (custom-dashboard.json).

I couldn't find a way to get this. I'll open a ticket with Helm to see if they know how to do it and I'll share it here. The issue opened with the Helm docs here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants