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

GrafanaDashboard syncing from url and replacing variables on the go #1760

Open
toporek3112 opened this issue Nov 14, 2024 · 2 comments
Open
Labels
enhancement New feature or request triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@toporek3112
Copy link

Is your feature request related to a problem? Please describe.
As platform engineers me and my collegues want to provide our customers with some standardized dashboards where our customers can only access their target cluster and namespace. For that we created a template dashboard which we store in git. Now we would like to create a kubernetes manifest GrafanaDashboard which takes in a url to the template dashboard json and substitutes some values on the go in the kubernetes manifest. Currently we have to create a seperate json file for each request where we need to change the query by hand. This is error prone and tidiouse if we want to update the "standardized" dashbaord

(If applicable)If your feature request solves a bug please provide a link to the community issue

Describe the solution you'd like
When I create a GrafanaDashboard I would like to be able to substitute some variables in the dashbaord.json. Example

      apiVersion: grafana.integreatly.org/v1beta1
      kind: GrafanaDashboard
      metadata:
        name: customer-dashboard.team-xyz
        namespace: monitoring
      spec:
        folder: Team-xyz
        instanceSelector:
          matchLabels:
            app.kubernetes.io/name: grafana-operator
        resyncPeriod: 10s
        url: https://raw.githubusercontent.com/blabla/dashbaord-template.json
        urlAuthorization:
          basicAuth:
            password:
              name: secret
              key: password
            username:
              name: secret
              key: username
         substituteVars:
           - varName1: "value1"
           - varName2: "value2"

Describe alternatives you've considered
Alternatives are to create a seperate dashboard.json and then a kubernetes manifest of GrafanaDashboard. With the approache described above we could have one central template and multiple GrafanaDashbaord's which synch with that one url and substitute variables on the go.

Additional context
n/a

Existing solutions
n/a

Would be a really nice feature to the operator. Please let me know what you think of this. BR.

@toporek3112 toporek3112 added enhancement New feature or request needs triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 14, 2024
@KaiseerKenopsia
Copy link

Wouldn't a helm template be enough to solve your problem?

Put your vars into Values and then you can iterate over them with a 'range' loop, golang can iterate well over dicts and lists, so the differing-imported vars can have any yaml structure you want.


Go docs can be hard to understand sometimes so here is a 'range' example:
https://stackoverflow.com/questions/54156119/range-over-string-slice-in-golang-template

If you dig around the templates folder in helm chart, you'll be probably able to reverse engineer the rest

@theSuess
Copy link
Member

theSuess commented Nov 25, 2024

I've investigated this a bit and found a way to do this which is officially supported by Grafana (albeit, not very well documented).

By using the __inputs field in the Dashboard specification and the /api/dashboards/import endpoint, arbitrary variables can be replaced in a dashboard specification.

I'm open to adding this as a feature to the operator but would like to hear other opinions on this

@theSuess theSuess added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

No branches or pull requests

3 participants