Template variables allow you to dynamically filter charts in a dashboard based on attribute values returned by the data. Instead of creating a chart for each value, you create one chart and then filter the dashboard to a specific value or values.
For example, say you want to view the health of your services. Instead of creating a separate dashboard for each service, you create one dashboard that uses service
as a template variable. On initial load, the charts show data using the default value of the variable. You use the variable dropdown to select only the service(s) you’re interested in.
To show all available values, don’t select any values (or click Clear if values are already selected). Selecting All for the filter implicitly returns all selected values, and any values added after this point will not be included.
Template variables provide greater functionality and are more predictable than Global filters. You can choose to use either one at the top of the dashboard.
You create template variables from existing attributes on your metric or span data. Variables are specific to a particular dashboard.
When you copy a dashboard chart that uses variables to a notebook or an alert, or use Cloud Observability’s correlation feature, the variable is replaced with the current value used in the dashboard.
You create and manage template variables from the Dashboard view. First, you create the variable and then you edit your charts to use it as a value in your query filter.
From a dashboard, click Template variable (or Manage template variables if you’ve already created one)
Enter the following:
Name: A unique name for the variable. This name displays the variable on the dashboard.
Names:
Suggestion attribute key: Select the attribute to use as the variable. The dropdown lists all available attributes that you can use as filters on the dashboard.
When Cloud Observability detects new attribute values, they automatically become available for the filter. You don’t need to update the variable.
Default value: Select the value that you want the dashboard to display on initial load.
To show all available values, don’t select any values (or click Clear if values are already selected). Selecting All for the filter implicitly returns all selected values, and any values added after this point will not be included.
Apply to charts: Select the charts on the dashboard that should use the variable.
When you apply a template variable to a chart, Cloud Observability adds a new filter to the query (for example, filter service == $service
). It will not remove or replace existing filters, as there are some cases where it may interfere with your query.
The variables display above the charts, where you can filter your dashboards to the selected variable values.
Create, edit, and delete template variables from the Manage template variables link.
Deleting a template variable removes the added filter from chart queries selected to use that variable.
Updated Sep 13, 2023