Skip to content

Commit e14a150

Browse files
authored
Revert the Revert of "[Alerting] renames Resolved action group to Recovered (#84123)" (#84662) (#84701)
Reapplies the #84123 PR: This PR changes the default term from “Resolved” to “Recovered”, as it fits most use cases and we feel users are most likely to understand its meaning across domains. # Conflicts: # x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_type_form.tsx
1 parent 30604e4 commit e14a150

21 files changed

+152
-95
lines changed

x-pack/plugins/alerts/common/builtin_action_groups.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import { i18n } from '@kbn/i18n';
77
import { ActionGroup } from './alert_type';
88

9-
export const ResolvedActionGroup: ActionGroup = {
10-
id: 'resolved',
11-
name: i18n.translate('xpack.alerts.builtinActionGroups.resolved', {
12-
defaultMessage: 'Resolved',
9+
export const RecoveredActionGroup: ActionGroup = {
10+
id: 'recovered',
11+
name: i18n.translate('xpack.alerts.builtinActionGroups.recovered', {
12+
defaultMessage: 'Recovered',
1313
}),
1414
};
1515

1616
export function getBuiltinActionGroups(): ActionGroup[] {
17-
return [ResolvedActionGroup];
17+
return [RecoveredActionGroup];
1818
}

x-pack/plugins/alerts/server/alert_type_registry.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ describe('register()', () => {
105105
name: 'Default',
106106
},
107107
{
108-
id: 'resolved',
109-
name: 'Resolved',
108+
id: 'recovered',
109+
name: 'Recovered',
110110
},
111111
],
112112
defaultActionGroupId: 'default',
@@ -117,7 +117,7 @@ describe('register()', () => {
117117

118118
expect(() => registry.register(alertType)).toThrowError(
119119
new Error(
120-
`Alert type [id="${alertType.id}"] cannot be registered. Action groups [resolved] are reserved by the framework.`
120+
`Alert type [id="${alertType.id}"] cannot be registered. Action groups [recovered] are reserved by the framework.`
121121
)
122122
);
123123
});
@@ -229,8 +229,8 @@ describe('get()', () => {
229229
"name": "Default",
230230
},
231231
Object {
232-
"id": "resolved",
233-
"name": "Resolved",
232+
"id": "recovered",
233+
"name": "Recovered",
234234
},
235235
],
236236
"actionVariables": Object {
@@ -287,8 +287,8 @@ describe('list()', () => {
287287
"name": "Test Action Group",
288288
},
289289
Object {
290-
"id": "resolved",
291-
"name": "Resolved",
290+
"id": "recovered",
291+
"name": "Recovered",
292292
},
293293
],
294294
"actionVariables": Object {

x-pack/plugins/alerts/server/alerts_client/tests/get_alert_instance_summary.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('getAlertInstanceSummary()', () => {
122122
.addActiveInstance('instance-previously-active', 'action group B')
123123
.advanceTime(10000)
124124
.addExecute()
125-
.addResolvedInstance('instance-previously-active')
125+
.addRecoveredInstance('instance-previously-active')
126126
.addActiveInstance('instance-currently-active', 'action group A')
127127
.getEvents();
128128
const eventsResult = {

x-pack/plugins/alerts/server/lib/alert_instance_summary_from_event_log.test.ts

+55-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { SanitizedAlert, AlertInstanceSummary } from '../types';
88
import { IValidatedEvent } from '../../../event_log/server';
9-
import { EVENT_LOG_ACTIONS, EVENT_LOG_PROVIDER } from '../plugin';
9+
import { EVENT_LOG_ACTIONS, EVENT_LOG_PROVIDER, LEGACY_EVENT_LOG_ACTIONS } from '../plugin';
1010
import { alertInstanceSummaryFromEventLog } from './alert_instance_summary_from_event_log';
1111

1212
const ONE_HOUR_IN_MILLIS = 60 * 60 * 1000;
@@ -189,7 +189,43 @@ describe('alertInstanceSummaryFromEventLog', () => {
189189
.addActiveInstance('instance-1', 'action group A')
190190
.advanceTime(10000)
191191
.addExecute()
192-
.addResolvedInstance('instance-1')
192+
.addRecoveredInstance('instance-1')
193+
.getEvents();
194+
195+
const summary: AlertInstanceSummary = alertInstanceSummaryFromEventLog({
196+
alert,
197+
events,
198+
dateStart,
199+
dateEnd,
200+
});
201+
202+
const { lastRun, status, instances } = summary;
203+
expect({ lastRun, status, instances }).toMatchInlineSnapshot(`
204+
Object {
205+
"instances": Object {
206+
"instance-1": Object {
207+
"actionGroupId": undefined,
208+
"activeStartDate": undefined,
209+
"muted": false,
210+
"status": "OK",
211+
},
212+
},
213+
"lastRun": "2020-06-18T00:00:10.000Z",
214+
"status": "OK",
215+
}
216+
`);
217+
});
218+
219+
test('legacy alert with currently inactive instance', async () => {
220+
const alert = createAlert({});
221+
const eventsFactory = new EventsFactory();
222+
const events = eventsFactory
223+
.addExecute()
224+
.addNewInstance('instance-1')
225+
.addActiveInstance('instance-1', 'action group A')
226+
.advanceTime(10000)
227+
.addExecute()
228+
.addLegacyResolvedInstance('instance-1')
193229
.getEvents();
194230

195231
const summary: AlertInstanceSummary = alertInstanceSummaryFromEventLog({
@@ -224,7 +260,7 @@ describe('alertInstanceSummaryFromEventLog', () => {
224260
.addActiveInstance('instance-1', 'action group A')
225261
.advanceTime(10000)
226262
.addExecute()
227-
.addResolvedInstance('instance-1')
263+
.addRecoveredInstance('instance-1')
228264
.getEvents();
229265

230266
const summary: AlertInstanceSummary = alertInstanceSummaryFromEventLog({
@@ -406,7 +442,7 @@ describe('alertInstanceSummaryFromEventLog', () => {
406442
.advanceTime(10000)
407443
.addExecute()
408444
.addActiveInstance('instance-1', 'action group A')
409-
.addResolvedInstance('instance-2')
445+
.addRecoveredInstance('instance-2')
410446
.getEvents();
411447

412448
const summary: AlertInstanceSummary = alertInstanceSummaryFromEventLog({
@@ -451,7 +487,7 @@ describe('alertInstanceSummaryFromEventLog', () => {
451487
.advanceTime(10000)
452488
.addExecute()
453489
.addActiveInstance('instance-1', 'action group A')
454-
.addResolvedInstance('instance-2')
490+
.addRecoveredInstance('instance-2')
455491
.advanceTime(10000)
456492
.addExecute()
457493
.addActiveInstance('instance-1', 'action group B')
@@ -561,12 +597,24 @@ export class EventsFactory {
561597
return this;
562598
}
563599

564-
addResolvedInstance(instanceId: string): EventsFactory {
600+
addRecoveredInstance(instanceId: string): EventsFactory {
601+
this.events.push({
602+
'@timestamp': this.date,
603+
event: {
604+
provider: EVENT_LOG_PROVIDER,
605+
action: EVENT_LOG_ACTIONS.recoveredInstance,
606+
},
607+
kibana: { alerting: { instance_id: instanceId } },
608+
});
609+
return this;
610+
}
611+
612+
addLegacyResolvedInstance(instanceId: string): EventsFactory {
565613
this.events.push({
566614
'@timestamp': this.date,
567615
event: {
568616
provider: EVENT_LOG_PROVIDER,
569-
action: EVENT_LOG_ACTIONS.resolvedInstance,
617+
action: LEGACY_EVENT_LOG_ACTIONS.resolvedInstance,
570618
},
571619
kibana: { alerting: { instance_id: instanceId } },
572620
});

x-pack/plugins/alerts/server/lib/alert_instance_summary_from_event_log.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import { SanitizedAlert, AlertInstanceSummary, AlertInstanceStatus } from '../types';
88
import { IEvent } from '../../../event_log/server';
9-
import { EVENT_LOG_ACTIONS, EVENT_LOG_PROVIDER } from '../plugin';
9+
import { EVENT_LOG_ACTIONS, EVENT_LOG_PROVIDER, LEGACY_EVENT_LOG_ACTIONS } from '../plugin';
1010

1111
export interface AlertInstanceSummaryFromEventLogParams {
1212
alert: SanitizedAlert;
@@ -80,7 +80,8 @@ export function alertInstanceSummaryFromEventLog(
8080
status.status = 'Active';
8181
status.actionGroupId = event?.kibana?.alerting?.action_group_id;
8282
break;
83-
case EVENT_LOG_ACTIONS.resolvedInstance:
83+
case LEGACY_EVENT_LOG_ACTIONS.resolvedInstance:
84+
case EVENT_LOG_ACTIONS.recoveredInstance:
8485
status.status = 'OK';
8586
status.activeStartDate = undefined;
8687
status.actionGroupId = undefined;

x-pack/plugins/alerts/server/plugin.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ export const EVENT_LOG_ACTIONS = {
8282
execute: 'execute',
8383
executeAction: 'execute-action',
8484
newInstance: 'new-instance',
85-
resolvedInstance: 'resolved-instance',
85+
recoveredInstance: 'recovered-instance',
8686
activeInstance: 'active-instance',
8787
};
88+
export const LEGACY_EVENT_LOG_ACTIONS = {
89+
resolvedInstance: 'resolved-instance',
90+
};
8891

8992
export interface PluginSetupContract {
9093
registerType: AlertTypeRegistry['register'];

x-pack/plugins/alerts/server/task_runner/task_runner.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import { alertsMock, alertsClientMock } from '../mocks';
2626
import { eventLoggerMock } from '../../../event_log/server/event_logger.mock';
2727
import { IEventLogger } from '../../../event_log/server';
2828
import { SavedObjectsErrorHelpers } from '../../../../../src/core/server';
29-
import { Alert, ResolvedActionGroup } from '../../common';
29+
import { Alert, RecoveredActionGroup } from '../../common';
3030
import { omit } from 'lodash';
3131
const alertType = {
3232
id: 'test',
3333
name: 'My test alert',
34-
actionGroups: [{ id: 'default', name: 'Default' }, ResolvedActionGroup],
34+
actionGroups: [{ id: 'default', name: 'Default' }, RecoveredActionGroup],
3535
defaultActionGroupId: 'default',
3636
executor: jest.fn(),
3737
producer: 'alerts',
@@ -114,7 +114,7 @@ describe('Task Runner', () => {
114114
},
115115
},
116116
{
117-
group: ResolvedActionGroup.id,
117+
group: RecoveredActionGroup.id,
118118
id: '2',
119119
actionTypeId: 'action',
120120
params: {
@@ -517,7 +517,7 @@ describe('Task Runner', () => {
517517
`);
518518
});
519519

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

@@ -650,7 +650,7 @@ describe('Task Runner', () => {
650650
Array [
651651
Object {
652652
"event": Object {
653-
"action": "resolved-instance",
653+
"action": "recovered-instance",
654654
},
655655
"kibana": Object {
656656
"alerting": Object {
@@ -666,7 +666,7 @@ describe('Task Runner', () => {
666666
},
667667
],
668668
},
669-
"message": "test:1: 'alert-name' resolved instance: '2'",
669+
"message": "test:1: 'alert-name' instance '2' has recovered",
670670
},
671671
],
672672
Array [

x-pack/plugins/alerts/server/task_runner/task_runner.ts

+17-15
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import { IEvent, IEventLogger, SAVED_OBJECT_REL_PRIMARY } from '../../../event_l
3939
import { isAlertSavedObjectNotFoundError } from '../lib/is_alert_not_found_error';
4040
import { AlertsClient } from '../alerts_client';
4141
import { partiallyUpdateAlert } from '../saved_objects';
42-
import { ResolvedActionGroup } from '../../common';
42+
import { RecoveredActionGroup } from '../../common';
4343

4444
const FALLBACK_RETRY_INTERVAL = '5m';
4545

@@ -219,7 +219,7 @@ export class TaskRunner {
219219
alertInstance.hasScheduledActions()
220220
);
221221

222-
generateNewAndResolvedInstanceEvents({
222+
generateNewAndRecoveredInstanceEvents({
223223
eventLogger,
224224
originalAlertInstances,
225225
currentAlertInstances: instancesWithScheduledActions,
@@ -229,7 +229,7 @@ export class TaskRunner {
229229
});
230230

231231
if (!muteAll) {
232-
scheduleActionsForResolvedInstances(
232+
scheduleActionsForRecoveredInstances(
233233
alertInstances,
234234
executionHandler,
235235
originalAlertInstances,
@@ -436,7 +436,7 @@ export class TaskRunner {
436436
}
437437
}
438438

439-
interface GenerateNewAndResolvedInstanceEventsParams {
439+
interface GenerateNewAndRecoveredInstanceEventsParams {
440440
eventLogger: IEventLogger;
441441
originalAlertInstances: Dictionary<AlertInstance>;
442442
currentAlertInstances: Dictionary<AlertInstance>;
@@ -445,18 +445,20 @@ interface GenerateNewAndResolvedInstanceEventsParams {
445445
namespace: string | undefined;
446446
}
447447

448-
function generateNewAndResolvedInstanceEvents(params: GenerateNewAndResolvedInstanceEventsParams) {
448+
function generateNewAndRecoveredInstanceEvents(
449+
params: GenerateNewAndRecoveredInstanceEventsParams
450+
) {
449451
const { eventLogger, alertId, namespace, currentAlertInstances, originalAlertInstances } = params;
450452
const originalAlertInstanceIds = Object.keys(originalAlertInstances);
451453
const currentAlertInstanceIds = Object.keys(currentAlertInstances);
452454

453455
const newIds = without(currentAlertInstanceIds, ...originalAlertInstanceIds);
454-
const resolvedIds = without(originalAlertInstanceIds, ...currentAlertInstanceIds);
456+
const recoveredIds = without(originalAlertInstanceIds, ...currentAlertInstanceIds);
455457

456-
for (const id of resolvedIds) {
458+
for (const id of recoveredIds) {
457459
const actionGroup = originalAlertInstances[id].getLastScheduledActions()?.group;
458-
const message = `${params.alertLabel} resolved instance: '${id}'`;
459-
logInstanceEvent(id, EVENT_LOG_ACTIONS.resolvedInstance, message, actionGroup);
460+
const message = `${params.alertLabel} instance '${id}' has recovered`;
461+
logInstanceEvent(id, EVENT_LOG_ACTIONS.recoveredInstance, message, actionGroup);
460462
}
461463

462464
for (const id of newIds) {
@@ -496,7 +498,7 @@ function generateNewAndResolvedInstanceEvents(params: GenerateNewAndResolvedInst
496498
}
497499
}
498500

499-
function scheduleActionsForResolvedInstances(
501+
function scheduleActionsForRecoveredInstances(
500502
alertInstancesMap: Record<string, AlertInstance>,
501503
executionHandler: ReturnType<typeof createExecutionHandler>,
502504
originalAlertInstances: Record<string, AlertInstance>,
@@ -505,22 +507,22 @@ function scheduleActionsForResolvedInstances(
505507
) {
506508
const currentAlertInstanceIds = Object.keys(currentAlertInstances);
507509
const originalAlertInstanceIds = Object.keys(originalAlertInstances);
508-
const resolvedIds = without(
510+
const recoveredIds = without(
509511
originalAlertInstanceIds,
510512
...currentAlertInstanceIds,
511513
...mutedInstanceIds
512514
);
513-
for (const id of resolvedIds) {
515+
for (const id of recoveredIds) {
514516
const instance = alertInstancesMap[id];
515-
instance.updateLastScheduledActions(ResolvedActionGroup.id);
517+
instance.updateLastScheduledActions(RecoveredActionGroup.id);
516518
instance.unscheduleActions();
517519
executionHandler({
518-
actionGroup: ResolvedActionGroup.id,
520+
actionGroup: RecoveredActionGroup.id,
519521
context: {},
520522
state: {},
521523
alertInstanceId: id,
522524
});
523-
instance.scheduleActions(ResolvedActionGroup.id);
525+
instance.scheduleActions(RecoveredActionGroup.id);
524526
}
525527
}
526528

x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import moment from 'moment';
99
import { getCustomMetricLabel } from '../../../../common/formatters/get_custom_metric_label';
1010
import { toMetricOpt } from '../../../../common/snapshot_metric_i18n';
1111
import { AlertStates, InventoryMetricConditions } from './types';
12-
import { ResolvedActionGroup } from '../../../../../alerts/common';
12+
import { RecoveredActionGroup } from '../../../../../alerts/common';
1313
import { AlertExecutorOptions } from '../../../../../alerts/server';
1414
import { InventoryItemType, SnapshotMetricType } from '../../../../common/inventory_models/types';
1515
import { InfraBackendLibs } from '../../infra_types';
@@ -103,7 +103,7 @@ export const createInventoryMetricThresholdExecutor = (libs: InfraBackendLibs) =
103103
}
104104
if (reason) {
105105
const actionGroupId =
106-
nextState === AlertStates.OK ? ResolvedActionGroup.id : FIRED_ACTIONS.id;
106+
nextState === AlertStates.OK ? RecoveredActionGroup.id : FIRED_ACTIONS.id;
107107
alertInstance.scheduleActions(actionGroupId, {
108108
group: item,
109109
alertState: stateToAlertMessage[nextState],

0 commit comments

Comments
 (0)