mirror of
https://github.com/grafana/grafana.git
synced 2025-09-19 18:22:58 +08:00
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
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -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.
|
||||
@ -395,13 +395,13 @@ lineage: schemas: [{
|
||||
// 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.
|
||||
// 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,
|
||||
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,
|
||||
},
|
||||
{
|
||||
|
Reference in New Issue
Block a user