Variables in Dashboard
Variables in Dashboard
Problem to solve
We need to be able to define variables in our dashboards. This feature is similar to variables in Grafana.
A user would then be able to choose/specify values for the variables in a dashboard on the UI. This will make dashboards more versatile and useful. For example, this would allow a dashboard to display metrics from whichever environment a user wants.
Without this feature, we would need to define separate dashboards per environment. The dashboards would have the exact same queries, but with a different environment
label.
It would also make it easier to replicate Grafana dashboards within Gitlab.
Intended users
Further details
The Prometheus proxy API currently supports variables with single-values.
We need to:
- Select a format for defining variables in dashboard yaml files.
- On the frontend, we will need to display dropdowns/textboxes for each variable, which will allow the user to choose/specify a value for each variable.
- When a variable value is changed, the charts need to reload.
Grafana's use-case for having variables inside a promQL query is to change label values from the queries without having to write multiple dashboards for queries that don't change its structure but they do change the label values. To change the values Grafana has a handy dropdown section
These dropdown boxes are generated depending on the number of variables set in the JSON schema, as for how the dropdown boxes are populated it seems to be directly from the data store, in this case Prometheus, that provides the values for each of the labels that conform the query.
To add to this feature, we need to refresh the dashboard every time a value is changed from any of the dropdown boxes. Finally depending on the number of arguments, the number of dropdown boxes might overflow so we need to account for that.
Iteration Breakdown
- MVC1 enables the URL param variable that can be used in the PromQL Query
- MVC2 loads the variables in the dashboard.yml into the Metrics Dashboard
- MVC3 enables variables to be pulled from a predefined PromQL Query from dashboard.yml
- Show closed items