TestData template variables
Use template variables with the TestData data source to test dynamic, reusable dashboards. TestData provides a hierarchical metric tree that you can query to populate variable drop-downs with simulated values.
For an introduction to templating and template variables, refer to the Templating and Add and manage variables documentation.
Supported variable types
Create a query variable
To create a query variable using TestData:
- Navigate to Dashboard settings > Variables.
- Click Add variable.
- Select Query as the variable type.
- Select the TestData data source.
- Enter your query in the Query field.
Metric tree queries
TestData generates a hierarchical metric tree with nodes named using letter combinations. The tree has 6 levels of depth, with each level containing 8 nodes labeled A through H. The query string navigates this tree using dot-separated path segments.
Query syntax
Use * as a wildcard to return all children at a given level:
Use glob patterns with curly braces to match multiple nodes:
Use * after a prefix to match nodes that start with the given string:
Value queries
If your query string starts with value, TestData returns the query string itself as the result. This is useful for creating variables with specific values for testing. For example, a query of value_production returns value_production.
Example: Create a region variable
This example walks through creating a query variable that populates a drop-down with simulated region values, then using it in a panel query.
- Navigate to Dashboard settings > Variables.
- Click Add variable.
- Set Type to Query.
- Select the TestData data source.
- Enter
*in the Query field. This populates the variable with the top-level nodes (A through H). - Name the variable
region. - Click Apply.
To use the variable in a panel:
- Add a new panel and select the TestData data source.
- Choose the Random Walk scenario.
- In the Labels field, enter
region=$region. - The panel updates when you select a different value from the region drop-down.
Example: Chain variables for cascading drop-downs
You can create dependent variables where one variable’s query references another, producing cascading drop-downs.
- Create a variable named
regionwith the query*. This returns the top-level nodes (A through H). - Create a second variable named
hostwith the query$region.*. When the user selectsAas the region, the host drop-down populates withAA,AB,AC, etc.
Changing the region selection automatically refreshes the host drop-down.
Use variables in queries
TestData interpolates template variables in the following query fields:
- Labels
- Alias
- Scenario
- String Input
- CSV Content
- Raw Frame Content
Use the standard Grafana variable syntax ($varname or ${varname}) in any of these fields to insert variable values.
Example
With a variable named env set to production, entering env=$env in the Labels field produces a series labeled env=production.
Limitations
TestData doesn’t support ad hoc filters. Ad hoc filters require the data source to implement tag key and value lookups, which TestData doesn’t provide.


