Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RAC][Metrics UI] Index reason field on inventory metric alerts #106842

Merged
merged 5 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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