From 6ae7c7e4a0e8cd96ec26dc81680bf63469ac697e Mon Sep 17 00:00:00 2001 From: "grafana-delivery-bot[bot]" <132647405+grafana-delivery-bot[bot]@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:30:36 +0100 Subject: [PATCH] [v10.2.x] DashboardSchema: Add options to VariableModel (#81107) DashboardSchema: Add options to VariableModel (#79236) * Add includeAll and regex fields to VariableModel #67639 * Add allValue option to VariableModel (cherry picked from commit f7fd8e6cd13a78392ec3795d5a60574fe880e1f0) Co-authored-by: Denis <7009699+someden@users.noreply.github.com> --- .../kinds/core/dashboard/schema-reference.md | 3 +++ kinds/dashboard/dashboard_kind.cue | 8 ++++++++ .../src/raw/dashboard/x/dashboard_types.gen.ts | 17 +++++++++++++++++ pkg/kinds/dashboard/dashboard_spec_gen.go | 10 ++++++++++ 4 files changed, 38 insertions(+) diff --git a/docs/sources/developers/kinds/core/dashboard/schema-reference.md b/docs/sources/developers/kinds/core/dashboard/schema-reference.md index e8fb56b1c18..5825133005c 100644 --- a/docs/sources/developers/kinds/core/dashboard/schema-reference.md +++ b/docs/sources/developers/kinds/core/dashboard/schema-reference.md @@ -604,15 +604,18 @@ A variable is a placeholder for a value. You can use variables in metric queries |---------------|-------------------------------------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `name` | string | **Yes** | | Name of variable | | `type` | string | **Yes** | | 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).
`constant`: Define a hidden constant.
`datasource`: Quickly change the data source for an entire dashboard.
`interval`: Interval variables represent time spans.
`textbox`: Display a free text input field with an optional default value.
`custom`: Define the variable options manually using a comma-separated list.
`system`: Variables defined by Grafana. See: https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#global-variables
Possible values are: `query`, `adhoc`, `constant`, `datasource`, `interval`, `textbox`, `custom`, `system`. | +| `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`. | | `hide` | integer | No | | Determine if the variable shows on dashboard
Accepted values are 0 (show label and value), 1 (show value only), 2 (show nothing).
Possible values are: `0`, `1`, `2`. | +| `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
`0`: Never refresh the variable
`1`: Queries the data source every time the dashboard loads.
`2`: Queries the data source when the dashboard time range changes.
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.
Named capture groups can be used to separate the display text and value. | | `skipUrlSync` | boolean | No | `false` | Whether the variable value should be managed by URL query params or not | | `sort` | integer | No | | 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
`7`: Natural ASC
`8`: Natural DESC
Possible values are: `0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`. | diff --git a/kinds/dashboard/dashboard_kind.cue b/kinds/dashboard/dashboard_kind.cue index 85e3a45040b..20745e4eddf 100644 --- a/kinds/dashboard/dashboard_kind.cue +++ b/kinds/dashboard/dashboard_kind.cue @@ -199,9 +199,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) diff --git a/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts b/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts index 8f4854b5bcb..1bc48ecb79a 100644 --- a/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts +++ b/packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts @@ -126,6 +126,10 @@ export const defaultAnnotationQuery: Partial = { * A variable is a placeholder for a value. You can use variables in metric queries and in panel titles. */ export interface VariableModel { + /** + * Custom all value + */ + allValue?: string; /** * Shows current selected variable text/value on the dashboard */ @@ -142,6 +146,10 @@ export interface VariableModel { * Visibility configuration for the variable */ hide?: VariableHide; + /** + * Whether all value option is available or not + */ + includeAll?: boolean; /** * Optional display name */ @@ -162,7 +170,15 @@ export interface VariableModel { * Query used to fetch values for a variable */ query?: (string | Record); + /** + * 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 */ @@ -178,6 +194,7 @@ export interface VariableModel { } export const defaultVariableModel: Partial = { + includeAll: false, multi: false, options: [], skipUrlSync: false, diff --git a/pkg/kinds/dashboard/dashboard_spec_gen.go b/pkg/kinds/dashboard/dashboard_spec_gen.go index 08c57edfd93..b16a156a4d0 100644 --- a/pkg/kinds/dashboard/dashboard_spec_gen.go +++ b/pkg/kinds/dashboard/dashboard_spec_gen.go @@ -884,6 +884,9 @@ type VariableHide int // A variable is a placeholder for a value. You can use variables in metric queries and in panel titles. type VariableModel struct { + // Custom all value + AllValue *string `json:"allValue,omitempty"` + // Option to be selected in a variable. Current *VariableOption `json:"current,omitempty"` @@ -897,6 +900,9 @@ type VariableModel struct { // Accepted values are 0 (show label and value), 1 (show value only), 2 (show nothing). Hide *VariableHide `json:"hide,omitempty"` + // Whether all value option is available or not + IncludeAll *bool `json:"includeAll,omitempty"` + // Optional display name Label *string `json:"label,omitempty"` @@ -918,6 +924,10 @@ 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,omitempty"`