Skip to content

Commit

Permalink
[Logs UI] Fix the ability to switch to the ratio alert type (elastic#…
Browse files Browse the repository at this point in the history
…87563)

This fixes a bug introduced with elastic#86488, which prevents the user from changing the log threshold alert type to `ratio`.
  • Loading branch information
weltenwort committed Jan 7, 2021
1 parent 3283ec0 commit 350d067
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -47,7 +49,7 @@ interface LogsContextMeta {

const DEFAULT_BASE_EXPRESSION = {
timeSize: 5,
timeUnit: 'm',
timeUnit: 'm' as const,
};

const DEFAULT_FIELD = 'log.level';
Expand All @@ -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,
Expand All @@ -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')],
],
});

Expand Down

0 comments on commit 350d067

Please sign in to comment.