Add support for variables with hard-coded values to be defined in metrics dashboard yaml files

Problem to solve

We need to be able to define variables in our dashboards. This feature is similar to variables in Grafana.

Intended users

Further details

In this issue, we will allow simple variables where all the possible values for the variable are listed in the dashboard yaml itself.

This has limited use in real life, but is a good start towards supporting variables on dashboards.

Proposal

The following should be added to a dashboard in order for the dashboard to have template variables. The variables can be used in queries.

Note that the templating key will be a top-level dashboard property.

Simple syntax for custom variable type

This is a simple syntax that reduces the amount of configuration that needs to be added to the yaml, and should hopefully be enough for most use-cases.

templating:
  variables:
    variable1: ['value1', 'value2', 'value3']

This will create a variable called variable1, whose values can be value1, value2 or value3. The first value (value1) in the array can be the default value.

Advanced syntax

This advanced syntax can be used when a user wants more control over how the variable and its values are displayed.

templating:
  variables:
    variable1:                           # The name that can be used in queries in the form `%{variable1}`.
      label: 'Variable 1'                # (Optional) label that will appear in the UI for this dropdown.
      type: custom                       # We can add more types as we implement them.
      options:
        values:
        - value: 'var 1 option 1 value'  # The value that will replace `${variable1}` in queries.
          text: 'Var 1 Option 1'         # (Optional key) Text that will appear in the UI dropdown.
        - value: var1_option_2
          text: 'Var 1 Option 2'
          default: true                  # (Optional) This option should be the default value of this variable.

Permissions and Security

Should the variable only be allowed to have one of the values that is listed in the yaml?

Documentation

This needs to be documented at https://docs.gitlab.com/ee/user/project/integrations/prometheus.html#dashboard-yaml-properties with a warning that this is an alpha feature.

Something like this: image

Availability & Testing

What does success look like, and how can we measure that?

Simple variables can be defined in custom dashboards, where all possible values of the variable are described in the dashboard yaml.

Links / references

#201758 (closed)

Edited by Reuben Pereira