Skip to content

Commit

Permalink
[RAC][Metrics UI] Index reason field on inventory metric alerts (#1…
Browse files Browse the repository at this point in the history
…06842) (#107061)

Co-authored-by: mgiota <giota85@gmail.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Alejandro Fernández Gómez <alejandro.fernandez@elastic.co>
Co-authored-by: mgiota <giota85@gmail.com>
  • Loading branch information
3 people authored Jul 28, 2021
1 parent 8ee1419 commit 61905cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,12 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import { ALERT_ID } from '@kbn/rule-data-utils';
import { ALERT_REASON } from '@kbn/rule-data-utils';
import { ObservabilityRuleTypeFormatter } from '../../../../observability/public';

export const formatReason: ObservabilityRuleTypeFormatter = ({ fields }) => {
const groupName = fields[ALERT_ID];
const reason = i18n.translate('xpack.infra.metrics.alerting.inventory.alertReasonDescription', {
defaultMessage: 'Inventory alert for {groupName}.', // TEMP reason message, will be deleted once we index the reason field
values: {
groupName,
},
});

const link = '/app/metrics/inventory';
const reason = fields[ALERT_REASON] ?? '-';
const link = '/app/metrics/inventory'; // TODO https://github.com/elastic/kibana/issues/106497

return {
reason,
Expand Down
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 61905cf

Please sign in to comment.