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. 14
      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

@ -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.
@ -395,13 +395,13 @@ lineage: schemas: [{
// 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.

@ -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