Schemas: Allow nulls in schema for +/-Infinity types (#70958)

* Add null options and remove veneer attributes

* Generate all code, remove old veneer defs

* Remove now-unnecessary error expect
pull/71000/head
sam boyer 2 years ago committed by GitHub
parent ad8211cce7
commit 751b982d9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .betterer.results
  2. 18
      docs/sources/developers/kinds/core/dashboard/schema-reference.md
  3. 68
      kinds/dashboard/dashboard_kind.cue
  4. 10
      packages/grafana-schema/src/index.gen.ts
  5. 6
      packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts
  6. 31
      packages/grafana-schema/src/veneer/dashboard.types.ts
  7. 6
      pkg/kinds/dashboard/dashboard_spec_gen.go
  8. 1
      public/app/features/dashboard/state/DashboardMigrator.test.ts

@ -868,8 +868,7 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "2"], [0, 0, 0, "Do not use any type assertions.", "2"],
[0, 0, 0, "Do not use any type assertions.", "3"], [0, 0, 0, "Do not use any type assertions.", "3"],
[0, 0, 0, "Do not use any type assertions.", "4"], [0, 0, 0, "Do not use any type assertions.", "4"],
[0, 0, 0, "Do not use any type assertions.", "5"], [0, 0, 0, "Do not use any type assertions.", "5"]
[0, 0, 0, "Do not use any type assertions.", "6"]
], ],
"packages/grafana-toolkit/src/cli/tasks/task.ts:5381": [ "packages/grafana-toolkit/src/cli/tasks/task.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "0"],

@ -274,10 +274,10 @@ Thresholds configuration for the panel
User-defined value for a metric that triggers visual changes in a panel when this value is met or exceeded User-defined value for a metric that triggers visual changes in a panel when this value is met or exceeded
They are used to conditionally style and color visualizations based on query results , and can be applied to most visualizations. They are used to conditionally style and color visualizations based on query results , and can be applied to most visualizations.
| Property | Type | Required | Default | Description | | Property | Type | Required | Default | Description |
|----------|--------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |----------|----------------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `color` | string | **Yes** | | Color represents the color of the visual change that will occur in the dashboard when the threshold value is met or exceeded. | | `color` | string | **Yes** | | Color represents the color of the visual change that will occur in the dashboard when the threshold value is met or exceeded. |
| `value` | number | **Yes** | | Value represents a specified metric for the threshold, which triggers a visual change in the dashboard when this value is met or exceeded.<br/>Nulls currently appear here when serializing -Infinity to JSON. | | `value` | number or null | **Yes** | | Value represents a specified metric for the threshold, which triggers a visual change in the dashboard when this value is met or exceeded.<br/>Nulls currently appear here when serializing -Infinity to JSON. |
### ValueMapping ### ValueMapping
@ -301,11 +301,11 @@ For example, if a value is within a certain range, you can configure a range val
Range to match against and the result to apply when the value is within the range Range to match against and the result to apply when the value is within the range
| Property | Type | Required | Default | Description | | Property | Type | Required | Default | Description |
|----------|-------------------------------------------|----------|---------|-----------------------------------------------------------------------| |----------|-------------------------------------------|----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `from` | number | **Yes** | | Min value of the range. It can be null which means -Infinity | | `from` | number or null | **Yes** | | Min value of the range. It can be null which means -Infinity<br/>Constraint: `>=-1.797693134862315708145274237317043567981E+308 & <=1.797693134862315708145274237317043567981E+308`. |
| `result` | [ValueMappingResult](#valuemappingresult) | **Yes** | | Result used as replacement with text and color when the value matches | | `result` | [ValueMappingResult](#valuemappingresult) | **Yes** | | Result used as replacement with text and color when the value matches |
| `to` | number | **Yes** | | Max value of the range. It can be null which means +Infinity | | `to` | number or null | **Yes** | | Max value of the range. It can be null which means +Infinity<br/>Constraint: `>=-1.797693134862315708145274237317043567981E+308 & <=1.797693134862315708145274237317043567981E+308`. |
### ValueMappingResult ### ValueMappingResult

@ -197,7 +197,7 @@ lineage: schemas: [{
name: string name: string
// Optional display name // Optional display name
label?: string label?: string
// Visibility configuration for the variable // Visibility configuration for the variable
hide: #VariableHide hide: #VariableHide
// Whether the variable value should be managed by URL query params or not // Whether the variable value should be managed by URL query params or not
skipUrlSync: bool | *false skipUrlSync: bool | *false
@ -231,8 +231,8 @@ lineage: schemas: [{
// Options to config when to refresh a variable // Options to config when to refresh a variable
// `0`: Never refresh the variable // `0`: Never refresh the variable
// `1`: Queries the data source every time the dashboard loads. // `1`: Queries the data source every time the dashboard loads.
// `2`: Queries the data source when the dashboard time range changes. // `2`: Queries the data source when the dashboard time range changes.
#VariableRefresh: 0 | 1 | 2 @cuetsy(kind="enum",memberNames="never|onDashboardLoad|onTimeRangeChanged") #VariableRefresh: 0 | 1 | 2 @cuetsy(kind="enum",memberNames="never|onDashboardLoad|onTimeRangeChanged")
// Determine if the variable shows on dashboard // Determine if the variable shows on dashboard
@ -291,17 +291,17 @@ lineage: schemas: [{
#DashboardLinkType: "link" | "dashboards" @cuetsy(kind="type") #DashboardLinkType: "link" | "dashboards" @cuetsy(kind="type")
// Dashboard variable type // Dashboard variable type
// `query`: Query-generated list of values such as metric names, server names, sensor IDs, data centers, and so on. // `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). // `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. // `constant`: Define a hidden constant.
// `datasource`: Quickly change the data source for an entire dashboard. // `datasource`: Quickly change the data source for an entire dashboard.
// `interval`: Interval variables represent time spans. // `interval`: Interval variables represent time spans.
// `textbox`: Display a free text input field with an optional default value. // `textbox`: Display a free text input field with an optional default value.
// `custom`: Define the variable options manually using a comma-separated list. // `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 // `system`: Variables defined by Grafana. See: https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#global-variables
#VariableType: "query" | "adhoc" | "constant" | "datasource" | "interval" | "textbox" | "custom" | "system" @cuetsy(kind="type") @grafanamaturity(NeedsExpertReview) #VariableType: "query" | "adhoc" | "constant" | "datasource" | "interval" | "textbox" | "custom" | "system" @cuetsy(kind="type") @grafanamaturity(NeedsExpertReview)
// Color mode for a field. You can specify a single color, or select a continuous (gradient) color schemes, based on a value. // Color mode for a field. You can specify a single color, or select a continuous (gradient) color schemes, based on a value.
// Continuous color interpolates a color using the percentage of a value relative to min and max. // Continuous color interpolates a color using the percentage of a value relative to min and max.
// Accepted values are: // Accepted values are:
// `thresholds`: From thresholds. Informs Grafana to take the color from the matching threshold // `thresholds`: From thresholds. Informs Grafana to take the color from the matching threshold
@ -353,10 +353,10 @@ lineage: schemas: [{
#Threshold: { #Threshold: {
// Value represents a specified metric for the threshold, which triggers a visual change in the dashboard when this value is met or exceeded. // Value represents a specified metric for the threshold, which triggers a visual change in the dashboard when this value is met or exceeded.
// Nulls currently appear here when serializing -Infinity to JSON. // Nulls currently appear here when serializing -Infinity to JSON.
value: number @grafanamaturity(NeedsExpertReview) value: number | null @grafanamaturity(NeedsExpertReview)
// Color represents the color of the visual change that will occur in the dashboard when the threshold value is met or exceeded. // Color represents the color of the visual change that will occur in the dashboard when the threshold value is met or exceeded.
color: string @grafanamaturity(NeedsExpertReview) color: string @grafanamaturity(NeedsExpertReview)
} @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview) } @cuetsy(kind="interface") @grafanamaturity(NeedsExpertReview)
// Thresholds can either be `absolute` (specific number) or `percentage` (relative to min or max, it will be values between 0 and 1). // Thresholds can either be `absolute` (specific number) or `percentage` (relative to min or max, it will be values between 0 and 1).
#ThresholdsMode: "absolute" | "percentage" @cuetsy(kind="enum",memberNames="Absolute|Percentage") #ThresholdsMode: "absolute" | "percentage" @cuetsy(kind="enum",memberNames="Absolute|Percentage")
@ -368,10 +368,10 @@ lineage: schemas: [{
// Must be sorted by 'value', first value is always -Infinity // Must be sorted by 'value', first value is always -Infinity
steps: [...#Threshold] @grafanamaturity(NeedsExpertReview) steps: [...#Threshold] @grafanamaturity(NeedsExpertReview)
} @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview) } @cuetsy(kind="interface") @grafanamaturity(NeedsExpertReview)
// Allow to transform the visual representation of specific data values in a visualization, irrespective of their original units // Allow to transform the visual representation of specific data values in a visualization, irrespective of their original units
#ValueMapping: #ValueMap | #RangeMap | #RegexMap | #SpecialValueMap @cuetsy(kind="type") @grafanamaturity(NeedsExpertReview) @grafana(TSVeneer="type") #ValueMapping: #ValueMap | #RangeMap | #RegexMap | #SpecialValueMap @cuetsy(kind="type") @grafanamaturity(NeedsExpertReview)
// Supported value mapping types // Supported value mapping types
// `value`: Maps text values to a color or different display text and color. For example, you can configure a value mapping so that all instances of the value 10 appear as Perfection! rather than the number. // `value`: Maps text values to a color or different display text and color. For example, you can configure a value mapping so that all instances of the value 10 appear as Perfection! rather than the number.
@ -380,7 +380,7 @@ lineage: schemas: [{
// `special`: Maps special values like Null, NaN (not a number), and boolean values like true and false to a display text and color. See SpecialValueMatch to see the list of special values. For example, you can configure a special value mapping so that null values appear as N/A. // `special`: Maps special values like Null, NaN (not a number), and boolean values like true and false to a display text and color. See SpecialValueMatch to see the list of special values. For example, you can configure a special value mapping so that null values appear as N/A.
#MappingType: "value" | "range" | "regex" | "special" @cuetsy(kind="enum",memberNames="ValueToText|RangeToText|RegexToText|SpecialValue") @grafanamaturity(NeedsExpertReview) #MappingType: "value" | "range" | "regex" | "special" @cuetsy(kind="enum",memberNames="ValueToText|RangeToText|RegexToText|SpecialValue") @grafanamaturity(NeedsExpertReview)
// Maps text values to a color or different display text and color. // Maps text values to a color or different display text and color.
// For example, you can configure a value mapping so that all instances of the value 10 appear as Perfection! rather than the number. // For example, you can configure a value mapping so that all instances of the value 10 appear as Perfection! rather than the number.
#ValueMap: { #ValueMap: {
type: #MappingType & "value" type: #MappingType & "value"
@ -388,22 +388,22 @@ lineage: schemas: [{
options: [string]: #ValueMappingResult options: [string]: #ValueMappingResult
} @cuetsy(kind="interface") } @cuetsy(kind="interface")
// Maps numerical ranges to a display text and color. // Maps numerical ranges to a display text and color.
// For example, if a value is within a certain range, you can configure a range value mapping to display Low or High rather than the number. // For example, if a value is within a certain range, you can configure a range value mapping to display Low or High rather than the number.
#RangeMap: { #RangeMap: {
type: #MappingType & "range" type: #MappingType & "range"
// Range to match against and the result to apply when the value is within the range // Range to match against and the result to apply when the value is within the range
options: { options: {
// Min value of the range. It can be null which means -Infinity // Min value of the range. It can be null which means -Infinity
from: float64 from: float64 | null
// Max value of the range. It can be null which means +Infinity // Max value of the range. It can be null which means +Infinity
to: float64 to: float64 | null
// Config to apply when the value is within the range // Config to apply when the value is within the range
result: #ValueMappingResult result: #ValueMappingResult
} }
} @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview) } @cuetsy(kind="interface") @grafanamaturity(NeedsExpertReview)
// Maps regular expressions to replacement text and a color. // Maps regular expressions to replacement text and a color.
// For example, if a value is www.example.com, you can configure a regex value mapping so that Grafana displays www and truncates the domain. // For example, if a value is www.example.com, you can configure a regex value mapping so that Grafana displays www and truncates the domain.
#RegexMap: { #RegexMap: {
type: #MappingType & "regex" type: #MappingType & "regex"
@ -416,8 +416,8 @@ lineage: schemas: [{
} }
} @cuetsy(kind="interface") @grafanamaturity(NeedsExpertReview) } @cuetsy(kind="interface") @grafanamaturity(NeedsExpertReview)
// Maps special values like Null, NaN (not a number), and boolean values like true and false to a display text and color. // Maps special values like Null, NaN (not a number), and boolean values like true and false to a display text and color.
// See SpecialValueMatch to see the list of special values. // See SpecialValueMatch to see the list of special values.
// For example, you can configure a special value mapping so that null values appear as N/A. // For example, you can configure a special value mapping so that null values appear as N/A.
#SpecialValueMap: { #SpecialValueMap: {
type: #MappingType & "special" type: #MappingType & "special"
@ -444,8 +444,8 @@ lineage: schemas: [{
index?: int32 index?: int32
} @cuetsy(kind="interface") } @cuetsy(kind="interface")
// Transformations allow to manipulate data returned by a query before the system applies a visualization. // Transformations allow to manipulate data returned by a query before the system applies a visualization.
// Using transformations you can: rename fields, join time series data, perform mathematical operations across queries, // Using transformations you can: rename fields, join time series data, perform mathematical operations across queries,
// use the output of one transformation as the input to another transformation, etc. // use the output of one transformation as the input to another transformation, etc.
#DataTransformerConfig: { #DataTransformerConfig: {
// Unique identifier of transformer // Unique identifier of transformer
@ -503,7 +503,7 @@ lineage: schemas: [{
userId: uint32 @grafanamaturity(NeedsExpertReview) userId: uint32 @grafanamaturity(NeedsExpertReview)
} @grafanamaturity(NeedsExpertReview) } @grafanamaturity(NeedsExpertReview)
// Dashboard panels are the basic visualization building blocks. // Dashboard panels are the basic visualization building blocks.
#Panel: { #Panel: {
// The panel plugin type id. This is used to find the plugin to display the panel. // The panel plugin type id. This is used to find the plugin to display the panel.
type: string & strings.MinRunes(1) type: string & strings.MinRunes(1)
@ -552,27 +552,27 @@ lineage: schemas: [{
maxDataPoints?: number maxDataPoints?: number
// List of transformations that are applied to the panel data before rendering. // List of transformations that are applied to the panel data before rendering.
// When there are multiple transformations, Grafana applies them in the order they are listed. // When there are multiple transformations, Grafana applies them in the order they are listed.
// Each transformation creates a result set that then passes on to the next transformation in the processing pipeline. // Each transformation creates a result set that then passes on to the next transformation in the processing pipeline.
transformations: [...#DataTransformerConfig] transformations: [...#DataTransformerConfig]
// The min time interval setting defines a lower limit for the $__interval and $__interval_ms variables. // The min time interval setting defines a lower limit for the $__interval and $__interval_ms variables.
// This value must be formatted as a number followed by a valid time // This value must be formatted as a number followed by a valid time
// identifier like: "40s", "3d", etc. // identifier like: "40s", "3d", etc.
// See: https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/#query-options // See: https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/#query-options
interval?: string interval?: string
// Overrides the relative time range for individual panels, // Overrides the relative time range for individual panels,
// which causes them to be different than what is selected in // which causes them to be different than what is selected in
// the dashboard time picker in the top-right corner of the dashboard. You can use this to show metrics from different // the dashboard time picker in the top-right corner of the dashboard. You can use this to show metrics from different
// time periods or days on the same dashboard. // time periods or days on the same dashboard.
// The value is formatted as time operation like: `now-5m` (Last 5 minutes), `now/d` (the day so far), // The value is formatted as time operation like: `now-5m` (Last 5 minutes), `now/d` (the day so far),
// `now-5d/d`(Last 5 days), `now/w` (This week so far), `now-2y/y` (Last 2 years). // `now-5d/d`(Last 5 days), `now/w` (This week so far), `now-2y/y` (Last 2 years).
// Note: Panel time overrides have no effect when the dashboard’s time range is absolute. // Note: Panel time overrides have no effect when the dashboard’s time range is absolute.
// See: https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/#query-options // See: https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/#query-options
timeFrom?: string timeFrom?: string
// Overrides the time range for individual panels by shifting its start and end relative to the time picker. // Overrides the time range for individual panels by shifting its start and end relative to the time picker.
// For example, you can shift the time range for the panel to be two hours earlier than the dashboard time picker setting `2h`. // For example, you can shift the time range for the panel to be two hours earlier than the dashboard time picker setting `2h`.
// Note: Panel time overrides have no effect when the dashboard’s time range is absolute. // Note: Panel time overrides have no effect when the dashboard’s time range is absolute.
// See: https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/#query-options // See: https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/#query-options
@ -588,7 +588,7 @@ lineage: schemas: [{
fieldConfig: #FieldConfigSource fieldConfig: #FieldConfigSource
} @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview) } @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview)
// The data model used in Grafana, namely the data frame, is a columnar-oriented table structure that unifies both time series and table query results. // The data model used in Grafana, namely the data frame, is a columnar-oriented table structure that unifies both time series and table query results.
// Each column within this structure is called a field. A field can represent a single time series or table column. // Each column within this structure is called a field. A field can represent a single time series or table column.
// Field options allow you to change how the data is displayed in your visualizations. // Field options allow you to change how the data is displayed in your visualizations.
#FieldConfigSource: { #FieldConfigSource: {
@ -601,8 +601,8 @@ lineage: schemas: [{
}] @grafanamaturity(NeedsExpertReview) }] @grafanamaturity(NeedsExpertReview)
} @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview) } @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview)
// A library panel is a reusable panel that you can use in any dashboard. // A library panel is a reusable panel that you can use in any dashboard.
// When you make a change to a library panel, that change propagates to all instances of where the panel is used. // When you make a change to a library panel, that change propagates to all instances of where the panel is used.
// Library panels streamline reuse of panels across multiple dashboards. // Library panels streamline reuse of panels across multiple dashboards.
#LibraryPanelRef: { #LibraryPanelRef: {
// Library panel name // Library panel name
@ -625,7 +625,7 @@ lineage: schemas: [{
value?: _ @grafanamaturity(NeedsExpertReview) value?: _ @grafanamaturity(NeedsExpertReview)
} }
// The data model used in Grafana, namely the data frame, is a columnar-oriented table structure that unifies both time series and table query results. // The data model used in Grafana, namely the data frame, is a columnar-oriented table structure that unifies both time series and table query results.
// Each column within this structure is called a field. A field can represent a single time series or table column. // Each column within this structure is called a field. A field can represent a single time series or table column.
// Field options allow you to change how the data is displayed in your visualizations. // Field options allow you to change how the data is displayed in your visualizations.
#FieldConfig: { #FieldConfig: {
@ -664,8 +664,8 @@ lineage: schemas: [{
// `currency:<unit>` for custom a currency unit. // `currency:<unit>` for custom a currency unit.
unit?: string @grafanamaturity(NeedsExpertReview) unit?: string @grafanamaturity(NeedsExpertReview)
// Specify the number of decimals Grafana includes in the rendered value. // Specify the number of decimals Grafana includes in the rendered value.
// If you leave this field blank, Grafana automatically truncates the number of decimals based on the value. // If you leave this field blank, Grafana automatically truncates the number of decimals based on the value.
// For example 1.1234 will display as 1.12 and 100.456 will display as 100. // For example 1.1234 will display as 1.12 and 100.456 will display as 100.
// To display all decimals, set the unit to `String`. // To display all decimals, set the unit to `String`.
decimals?: number @grafanamaturity(NeedsExpertReview) decimals?: number @grafanamaturity(NeedsExpertReview)

@ -29,7 +29,11 @@ export type {
FieldColorSeriesByMode, FieldColorSeriesByMode,
FieldColor, FieldColor,
GridPos, GridPos,
Threshold,
ThresholdsConfig,
ValueMapping,
ValueMap, ValueMap,
RangeMap,
RegexMap, RegexMap,
SpecialValueMap, SpecialValueMap,
ValueMappingResult, ValueMappingResult,
@ -49,6 +53,7 @@ export {
FieldColorModeId, FieldColorModeId,
defaultGridPos, defaultGridPos,
ThresholdsMode, ThresholdsMode,
defaultThresholdsConfig,
MappingType, MappingType,
SpecialValueMatch, SpecialValueMatch,
DashboardCursorSync, DashboardCursorSync,
@ -70,10 +75,6 @@ export type {
AnnotationQuery, AnnotationQuery,
VariableModel, VariableModel,
DataSourceRef, DataSourceRef,
Threshold,
ThresholdsConfig,
ValueMapping,
RangeMap,
DataTransformerConfig, DataTransformerConfig,
Panel, Panel,
FieldConfigSource, FieldConfigSource,
@ -97,7 +98,6 @@ export {
defaultAnnotationQuery, defaultAnnotationQuery,
defaultVariableModel, defaultVariableModel,
VariableHide, VariableHide,
defaultThresholdsConfig,
defaultPanel, defaultPanel,
defaultFieldConfigSource, defaultFieldConfigSource,
defaultMatcherConfig, defaultMatcherConfig,

@ -449,7 +449,7 @@ export interface Threshold {
* Value represents a specified metric for the threshold, which triggers a visual change in the dashboard when this value is met or exceeded. * Value represents a specified metric for the threshold, which triggers a visual change in the dashboard when this value is met or exceeded.
* Nulls currently appear here when serializing -Infinity to JSON. * Nulls currently appear here when serializing -Infinity to JSON.
*/ */
value: number; value: (number | null);
} }
/** /**
@ -521,11 +521,11 @@ export interface RangeMap {
/** /**
* Min value of the range. It can be null which means -Infinity * Min value of the range. It can be null which means -Infinity
*/ */
from: number; from: (number | null);
/** /**
* Max value of the range. It can be null which means +Infinity * Max value of the range. It can be null which means +Infinity
*/ */
to: number; to: (number | null);
/** /**
* Config to apply when the value is within the range * Config to apply when the value is within the range
*/ */

@ -26,10 +26,9 @@ export interface VariableModel extends Omit<raw.VariableModel, 'hide' | 'descrip
datasource: DataSourceRef | null; datasource: DataSourceRef | null;
} }
export interface Dashboard extends Omit<raw.Dashboard, 'templating' | 'annotations' | 'thresholds' | 'panels'> { export interface Dashboard extends Omit<raw.Dashboard, 'templating' | 'annotations' | 'panels'> {
panels?: Array<Panel | RowPanel | raw.GraphPanel | raw.HeatmapPanel>; panels?: Array<Panel | RowPanel | raw.GraphPanel | raw.HeatmapPanel>;
annotations?: AnnotationContainer; annotations?: AnnotationContainer;
thresholds?: ThresholdsConfig;
templating?: { templating?: {
list?: VariableModel[]; list?: VariableModel[];
}; };
@ -45,33 +44,8 @@ export interface AnnotationContainer extends Omit<raw.AnnotationContainer, 'list
list?: AnnotationQuery[]; // use the version from this file list?: AnnotationQuery[]; // use the version from this file
} }
export interface Threshold extends Omit<raw.Threshold, 'value'> { export interface FieldConfig<TOptions = Record<string, unknown>> extends raw.FieldConfig {
// Value represents a lower bound of a threshold. This triggers a visual change in the dashboard when a graphed value is within the bounds of a threshold.
// Nulls currently appear here when serializing -Infinity to JSON.
value: number | null;
}
export interface ThresholdsConfig extends Omit<raw.ThresholdsConfig, 'steps'> {
steps: Threshold[];
}
export interface FieldConfig<TOptions = Record<string, unknown>> extends Omit<raw.FieldConfig, 'mappings'> {
custom?: TOptions & Record<string, unknown>; custom?: TOptions & Record<string, unknown>;
mappings?: ValueMapping[];
}
export type ValueMapping = raw.ValueMap | RangeMap | raw.RegexMap | raw.SpecialValueMap;
export interface RangeMap extends Omit<raw.RangeMap, 'options'> {
// Range to match against and the result to apply when the value is within the range
options: {
// Min value of the range. It can be null which means -Infinity
from: number | null;
// Max value of the range. It can be null which means +Infinity
to: number | null;
// Config to apply when the value is within the range
result: raw.ValueMappingResult;
};
} }
export interface FieldConfigSource<TOptions = Record<string, unknown>> extends Omit<raw.FieldConfigSource, 'defaults'> { export interface FieldConfigSource<TOptions = Record<string, unknown>> extends Omit<raw.FieldConfigSource, 'defaults'> {
@ -101,4 +75,3 @@ export const defaultMatcherConfig: Partial<MatcherConfig> = raw.defaultMatcherCo
export const defaultAnnotationQuery: Partial<AnnotationQuery> = raw.defaultAnnotationQuery as AnnotationQuery; export const defaultAnnotationQuery: Partial<AnnotationQuery> = raw.defaultAnnotationQuery as AnnotationQuery;
export const defaultAnnotationContainer: Partial<AnnotationContainer> = export const defaultAnnotationContainer: Partial<AnnotationContainer> =
raw.defaultAnnotationContainer as AnnotationContainer; raw.defaultAnnotationContainer as AnnotationContainer;
export const defaultThresholdsConfig: Partial<ThresholdsConfig> = raw.defaultThresholdsConfig as ThresholdsConfig;

@ -612,13 +612,13 @@ type RangeMap struct {
// Range to match against and the result to apply when the value is within the range // Range to match against and the result to apply when the value is within the range
Options struct { Options struct {
// Min value of the range. It can be null which means -Infinity // Min value of the range. It can be null which means -Infinity
From float64 `json:"from"` From *float32 `json:"from"`
// Result used as replacement with text and color when the value matches // Result used as replacement with text and color when the value matches
Result ValueMappingResult `json:"result"` Result ValueMappingResult `json:"result"`
// Max value of the range. It can be null which means +Infinity // Max value of the range. It can be null which means +Infinity
To float64 `json:"to"` To *float32 `json:"to"`
} `json:"options"` } `json:"options"`
Type RangeMapType `json:"type"` Type RangeMapType `json:"type"`
} }
@ -866,7 +866,7 @@ type Threshold struct {
// Value represents a specified metric for the threshold, which triggers a visual change in the dashboard when this value is met or exceeded. // Value represents a specified metric for the threshold, which triggers a visual change in the dashboard when this value is met or exceeded.
// Nulls currently appear here when serializing -Infinity to JSON. // Nulls currently appear here when serializing -Infinity to JSON.
Value float32 `json:"value"` Value *float32 `json:"value"`
} }
// Thresholds configuration for the panel // Thresholds configuration for the panel

@ -1162,7 +1162,6 @@ describe('DashboardModel', () => {
steps: [ steps: [
{ {
color: 'green', color: 'green',
// @ts-expect-error
value: null, value: null,
}, },
{ {

Loading…
Cancel
Save