## Configure Template Variables

Template variables let you dynamically filter dashboards using runtime values from your telemetry data, such as namespace, cluster, pod, or service.

### Create a Template Variable

1. In the dashboard, open the **Actions** menu.

2. Select **Configure variables**.

3. Click **Add Variable**.

### General Settings

- **Name** — Internal reference used in queries (e.g., `$namespace`)
- **Label** — Optional UI label (e.g., **Namespace**)
- **Description** — Optional help text visible in the dropdown
- **Variable type** — Select from:

- `Query` (default): populate values dynamically from the backend

### Query Options

- **Stream type** — Choose `Metrics`, `Logs`, or other supported types
- **Query type** — Select how to extract values:
  - `Label values` — populate from label keys
  - `Series` — match full series names
- **Label** — Choose a label such as `service_namespace` or `cluster`
- **Metric** — Optional, limit values to a specific metric

### Filter values

Use filters to narrow results:

- Combine filters using **key**, **operator**, and **value**
- Click `+` to add multiple filter conditions

### Use Regex

Use regex to extract or format display values.

Example:

```regex
/.+(?<text>.*):(?<value>.*)/
```

This lets you split a label or metric into display name and internal value.

### Sort and Selection Options

- **Sort** — Choose how to order values (e.g., by value or name)
- **Multi-value** — Allow selecting more than one value
- **Allow custom values** — Allow users to enter custom values
- **Include all options** — Add an **All** selection to apply to every possible value

### Preview and Save

1. Click **Run query** to test the variable setup.
2. Use the preview at the bottom to confirm expected values.
3. Click **Save** or **Go back to list** to apply the configuration.

|     |     |
| --- | --- |
|  | Once configured, you can use the variable in any panel query using `$variableName`. |
