Skip to content

Commit

Permalink
Pass a reason to the alert instance factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Fernández Gómez committed Jul 27, 2021
1 parent 1b2e712 commit 29480f7
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { first, get, last } from 'lodash';
import { i18n } from '@kbn/i18n';
import { ALERT_REASON } from '@kbn/rule-data-utils';
import moment from 'moment';
import { getCustomMetricLabel } from '../../../../common/formatters/get_custom_metric_label';
import { toMetricOpt } from '../../../../common/snapshot_metric_i18n';
Expand Down Expand Up @@ -56,6 +57,7 @@ type InventoryMetricThresholdAlertInstance = AlertInstance<
>;
type InventoryMetricThresholdAlertInstanceFactory = (
id: string,
reason: string,
threshold?: number | undefined,
value?: number | undefined
) => InventoryMetricThresholdAlertInstance;
Expand All @@ -77,10 +79,12 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) =
} = params as InventoryMetricThresholdParams;
if (criteria.length === 0) throw new Error('Cannot execute an alert with 0 conditions');
const { alertWithLifecycle, savedObjectsClient } = services;
const alertInstanceFactory: InventoryMetricThresholdAlertInstanceFactory = (id) =>
const alertInstanceFactory: InventoryMetricThresholdAlertInstanceFactory = (id, reason) =>
alertWithLifecycle({
id,
fields: {},
fields: {
[ALERT_REASON]: reason,
},
});

const source = await libs.sources.getSourceConfiguration(
Expand Down Expand Up @@ -175,7 +179,7 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) =
? WARNING_ACTIONS.id
: FIRED_ACTIONS.id;

const alertInstance = alertInstanceFactory(`${item}`);
const alertInstance = alertInstanceFactory(`${item}`, reason);
alertInstance.scheduleActions(
/**
* TODO: We're lying to the compiler here as explicitly calling `scheduleActions` on
Expand Down

0 comments on commit 29480f7

Please sign in to comment.