|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Managing dashboard variables |
| 4 | +parent: Dashboard variables |
| 5 | +nav_order: 10 |
| 6 | +--- |
| 7 | + |
| 8 | +# Managing dashboard variables |
| 9 | + |
| 10 | +You can create, edit, delete, organize, and view dashboard variables from within a dashboard. |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +Before you start, ensure that you have met the following prerequisites: |
| 15 | + |
| 16 | +- Dashboard variables are [enabled]({{site.url}}{{site.baseurl}}/dashboards/dashboard-variables/#enabling-dashboard-variables) in your `opensearch_dashboards.yml` file. |
| 17 | +- You have an [Observability workspace]({{site.url}}{{site.baseurl}}/dashboards/workspace/create-workspace/) set up. |
| 18 | + |
| 19 | +For the complete setup, see [Creating and using dashboard variables]({{site.url}}{{site.baseurl}}/dashboards/dashboard-variables/#creating-and-using-dashboard-variables). |
| 20 | + |
| 21 | +## Creating a variable |
| 22 | + |
| 23 | +To create a new variable, follow these steps: |
| 24 | + |
| 25 | +1. In your Observability workspace, select **Dashboards** in the left navigation. |
| 26 | +1. Open an existing dashboard or select **Create** > **Dashboard** to create a new dashboard. If creating a new dashboard, save it first by entering a title and selecting **Save**. |
| 27 | +1. At the top of the dashboard, select **Add variable**. |
| 28 | +1. Configure the variable settings. The Add variable panel contains the following sections: |
| 29 | + |
| 30 | + - **General configuration**: |
| 31 | + - **Name** (required): The identifier used to reference the variable in queries using `$variableName` or `${variableName}` syntax. |
| 32 | + - **Label** (optional): A display name shown at the top of the dashboard. |
| 33 | + - **Description** (optional): Additional context about the variable's purpose. |
| 34 | + - **Type** (required): Select **Query** or **Custom**. For more information about variable types, see [Variable types]({{site.url}}{{site.baseurl}}/dashboards/dashboard-variables/#variable-types). |
| 35 | + - **Query type configuration** (for query type variables): |
| 36 | + - **Options Query**: Define a query to fetch variable options dynamically. |
| 37 | + - If needed, update the default language (PPL) to PromQL using the language toggle. |
| 38 | + - In the **Select dataset** dropdown list, select a dataset. For PPL, select an index pattern. For PromQL, select a Prometheus data source. |
| 39 | + - Write a query that returns a single column of values. |
| 40 | + - Select **Preview** to validate the query and view the first 100 results. |
| 41 | + - **Regex** (optional): Filter query results using a regular expression. Only values matching the pattern are displayed. |
| 42 | + - **Refresh**: Choose when to update variable options: |
| 43 | + - **On dashboard load**: Options are fetched once when the dashboard loads. |
| 44 | + - **On time range change**: Options refresh automatically when the dashboard time range changes. |
| 45 | + - **Custom type configuration** (for custom type variables): |
| 46 | + - **Custom options**: Enter custom values for the variable. Type a value and press Enter to add it. The maximum of 100 options can be displayed in the dropdown list. |
| 47 | + - **Selection configuration** (available for both query and custom types): |
| 48 | + - **Sort**: Choose how options are sorted in the dropdown list (**Disabled**, **Alphabetical** (ascending or descending), or **Numerical** (ascending or descending)). |
| 49 | + - **Allow multiple selections**: Enables you to select multiple values from the dropdown. |
| 50 | + - **Include All option** (only available when multiple selections are enabled): Adds an **All** option to the dropdown that selects all available values. |
| 51 | + |
| 52 | +1. Select **Add variable** to save. |
| 53 | + |
| 54 | +The variable appears at the top of the dashboard. |
| 55 | + |
| 56 | +## Managing existing variables |
| 57 | + |
| 58 | +The **Manage variables** panel lists all existing variables, including their type, name, and configuration options. To access this panel, follow these steps: |
| 59 | + |
| 60 | +1. Navigate to your workspace. |
| 61 | +1. From **Dashboards**, select the dashboard to update. |
| 62 | +1. On the top, toggle the **Edit** selector to enter edit mode. |
| 63 | +1. In the upper-left corner, select the **Manage variables** icon, as shown in the following image. |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +The **Manage variables** icon only appears when variables have been created in the dashboard. If no variables exist, create one first before accessing the management interface. |
| 68 | +{: .note} |
| 69 | + |
| 70 | +## Editing a variable |
| 71 | + |
| 72 | +To edit an existing variable, follow these steps: |
| 73 | + |
| 74 | +1. Open the **Manage variables** panel. |
| 75 | +1. Select the **Edit** icon for the variable you want to modify. |
| 76 | +1. Make your changes. |
| 77 | +1. Select **Update variable** to save. |
| 78 | + |
| 79 | +Changing the variable name causes any queries that reference the old name to fail. |
| 80 | +{: .note} |
| 81 | + |
| 82 | +## Deleting a variable |
| 83 | + |
| 84 | +To delete a variable, follow these steps: |
| 85 | + |
| 86 | +1. Open the **Manage variables** panel. |
| 87 | +1. Select the **Delete** icon for the variable you want to remove. |
| 88 | +1. Confirm the deletion in the dialog. |
| 89 | + |
| 90 | +Variables that are referenced by other variables or visualization editors display an indicator in the management panel. Deleting a referenced variable causes any queries that use it to fail. |
| 91 | +{: .note} |
| 92 | + |
| 93 | +## Organizing variables |
| 94 | + |
| 95 | +Variables are displayed at the top of the dashboard in the order they appear in the management panel. |
| 96 | + |
| 97 | +To reorder variables, follow these steps: |
| 98 | + |
| 99 | +1. Open the **Manage variables** panel. |
| 100 | +1. Drag the reorder handle on the left side of a variable. |
| 101 | +1. Drop it in the desired position. |
| 102 | +1. Save the dashboard to apply the new order. |
| 103 | + |
| 104 | +## Hiding variables |
| 105 | + |
| 106 | +You can hide variables from the top of the dashboard while keeping them available for use in queries. |
| 107 | + |
| 108 | +To hide or show a variable, follow these steps: |
| 109 | + |
| 110 | +1. Open the **Manage variables** panel. |
| 111 | +1. Select the **Hide/Show** icon for the variable. |
| 112 | +1. Save the dashboard to apply the change. |
| 113 | + |
| 114 | +Hidden variables are marked with a **Hidden** badge in the management panel and do not appear in the dashboard. |
| 115 | +{: .note} |
| 116 | + |
| 117 | +## Variable status indicators |
| 118 | + |
| 119 | +Each variable displays a status indicator at the top of the dashboard: |
| 120 | + |
| 121 | +- **Loading**: A spinner appears while the system fetches options. |
| 122 | +- **Error**: An error icon appears with a tooltip showing the error message. The dropdown is disabled. |
| 123 | +- **No options**: If a variable query returns no results, "No options" is displayed in the dropdown. |
| 124 | + |
| 125 | +## URL synchronization |
| 126 | + |
| 127 | +Variable values are automatically synchronized to the dashboard URL using the `variableValues` query parameter: |
| 128 | + |
| 129 | +```js |
| 130 | +?variableValues=(service:(api),region:(us-east,us-west)) |
| 131 | +``` |
| 132 | +
|
| 133 | +URL synchronization enables the following functionality: |
| 134 | +
|
| 135 | +- Send a link to a dashboard with specific variable values preselected. |
| 136 | +- Save a dashboard view with your preferred variable settings. |
| 137 | +- Preserve variable selections across page refreshes. |
| 138 | +
|
| 139 | +## Variable dependencies |
| 140 | +
|
| 141 | +Query type variables can reference other variables in their queries. The following example shows a query variable that references another variable: |
| 142 | +
|
| 143 | +```sql |
| 144 | +source=logs | where region=$region | dedup service | fields service |
| 145 | +``` |
| 146 | +{% include copy.html %} |
| 147 | +
|
| 148 | +In this example, the `service` variable depends on the `region` variable. When the `region` variable changes, the `service` variable automatically refreshes its options. |
| 149 | +
|
| 150 | +Keep the following considerations in mind: |
| 151 | +
|
| 152 | +- Avoid circular dependencies where Variable A references Variable B, and Variable B references Variable A. |
| 153 | +- Variables are evaluated in the order they appear in the management panel. Place dependent variables after the variables they reference. |
| 154 | +
|
| 155 | +## Next steps |
| 156 | +
|
| 157 | +- [Using dashboard variables]({{site.url}}{{site.baseurl}}/dashboards/dashboard-variables/using-variables/) |
0 commit comments