fix: constrain dashboard metric validation
This commit is contained in:
parent
b7c673bbd7
commit
31604ea935
3 changed files with 83 additions and 6 deletions
|
|
@ -64,16 +64,25 @@ const DatasourceReferenceSchema = Type.Union([
|
|||
ExternalDatasourceSchema,
|
||||
]);
|
||||
|
||||
const NumericMetricValueSchema = Type.Object(
|
||||
const PercentMetricValueSchema = Type.Object(
|
||||
{
|
||||
kind: Type.Literal("percent"),
|
||||
value: Type.Number({ minimum: 0, maximum: 100 }),
|
||||
unit: Type.Optional(Type.String({ minLength: 1 })),
|
||||
precision: Type.Optional(Type.Integer({ minimum: 0, maximum: 4 })),
|
||||
},
|
||||
{ additionalProperties: false },
|
||||
);
|
||||
|
||||
const NonNegativeMetricValueSchema = Type.Object(
|
||||
{
|
||||
kind: Type.Union([
|
||||
Type.Literal("percent"),
|
||||
Type.Literal("bytes"),
|
||||
Type.Literal("temperature"),
|
||||
Type.Literal("latency"),
|
||||
Type.Literal("number"),
|
||||
]),
|
||||
value: Type.Number(),
|
||||
value: Type.Number({ minimum: 0 }),
|
||||
unit: Type.Optional(Type.String({ minLength: 1 })),
|
||||
precision: Type.Optional(Type.Integer({ minimum: 0, maximum: 4 })),
|
||||
},
|
||||
|
|
@ -90,14 +99,15 @@ const TextMetricValueSchema = Type.Object(
|
|||
);
|
||||
|
||||
const MetricValueSchema = Type.Union([
|
||||
NumericMetricValueSchema,
|
||||
PercentMetricValueSchema,
|
||||
NonNegativeMetricValueSchema,
|
||||
TextMetricValueSchema,
|
||||
]);
|
||||
|
||||
const ThresholdSchema = Type.Object(
|
||||
{
|
||||
warning: Type.Optional(Type.Number()),
|
||||
danger: Type.Optional(Type.Number()),
|
||||
warning: Type.Optional(Type.Number({ minimum: 0 })),
|
||||
danger: Type.Optional(Type.Number({ minimum: 0 })),
|
||||
},
|
||||
{ additionalProperties: false, minProperties: 1 },
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue