From 18b916d9faffc9c1dc04f19b52d407d9cd605977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Wed, 6 Jan 2021 20:37:10 +0100 Subject: [PATCH] Fix the ability to switch to the ratio alert type --- .../components/expression_editor/editor.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx index f69ca798c01b0..82f491c389029 100644 --- a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx +++ b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/editor.tsx @@ -14,10 +14,12 @@ import { ForLastExpression, } from '../../../../../../triggers_actions_ui/public'; import { - PartialAlertParams, Comparator, isRatioAlert, + PartialAlertParams, + PartialCountAlertParams, PartialCriteria as PartialCriteriaType, + PartialRatioAlertParams, ThresholdType, timeUnitRT, } from '../../../../../common/alerting/logs/log_threshold/types'; @@ -47,7 +49,7 @@ interface LogsContextMeta { const DEFAULT_BASE_EXPRESSION = { timeSize: 5, - timeUnit: 'm', + timeUnit: 'm' as const, }; const DEFAULT_FIELD = 'log.level'; @@ -60,7 +62,9 @@ const createDefaultCriterion = ( ? { field: DEFAULT_FIELD, comparator: Comparator.EQ, value } : { field: undefined, comparator: undefined, value: undefined }; -const createDefaultCountAlertParams = (availableFields: LogIndexField[]) => ({ +const createDefaultCountAlertParams = ( + availableFields: LogIndexField[] +): PartialCountAlertParams => ({ ...DEFAULT_BASE_EXPRESSION, count: { value: 75, @@ -69,15 +73,17 @@ const createDefaultCountAlertParams = (availableFields: LogIndexField[]) => ({ criteria: [createDefaultCriterion(availableFields, 'error')], }); -const createDefaultRatioAlertParams = (availableFields: LogIndexField[]) => ({ +const createDefaultRatioAlertParams = ( + availableFields: LogIndexField[] +): PartialRatioAlertParams => ({ ...DEFAULT_BASE_EXPRESSION, count: { value: 2, comparator: Comparator.GT, }, criteria: [ - createDefaultCriterion(availableFields, 'error'), - createDefaultCriterion([], 'warning'), + [createDefaultCriterion(availableFields, 'error')], + [createDefaultCriterion(availableFields, 'warning')], ], });