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.", "3"],
[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.", "6"]
[0, 0, 0, "Do not use any type assertions.", "5"]
],
"packages/grafana-toolkit/src/cli/tasks/task.ts:5381": [
[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
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 |
|----------|--------|----------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `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. |
| 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. |
| `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
@ -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
| Property | Type | Required | Default | Description |
|----------|-------------------------------------------|----------|---------|-----------------------------------------------------------------------|
| `from` | number | **Yes** | | Min value of the range. It can be null which means -Infinity |
| `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 |
| Property | Type | Required | Default | Description |
|----------|-------------------------------------------|----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `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 |
| `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

@ -197,7 +197,7 @@ lineage: schemas: [{
name: string
// Optional display name
label?: string
// Visibility configuration for the variable
// Visibility configuration for the variable
hide: #VariableHide
// Whether the variable value should be managed by URL query params or not
skipUrlSync: bool | *false
@ -231,8 +231,8 @@ lineage: schemas: [{
// 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.
// `1`: Queries the data source every time the dashboard loads.
// `2`: Queries the data source when the dashboard time range changes.
#VariableRefresh: 0 | 1 | 2 @cuetsy(kind="enum",memberNames="never|onDashboardLoad|onTimeRangeChanged")
// Determine if the variable shows on dashboard
@ -291,17 +291,17 @@ lineage: schemas: [{
#DashboardLinkType: "link" | "dashboards" @cuetsy(kind="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).
// `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.
// `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
#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.
// Accepted values are:
// `thresholds`: From thresholds. Informs Grafana to take the color from the matching threshold
@ -353,10 +353,10 @@ lineage: schemas: [{
#Threshold: {
// 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.
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: 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).
#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
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
#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
// `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.
#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.
#ValueMap: {
type: #MappingType & "value"
@ -388,22 +388,22 @@ lineage: schemas: [{
options: [string]: #ValueMappingResult
} @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.
#RangeMap: {
type: #MappingType & "range"
// 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: float64
from: float64 | null
// 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
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.
#RegexMap: {
type: #MappingType & "regex"
@ -416,8 +416,8 @@ lineage: schemas: [{
}
} @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.
// See SpecialValueMatch to see the list of special values.
// 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.
#SpecialValueMap: {
type: #MappingType & "special"
@ -444,8 +444,8 @@ lineage: schemas: [{
index?: int32
} @cuetsy(kind="interface")
// 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,
// 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,
// use the output of one transformation as the input to another transformation, etc.
#DataTransformerConfig: {
// Unique identifier of transformer
@ -503,7 +503,7 @@ lineage: schemas: [{
userId: uint32 @grafanamaturity(NeedsExpertReview)
} @grafanamaturity(NeedsExpertReview)
// Dashboard panels are the basic visualization building blocks.
// Dashboard panels are the basic visualization building blocks.
#Panel: {
// The panel plugin type id. This is used to find the plugin to display the panel.
type: string & strings.MinRunes(1)
@ -552,27 +552,27 @@ lineage: schemas: [{
maxDataPoints?: number
// 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.
transformations: [...#DataTransformerConfig]
// 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.
// See: https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/#query-options
interval?: string
// Overrides the relative time range for individual panels,
// 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
// Overrides the relative time range for individual panels,
// 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
// 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).
// 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
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`.
// 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
@ -588,7 +588,7 @@ lineage: schemas: [{
fieldConfig: #FieldConfigSource
} @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.
// Field options allow you to change how the data is displayed in your visualizations.
#FieldConfigSource: {
@ -601,8 +601,8 @@ lineage: schemas: [{
}] @grafanamaturity(NeedsExpertReview)
} @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview)
// 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.
// 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.
// Library panels streamline reuse of panels across multiple dashboards.
#LibraryPanelRef: {
// Library panel name
@ -625,7 +625,7 @@ lineage: schemas: [{
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.
// Field options allow you to change how the data is displayed in your visualizations.
#FieldConfig: {
@ -664,8 +664,8 @@ lineage: schemas: [{
// `currency:<unit>` for custom a currency unit.
unit?: string @grafanamaturity(NeedsExpertReview)
// 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.
// 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.
// 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`.
decimals?: number @grafanamaturity(NeedsExpertReview)

@ -29,7 +29,11 @@ export type {
FieldColorSeriesByMode,
FieldColor,
GridPos,
Threshold,
ThresholdsConfig,
ValueMapping,
ValueMap,
RangeMap,
RegexMap,
SpecialValueMap,
ValueMappingResult,
@ -49,6 +53,7 @@ export {
FieldColorModeId,
defaultGridPos,
ThresholdsMode,
defaultThresholdsConfig,
MappingType,
SpecialValueMatch,
DashboardCursorSync,
@ -70,10 +75,6 @@ export type {
AnnotationQuery,
VariableModel,
DataSourceRef,
Threshold,
ThresholdsConfig,
ValueMapping,
RangeMap,
DataTransformerConfig,
Panel,
FieldConfigSource,
@ -97,7 +98,6 @@ export {
defaultAnnotationQuery,
defaultVariableModel,
VariableHide,
defaultThresholdsConfig,
defaultPanel,
defaultFieldConfigSource,
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.
* 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
*/
from: number;
from: (number | null);
/**
* 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
*/

@ -26,10 +26,9 @@ export interface VariableModel extends Omit<raw.VariableModel, 'hide' | 'descrip
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>;
annotations?: AnnotationContainer;
thresholds?: ThresholdsConfig;
templating?: {
list?: VariableModel[];
};
@ -45,33 +44,8 @@ export interface AnnotationContainer extends Omit<raw.AnnotationContainer, 'list
list?: AnnotationQuery[]; // use the version from this file
}
export interface Threshold extends Omit<raw.Threshold, 'value'> {
// 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'> {
export interface FieldConfig<TOptions = Record<string, unknown>> extends raw.FieldConfig {
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'> {
@ -101,4 +75,3 @@ export const defaultMatcherConfig: Partial<MatcherConfig> = raw.defaultMatcherCo
export const defaultAnnotationQuery: Partial<AnnotationQuery> = raw.defaultAnnotationQuery as AnnotationQuery;
export const defaultAnnotationContainer: Partial<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
Options struct {
// 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 ValueMappingResult `json:"result"`
// Max value of the range. It can be null which means +Infinity
To float64 `json:"to"`
To *float32 `json:"to"`
} `json:"options"`
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.
// Nulls currently appear here when serializing -Infinity to JSON.
Value float32 `json:"value"`
Value *float32 `json:"value"`
}
// Thresholds configuration for the panel

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

Loading…
Cancel
Save