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

[Alerting] renames Resolved action group to Recovered #84123

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
10 changes: 5 additions & 5 deletions x-pack/plugins/alerts/common/builtin_action_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import { i18n } from '@kbn/i18n';
import { ActionGroup } from './alert_type';

export const ResolvedActionGroup: ActionGroup = {
id: 'resolved',
name: i18n.translate('xpack.alerts.builtinActionGroups.resolved', {
defaultMessage: 'Resolved',
export const RecoveredActionGroup: ActionGroup = {
id: 'recovered',
name: i18n.translate('xpack.alerts.builtinActionGroups.recovered', {
defaultMessage: 'Recovered',
}),
};

export function getBuiltinActionGroups(): ActionGroup[] {
return [ResolvedActionGroup];
return [RecoveredActionGroup];
}
14 changes: 7 additions & 7 deletions x-pack/plugins/alerts/server/alert_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ describe('register()', () => {
name: 'Default',
},
{
id: 'resolved',
name: 'Resolved',
id: 'recovered',
name: 'Recovered',
},
],
defaultActionGroupId: 'default',
Expand All @@ -117,7 +117,7 @@ describe('register()', () => {

expect(() => registry.register(alertType)).toThrowError(
new Error(
`Alert type [id="${alertType.id}"] cannot be registered. Action groups [resolved] are reserved by the framework.`
`Alert type [id="${alertType.id}"] cannot be registered. Action groups [recovered] are reserved by the framework.`
)
);
});
Expand Down Expand Up @@ -229,8 +229,8 @@ describe('get()', () => {
"name": "Default",
},
Object {
"id": "resolved",
"name": "Resolved",
"id": "recovered",
"name": "Recovered",
},
],
"actionVariables": Object {
Expand Down Expand Up @@ -287,8 +287,8 @@ describe('list()', () => {
"name": "Test Action Group",
},
Object {
"id": "resolved",
"name": "Resolved",
"id": "recovered",
"name": "Recovered",
},
],
"actionVariables": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export class EventsFactory {
'@timestamp': this.date,
event: {
provider: EVENT_LOG_PROVIDER,
action: EVENT_LOG_ACTIONS.resolvedInstance,
action: EVENT_LOG_ACTIONS.recoveredInstance,
gmmorris marked this conversation as resolved.
Show resolved Hide resolved
},
kibana: { alerting: { instance_id: instanceId } },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function alertInstanceSummaryFromEventLog(
status.status = 'Active';
status.actionGroupId = event?.kibana?.alerting?.action_group_id;
break;
case EVENT_LOG_ACTIONS.resolvedInstance:
case EVENT_LOG_ACTIONS.recoveredInstance:
gmmorris marked this conversation as resolved.
Show resolved Hide resolved
status.status = 'OK';
status.activeStartDate = undefined;
status.actionGroupId = undefined;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerts/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const EVENT_LOG_ACTIONS = {
execute: 'execute',
executeAction: 'execute-action',
newInstance: 'new-instance',
resolvedInstance: 'resolved-instance',
recoveredInstance: 'recovered-instance',
gmmorris marked this conversation as resolved.
Show resolved Hide resolved
activeInstance: 'active-instance',
};

Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/alerts/server/task_runner/task_runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import { alertsMock, alertsClientMock } from '../mocks';
import { eventLoggerMock } from '../../../event_log/server/event_logger.mock';
import { IEventLogger } from '../../../event_log/server';
import { SavedObjectsErrorHelpers } from '../../../../../src/core/server';
import { Alert, ResolvedActionGroup } from '../../common';
import { Alert, RecoveredActionGroup } from '../../common';
import { omit } from 'lodash';
const alertType = {
id: 'test',
name: 'My test alert',
actionGroups: [{ id: 'default', name: 'Default' }, ResolvedActionGroup],
actionGroups: [{ id: 'default', name: 'Default' }, RecoveredActionGroup],
defaultActionGroupId: 'default',
executor: jest.fn(),
producer: 'alerts',
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('Task Runner', () => {
},
},
{
group: ResolvedActionGroup.id,
group: RecoveredActionGroup.id,
id: '2',
actionTypeId: 'action',
params: {
Expand Down Expand Up @@ -517,7 +517,7 @@ describe('Task Runner', () => {
`);
});

test('fire resolved actions for execution for the alertInstances which is in the resolved state', async () => {
test('fire recovered actions for execution for the alertInstances which is in the recovered state', async () => {
taskRunnerFactoryInitializerParams.actionsPlugin.isActionTypeEnabled.mockReturnValue(true);
taskRunnerFactoryInitializerParams.actionsPlugin.isActionExecutable.mockReturnValue(true);

Expand Down Expand Up @@ -650,7 +650,7 @@ describe('Task Runner', () => {
Array [
Object {
"event": Object {
"action": "resolved-instance",
"action": "recovered-instance",
},
"kibana": Object {
"alerting": Object {
Expand All @@ -666,7 +666,7 @@ describe('Task Runner', () => {
},
],
},
"message": "test:1: 'alert-name' resolved instance: '2'",
"message": "test:1: 'alert-name' recovered instance: '2'",
},
],
Array [
Expand Down
32 changes: 17 additions & 15 deletions x-pack/plugins/alerts/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { IEvent, IEventLogger, SAVED_OBJECT_REL_PRIMARY } from '../../../event_l
import { isAlertSavedObjectNotFoundError } from '../lib/is_alert_not_found_error';
import { AlertsClient } from '../alerts_client';
import { partiallyUpdateAlert } from '../saved_objects';
import { ResolvedActionGroup } from '../../common';
import { RecoveredActionGroup } from '../../common';

const FALLBACK_RETRY_INTERVAL = '5m';

Expand Down Expand Up @@ -219,7 +219,7 @@ export class TaskRunner {
alertInstance.hasScheduledActions()
);

generateNewAndResolvedInstanceEvents({
generateNewAndRecoveredInstanceEvents({
eventLogger,
originalAlertInstances,
currentAlertInstances: instancesWithScheduledActions,
Expand All @@ -229,7 +229,7 @@ export class TaskRunner {
});

if (!muteAll) {
scheduleActionsForResolvedInstances(
scheduleActionsForRecoveredInstances(
alertInstances,
executionHandler,
originalAlertInstances,
Expand Down Expand Up @@ -436,7 +436,7 @@ export class TaskRunner {
}
}

interface GenerateNewAndResolvedInstanceEventsParams {
interface GenerateNewAndRecoveredInstanceEventsParams {
eventLogger: IEventLogger;
originalAlertInstances: Dictionary<AlertInstance>;
currentAlertInstances: Dictionary<AlertInstance>;
Expand All @@ -445,18 +445,20 @@ interface GenerateNewAndResolvedInstanceEventsParams {
namespace: string | undefined;
}

function generateNewAndResolvedInstanceEvents(params: GenerateNewAndResolvedInstanceEventsParams) {
function generateNewAndRecoveredInstanceEvents(
params: GenerateNewAndRecoveredInstanceEventsParams
) {
const { eventLogger, alertId, namespace, currentAlertInstances, originalAlertInstances } = params;
const originalAlertInstanceIds = Object.keys(originalAlertInstances);
const currentAlertInstanceIds = Object.keys(currentAlertInstances);

const newIds = without(currentAlertInstanceIds, ...originalAlertInstanceIds);
const resolvedIds = without(originalAlertInstanceIds, ...currentAlertInstanceIds);
const recoveredIds = without(originalAlertInstanceIds, ...currentAlertInstanceIds);

for (const id of resolvedIds) {
for (const id of recoveredIds) {
const actionGroup = originalAlertInstances[id].getLastScheduledActions()?.group;
const message = `${params.alertLabel} resolved instance: '${id}'`;
logInstanceEvent(id, EVENT_LOG_ACTIONS.resolvedInstance, message, actionGroup);
const message = `${params.alertLabel} recovered instance: '${id}'`;
gmmorris marked this conversation as resolved.
Show resolved Hide resolved
logInstanceEvent(id, EVENT_LOG_ACTIONS.recoveredInstance, message, actionGroup);
}

for (const id of newIds) {
Expand Down Expand Up @@ -496,7 +498,7 @@ function generateNewAndResolvedInstanceEvents(params: GenerateNewAndResolvedInst
}
}

function scheduleActionsForResolvedInstances(
function scheduleActionsForRecoveredInstances(
alertInstancesMap: Record<string, AlertInstance>,
executionHandler: ReturnType<typeof createExecutionHandler>,
originalAlertInstances: Record<string, AlertInstance>,
Expand All @@ -505,22 +507,22 @@ function scheduleActionsForResolvedInstances(
) {
const currentAlertInstanceIds = Object.keys(currentAlertInstances);
const originalAlertInstanceIds = Object.keys(originalAlertInstances);
const resolvedIds = without(
const recoveredIds = without(
originalAlertInstanceIds,
...currentAlertInstanceIds,
...mutedInstanceIds
);
for (const id of resolvedIds) {
for (const id of recoveredIds) {
const instance = alertInstancesMap[id];
instance.updateLastScheduledActions(ResolvedActionGroup.id);
instance.updateLastScheduledActions(RecoveredActionGroup.id);
instance.unscheduleActions();
executionHandler({
actionGroup: ResolvedActionGroup.id,
actionGroup: RecoveredActionGroup.id,
context: {},
state: {},
alertInstanceId: id,
});
instance.scheduleActions(ResolvedActionGroup.id);
instance.scheduleActions(RecoveredActionGroup.id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import moment from 'moment';
import { getCustomMetricLabel } from '../../../../common/formatters/get_custom_metric_label';
import { toMetricOpt } from '../../../../common/snapshot_metric_i18n';
import { AlertStates, InventoryMetricConditions } from './types';
import { ResolvedActionGroup } from '../../../../../alerts/common';
import { RecoveredActionGroup } from '../../../../../alerts/common';
import { AlertExecutorOptions } from '../../../../../alerts/server';
import { InventoryItemType, SnapshotMetricType } from '../../../../common/inventory_models/types';
import { InfraBackendLibs } from '../../infra_types';
Expand Down Expand Up @@ -103,7 +103,7 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) =
}
if (reason) {
const actionGroupId =
nextState === AlertStates.OK ? ResolvedActionGroup.id : FIRED_ACTIONS.id;
nextState === AlertStates.OK ? RecoveredActionGroup.id : FIRED_ACTIONS.id;
alertInstance.scheduleActions(actionGroupId, {
group: item,
alertState: stateToAlertMessage[nextState],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { createMetricThresholdExecutor, FIRED_ACTIONS } from './metric_threshold_executor';
import { Comparator, AlertStates } from './types';
import * as mocks from './test_mocks';
import { ResolvedActionGroup } from '../../../../../alerts/common';
import { RecoveredActionGroup } from '../../../../../alerts/common';
import { AlertExecutorOptions } from '../../../../../alerts/server';
import {
alertsMock,
Expand Down Expand Up @@ -367,7 +367,7 @@ describe('The metric threshold alert type', () => {
expect(mostRecentAction(instanceID).id).toBe(FIRED_ACTIONS.id);
expect(getState(instanceID).alertState).toBe(AlertStates.ALERT);
await execute([2]);
expect(mostRecentAction(instanceID).id).toBe(ResolvedActionGroup.id);
expect(mostRecentAction(instanceID).id).toBe(RecoveredActionGroup.id);
expect(getState(instanceID).alertState).toBe(AlertStates.OK);
});
test('does not continue to send a recovery alert if the metric is still OK', async () => {
Expand All @@ -383,7 +383,7 @@ describe('The metric threshold alert type', () => {
expect(mostRecentAction(instanceID).id).toBe(FIRED_ACTIONS.id);
expect(getState(instanceID).alertState).toBe(AlertStates.ALERT);
await execute([2]);
expect(mostRecentAction(instanceID).id).toBe(ResolvedActionGroup.id);
expect(mostRecentAction(instanceID).id).toBe(RecoveredActionGroup.id);
expect(getState(instanceID).alertState).toBe(AlertStates.OK);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { first, last } from 'lodash';
import { i18n } from '@kbn/i18n';
import moment from 'moment';
import { ResolvedActionGroup } from '../../../../../alerts/common';
import { RecoveredActionGroup } from '../../../../../alerts/common';
import { AlertExecutorOptions } from '../../../../../alerts/server';
import { InfraBackendLibs } from '../../infra_types';
import {
Expand Down Expand Up @@ -89,7 +89,7 @@ export const createMetricThresholdExecutor = (libs: InfraBackendLibs) =>
const firstResult = first(alertResults);
const timestamp = (firstResult && firstResult[group].timestamp) ?? moment().toISOString();
const actionGroupId =
nextState === AlertStates.OK ? ResolvedActionGroup.id : FIRED_ACTIONS.id;
nextState === AlertStates.OK ? RecoveredActionGroup.id : FIRED_ACTIONS.id;
alertInstance.scheduleActions(actionGroupId, {
group,
alertState: stateToAlertMessage[nextState],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ActionParamsProps } from '../../../../types';
import { EmailActionParams } from '../types';
import { TextFieldWithMessageVariables } from '../../text_field_with_message_variables';
import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables';
import { resolvedActionGroupMessage } from '../../../constants';
import { recoveredActionGroupMessage } from '../../../constants';

export const EmailParamsFields = ({
actionParams,
Expand All @@ -29,10 +29,10 @@ export const EmailParamsFields = ({
const [addBCC, setAddBCC] = useState<boolean>(false);

useEffect(() => {
if (defaultMessage === resolvedActionGroupMessage) {
if (defaultMessage === recoveredActionGroupMessage) {
editAction('message', defaultMessage, index);
} else if (
(!message || message === resolvedActionGroupMessage) &&
(!message || message === recoveredActionGroupMessage) &&
defaultMessage &&
defaultMessage.length > 0
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EuiSelect, EuiFormRow } from '@elastic/eui';
import { ActionParamsProps } from '../../../../types';
import { ServerLogActionParams } from '.././types';
import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables';
import { resolvedActionGroupMessage } from '../../../constants';
import { recoveredActionGroupMessage } from '../../../constants';

export const ServerLogParamsFields: React.FunctionComponent<
ActionParamsProps<ServerLogActionParams>
Expand All @@ -32,10 +32,10 @@ export const ServerLogParamsFields: React.FunctionComponent<
}, []);

useEffect(() => {
if (defaultMessage === resolvedActionGroupMessage) {
if (defaultMessage === recoveredActionGroupMessage) {
editAction('message', defaultMessage, index);
} else if (
(!message || message === resolvedActionGroupMessage) &&
(!message || message === recoveredActionGroupMessage) &&
defaultMessage &&
defaultMessage.length > 0
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { i18n } from '@kbn/i18n';
import { ActionParamsProps } from '../../../../types';
import { SlackActionParams } from '../types';
import { TextAreaWithMessageVariables } from '../../text_area_with_message_variables';
import { resolvedActionGroupMessage } from '../../../constants';
import { recoveredActionGroupMessage } from '../../../constants';

const SlackParamsFields: React.FunctionComponent<ActionParamsProps<SlackActionParams>> = ({
actionParams,
Expand All @@ -20,10 +20,10 @@ const SlackParamsFields: React.FunctionComponent<ActionParamsProps<SlackActionPa
}) => {
const { message } = actionParams;
useEffect(() => {
if (defaultMessage === resolvedActionGroupMessage) {
if (defaultMessage === recoveredActionGroupMessage) {
editAction('message', defaultMessage, index);
} else if (
(!message || message === resolvedActionGroupMessage) &&
(!message || message === recoveredActionGroupMessage) &&
defaultMessage &&
defaultMessage.length > 0
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export const routeToConnectors = `/connectors`;
export const routeToAlerts = `/alerts`;
export const routeToAlertDetails = `/alert/:alertId`;

export const resolvedActionGroupMessage = i18n.translate(
'xpack.triggersActionsUI.sections.actionForm.ResolvedMessage',
export const recoveredActionGroupMessage = i18n.translate(
'xpack.triggersActionsUI.sections.actionForm.RecoveredMessage',
{
defaultMessage: 'Resolved',
defaultMessage: 'Recovered',
}
);

Expand Down
Loading