Skip to content

Commit

Permalink
Ensure that if alert instances are instantiated they are used in a wa…
Browse files Browse the repository at this point in the history
…y recognised by the framework
  • Loading branch information
Kerry350 committed Jan 5, 2021
1 parent 875fde5 commit 9438a17
Showing 1 changed file with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) =>
const sourceConfiguration = await sources.getSourceConfiguration(savedObjectsClient, 'default');
const indexPattern = sourceConfiguration.configuration.logAlias;
const timestampField = sourceConfiguration.configuration.fields.timestamp;
const alertInstance = alertInstanceFactory(UNGROUPED_FACTORY_KEY);

try {
const validatedParams = decodeOrThrow(alertParamsRT)(params);
Expand All @@ -87,10 +86,6 @@ export const createLogThresholdExecutor = (libs: InfraBackendLibs) =>
);
}
} catch (e) {
alertInstance.replaceState({
alertState: AlertStates.ERROR,
});

throw new Error(e);
}
};
Expand Down Expand Up @@ -190,11 +185,10 @@ export const processUngroupedResults = (
alertInstaceUpdater: AlertInstanceUpdater
) => {
const { count, criteria } = params;

const alertInstance = alertInstanceFactory(UNGROUPED_FACTORY_KEY);
const documentCount = results.hits.total.value;

if (checkValueAgainstComparatorMap[count.comparator](documentCount, count.value)) {
const alertInstance = alertInstanceFactory(UNGROUPED_FACTORY_KEY);
alertInstaceUpdater(alertInstance, AlertStates.ALERT, [
{
actionGroup: FIRED_ACTIONS.id,
Expand All @@ -206,8 +200,6 @@ export const processUngroupedResults = (
},
},
]);
} else {
alertInstaceUpdater(alertInstance, AlertStates.OK);
}
};

Expand All @@ -220,12 +212,12 @@ export const processUngroupedRatioResults = (
) => {
const { count, criteria } = params;

const alertInstance = alertInstanceFactory(UNGROUPED_FACTORY_KEY);
const numeratorCount = numeratorResults.hits.total.value;
const denominatorCount = denominatorResults.hits.total.value;
const ratio = getRatio(numeratorCount, denominatorCount);

if (ratio !== undefined && checkValueAgainstComparatorMap[count.comparator](ratio, count.value)) {
const alertInstance = alertInstanceFactory(UNGROUPED_FACTORY_KEY);
alertInstaceUpdater(alertInstance, AlertStates.ALERT, [
{
actionGroup: FIRED_ACTIONS.id,
Expand All @@ -238,8 +230,6 @@ export const processUngroupedRatioResults = (
},
},
]);
} else {
alertInstaceUpdater(alertInstance, AlertStates.OK);
}
};

Expand Down Expand Up @@ -278,10 +268,10 @@ export const processGroupByResults = (
const groupResults = getReducedGroupByResults(results);

groupResults.forEach((group) => {
const alertInstance = alertInstanceFactory(group.name);
const documentCount = group.documentCount;

if (checkValueAgainstComparatorMap[count.comparator](documentCount, count.value)) {
const alertInstance = alertInstanceFactory(group.name);
alertInstaceUpdater(alertInstance, AlertStates.ALERT, [
{
actionGroup: FIRED_ACTIONS.id,
Expand All @@ -293,8 +283,6 @@ export const processGroupByResults = (
},
},
]);
} else {
alertInstaceUpdater(alertInstance, AlertStates.OK);
}
});
};
Expand All @@ -312,7 +300,6 @@ export const processGroupByRatioResults = (
const denominatorGroupResults = getReducedGroupByResults(denominatorResults);

numeratorGroupResults.forEach((numeratorGroup) => {
const alertInstance = alertInstanceFactory(numeratorGroup.name);
const numeratorDocumentCount = numeratorGroup.documentCount;
const denominatorGroup = denominatorGroupResults.find(
(_group) => _group.name === numeratorGroup.name
Expand All @@ -325,6 +312,7 @@ export const processGroupByRatioResults = (
ratio !== undefined &&
checkValueAgainstComparatorMap[count.comparator](ratio, count.value)
) {
const alertInstance = alertInstanceFactory(numeratorGroup.name);
alertInstaceUpdater(alertInstance, AlertStates.ALERT, [
{
actionGroup: FIRED_ACTIONS.id,
Expand All @@ -337,8 +325,6 @@ export const processGroupByRatioResults = (
},
},
]);
} else {
alertInstaceUpdater(alertInstance, AlertStates.OK);
}
});
};
Expand Down

0 comments on commit 9438a17

Please sign in to comment.