[v10.1.x] DashboardSchema: Add options to VariableModel (#81112)

DashboardSchema: Add options to VariableModel (#79236)

* Add includeAll and regex fields to VariableModel  #67639

* Add allValue option to VariableModel

(cherry picked from commit f7fd8e6cd1)

Co-authored-by: Denis <7009699+someden@users.noreply.github.com>
This commit is contained in:
Selene
2024-01-23 11:54:09 -05:00
committed by GitHub
co-authored by Denis
parent 6582de0628
commit 42dad26bef
4 changed files with 78 additions and 0 deletions
@@ -640,14 +640,18 @@ A variable is a placeholder for a value. You can use variables in metric queries
| `skipUrlSync` | boolean | **Yes** | `false` | Whether the variable value should be managed by URL query params or not |
| `type` | string | **Yes** | | Dashboard variable type<br/>`query`: Query-generated list of values such as metric names, server names, sensor IDs, data centers, and so on.<br/>`adhoc`: Key/value filters that are automatically added to all metric queries for a data source (Prometheus, Loki, InfluxDB, and Elasticsearch only).<br/>`constant`: Define a hidden constant.<br/>`datasource`: Quickly change the data source for an entire dashboard.<br/>`interval`: Interval variables represent time spans.<br/>`textbox`: Display a free text input field with an optional default value.<br/>`custom`: Define the variable options manually using a comma-separated list.<br/>`system`: Variables defined by Grafana. See: https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#global-variables<br/>Possible values are: `query`, `adhoc`, `constant`, `datasource`, `interval`, `textbox`, `custom`, `system`. |
| `allFormat` | string | No | | Format to use while fetching all values from data source, eg: wildcard, glob, regex, pipe, etc. |
| `allValue` | string | No | | Custom all value |
| `current` | [VariableOption](#variableoption) | No | | Option to be selected in a variable. |
| `datasource` | [DataSourceRef](#datasourceref) | No | | Ref to a DataSource instance |
| `description` | string | No | | Description of variable. It can be defined but `null`. |
| `includeAll` | boolean | No | `false` | Whether all value option is available or not |
| `label` | string | No | | Optional display name |
| `multi` | boolean | No | `false` | Whether multiple values can be selected or not from variable value list |
| `options` | [VariableOption](#variableoption)[] | No | | Options that can be selected for a variable. |
| `query` | | No | | Query used to fetch values for a variable |
| `refresh` | integer | No | | Options to config when to refresh a variable<br/>`0`: Never refresh the variable<br/>`1`: Queries the data source every time the dashboard loads.<br/>`2`: Queries the data source when the dashboard time range changes.<br/>Possible values are: `0`, `1`, `2`. |
| `regex` | string | No | | Optional field, if you want to extract part of a series name or metric node segment.<br/>Named capture groups can be used to separate the display text and value. |
| `sort` | integer | No | | Sort variable options<br/>Accepted values are:<br/>`0`: No sorting<br/>`1`: Alphabetical ASC<br/>`2`: Alphabetical DESC<br/>`3`: Numerical ASC<br/>`4`: Numerical DESC<br/>`5`: Alphabetical Case Insensitive ASC<br/>`6`: Alphabetical Case Insensitive DESC<br/>Possible values are: `0`, `1`, `2`, `3`, `4`, `5`, `6`. |
### VariableOption
+10
View File
@@ -215,7 +215,17 @@ lineage: schemas: [{
multi?: bool | *false
// Options that can be selected for a variable.
options?: [...#VariableOption]
// Options to config when to refresh a variable
refresh?: #VariableRefresh
// Options sort order
sort?: #VariableSort
// Whether all value option is available or not
includeAll?: bool | *false
// Custom all value
allValue?: string
// Optional field, if you want to extract part of a series name or metric node segment.
// Named capture groups can be used to separate the display text and value.
regex?: string
...
} @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview)
@@ -125,6 +125,10 @@ export interface VariableModel {
* Format to use while fetching all values from data source, eg: wildcard, glob, regex, pipe, etc.
*/
allFormat?: string;
/**
* Custom all value
*/
allValue?: string;
/**
* Shows current selected variable text/value on the dashboard
*/
@@ -145,6 +149,10 @@ export interface VariableModel {
* Unique numeric identifier for the variable.
*/
id: string;
/**
* Whether all value option is available or not
*/
includeAll?: boolean;
/**
* Optional display name
*/
@@ -165,11 +173,23 @@ export interface VariableModel {
* Query used to fetch values for a variable
*/
query?: (string | Record<string, unknown>);
/**
* Options to config when to refresh a variable
*/
refresh?: VariableRefresh;
/**
* Optional field, if you want to extract part of a series name or metric node segment.
* Named capture groups can be used to separate the display text and value.
*/
regex?: string;
/**
* Whether the variable value should be managed by URL query params or not
*/
skipUrlSync: boolean;
/**
* Options sort order
*/
sort?: VariableSort;
/**
* Type of variable
*/
@@ -178,6 +198,7 @@ export interface VariableModel {
export const defaultVariableModel: Partial<VariableModel> = {
id: '00000000-0000-0000-0000-000000000000',
includeAll: false,
multi: false,
options: [],
skipUrlSync: false,
+43
View File
@@ -149,6 +149,17 @@ const (
VariableRefreshN2 VariableRefresh = 2
)
// Defines values for VariableSort.
const (
VariableSortN0 VariableSort = 0
VariableSortN1 VariableSort = 1
VariableSortN2 VariableSort = 2
VariableSortN3 VariableSort = 3
VariableSortN4 VariableSort = 4
VariableSortN5 VariableSort = 5
VariableSortN6 VariableSort = 6
)
// Defines values for VariableType.
const (
VariableTypeAdhoc VariableType = "adhoc"
@@ -916,6 +927,9 @@ type VariableModel struct {
// Format to use while fetching all values from data source, eg: wildcard, glob, regex, pipe, etc.
AllFormat *string `json:"allFormat,omitempty"`
// Custom all value
AllValue *string `json:"allValue,omitempty"`
// Option to be selected in a variable.
Current *VariableOption `json:"current,omitempty"`
@@ -932,6 +946,9 @@ type VariableModel struct {
// Unique numeric identifier for the variable.
Id string `json:"id"`
// Whether all value option is available or not
IncludeAll *bool `json:"includeAll,omitempty"`
// Optional display name
Label *string `json:"label,omitempty"`
@@ -953,9 +970,24 @@ type VariableModel struct {
// `2`: Queries the data source when the dashboard time range changes.
Refresh *VariableRefresh `json:"refresh,omitempty"`
// Optional field, if you want to extract part of a series name or metric node segment.
// Named capture groups can be used to separate the display text and value.
Regex *string `json:"regex,omitempty"`
// Whether the variable value should be managed by URL query params or not
SkipUrlSync bool `json:"skipUrlSync"`
// Sort variable options
// Accepted values are:
// `0`: No sorting
// `1`: Alphabetical ASC
// `2`: Alphabetical DESC
// `3`: Numerical ASC
// `4`: Numerical DESC
// `5`: Alphabetical Case Insensitive ASC
// `6`: Alphabetical Case Insensitive DESC
Sort *VariableSort `json:"sort,omitempty"`
// Dashboard variable type
// `query`: Query-generated list of values such as metric names, server names, sensor IDs, data centers, and so on.
// `adhoc`: Key/value filters that are automatically added to all metric queries for a data source (Prometheus, Loki, InfluxDB, and Elasticsearch only).
@@ -986,6 +1018,17 @@ type VariableOption struct {
// `2`: Queries the data source when the dashboard time range changes.
type VariableRefresh int
// Sort variable options
// Accepted values are:
// `0`: No sorting
// `1`: Alphabetical ASC
// `2`: Alphabetical DESC
// `3`: Numerical ASC
// `4`: Numerical DESC
// `5`: Alphabetical Case Insensitive ASC
// `6`: Alphabetical Case Insensitive DESC
type VariableSort int
// Dashboard variable type
// `query`: Query-generated list of values such as metric names, server names, sensor IDs, data centers, and so on.
// `adhoc`: Key/value filters that are automatically added to all metric queries for a data source (Prometheus, Loki, InfluxDB, and Elasticsearch only).