Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Jan 23, 2023
1 parent 2b45a7d commit 9958376
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 113 deletions.
51 changes: 4 additions & 47 deletions x-pack/plugins/alerting/server/task_runner/task_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,55 +373,12 @@ export class TaskRunner<
updatedAt,
throttle,
notifyWhen,
muteAll,
snoozeSchedule,
},
logger: this.logger,
canSetRecoveryContext: ruleType.doesSetRecoveryContext ?? false,
}),
shouldWriteAlerts: () => this.shouldLogAndScheduleActionsForAlerts(),
shouldStopExecution: () => this.cancelled,
},
params,
state: ruleTypeState as RuleState,
startedAt: this.taskInstance.startedAt!,
previousStartedAt: previousStartedAt ? new Date(previousStartedAt) : null,
spaceId,
namespace,
name,
tags,
createdBy,
updatedBy,
rule: {
name,
tags,
consumer,
producer: ruleType.producer,
ruleTypeId: rule.alertTypeId,
ruleTypeName: ruleType.name,
enabled,
schedule,
actions,
createdBy,
updatedBy,
createdAt,
updatedAt,
throttle,
notifyWhen,
muteAll,
snoozeSchedule,
},
})
);
} catch (err) {
this.alertingEventLogger.setExecutionFailed(
`rule execution failure: ${ruleLabel}`,
err.message
);
this.logger.error(err, {
tags: [this.ruleType.id, ruleId, 'rule-run-failed'],
error: { stack_trace: err.stack },
});
throw new ErrorWithReason(RuleExecutionStatusErrorReasons.Execute, err);
}
})
);

// Rule type execution has successfully completed
// Check that the rule type either never requested the max alerts limit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ const mockOptions = {
producer: '',
ruleTypeId: '',
ruleTypeName: '',
muteAll: false,
snoozeSchedule: [],
},
logger,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function createRule(shouldWriteAlerts: boolean = true) {
createdAt,
createdBy: 'createdBy',
enabled: true,
muteAll: false,
name: 'name',
notifyWhen: 'onActionGroupChange',
producer: 'producer',
Expand All @@ -118,6 +119,7 @@ function createRule(shouldWriteAlerts: boolean = true) {
schedule: {
interval: '1m',
},
snoozeSchedule: [],
tags: ['tags'],
throttle: null,
updatedAt: createdAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export const createDefaultAlertExecutorOptions = <
notifyWhen: null,
ruleTypeId: 'RULE_TYPE_ID',
ruleTypeName: 'RULE_TYPE_NAME',
muteAll: false,
snoozeSchedule: [],
},
params,
spaceId: 'SPACE_ID',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { TIMESTAMP } from '@kbn/rule-data-utils';
import { createPersistenceRuleTypeWrapper } from '@kbn/rule-registry-plugin/server';
import { parseScheduleDates } from '@kbn/securitysolution-io-ts-utils';

import { buildExceptionFilter } from '@kbn/lists-plugin/server/services/exception_lists';
import { isRuleSnoozed } from '@kbn/alerting-plugin/server';

import {
checkPrivilegesFromEsClient,
getExceptions,
Expand Down Expand Up @@ -387,7 +388,7 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =

const createdSignalsCount = result.createdSignals.length;

if (actions.length) {
if (actions.length && !isRuleSnoozed(options.rule)) {
const fromInMs = parseScheduleDates(`now-${interval}`)?.format('x');
const toInMs = parseScheduleDates('now')?.format('x');
const resultsLink = getNotificationResultsLink({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ async function invokeExecutor({
updatedAt: new Date(),
throttle: null,
notifyWhen: null,
muteAll: false,
snoozeSchedule: [],
},
logger,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ describe('ruleType', () => {
updatedAt: new Date(),
throttle: null,
notifyWhen: null,
muteAll: false,
snoozeSchedule: [],
},
logger,
});
Expand Down Expand Up @@ -278,6 +280,8 @@ describe('ruleType', () => {
updatedAt: new Date(),
throttle: null,
notifyWhen: null,
muteAll: false,
snoozeSchedule: [],
},
logger,
});
Expand Down Expand Up @@ -341,6 +345,8 @@ describe('ruleType', () => {
updatedAt: new Date(),
throttle: null,
notifyWhen: null,
muteAll: false,
snoozeSchedule: [],
},
logger,
});
Expand Down Expand Up @@ -403,6 +409,8 @@ describe('ruleType', () => {
updatedAt: new Date(),
throttle: null,
notifyWhen: null,
muteAll: false,
snoozeSchedule: [],
},
logger,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
SNOOZE_FAILED_MESSAGE,
SNOOZE_SUCCESS_MESSAGE,
UNSNOOZE_SUCCESS_MESSAGE,
} from './rules_list_notify_badge';
} from './notify_badge';
import { SnoozePanel, futureTimeToInterval } from './rule_snooze';
import { Rule, RuleTypeParams, SnoozeSchedule } from '../../../../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ import { hasAllPrivilege } from '../../../lib/capabilities';
import { RuleTagBadge } from './rule_tag_badge';
import { RuleStatusDropdown } from './rule_status_dropdown';
import { RulesListNotifyBadge } from './notify_badge';
import {
RulesListColumns,
RulesListVisibleColumns,
useRulesListColumnSelector,
} from './rules_list_column_selector';
import { RulesListTableStatusCell } from './rules_list_table_status_cell';
import { getIsExperimentalFeatureEnabled } from '../../../../common/get_experimental_features';
import { RulesListColumns, useRulesListColumnSelector } from './rules_list_column_selector';

interface RuleTypeState {
isLoading: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,38 @@ export default function alertTests({ getService }: FtrProviderContext) {
let alertUtils: AlertUtils;
let indexRecordActionId: string;

const getAlertInfo = (alertId: string, actions: any) => ({
alertId,
consumer: 'alertsFixture',
spaceId: space.id,
namespace: space.id,
name: 'abc',
enabled: true,
notifyWhen: 'onActiveAlert',
schedule: {
interval: '1m',
},
tags: ['tag-A', 'tag-B'],
throttle: '1m',
createdBy: user.fullName,
updatedBy: user.fullName,
actions: actions.map((action: any) => {
/* eslint-disable @typescript-eslint/naming-convention */
const { connector_type_id, group, id, params } = action;
return {
actionTypeId: connector_type_id,
group,
id,
params,
};
}),
producer: 'alertsFixture',
ruleTypeId: 'test.always-firing',
ruleTypeName: 'Test: Always Firing',
muteAll: false,
snoozeSchedule: [],
});

before(async () => {
const { body: createdAction } = await supertest
.post(`${getUrlPrefix(space.id)}/api/actions/connector`)
Expand Down Expand Up @@ -145,35 +177,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
index: ES_TEST_INDEX_NAME,
reference,
},
alertInfo: {
id: alertId,
consumer: 'alertsFixture',
spaceId: space.id,
namespace: space.id,
name: 'abc',
enabled: true,
notifyWhen: 'onActiveAlert',
schedule: {
interval: '1m',
},
tags: ['tag-A', 'tag-B'],
throttle: '1m',
createdBy: user.fullName,
updatedBy: user.fullName,
actions: response.body.actions.map((action: any) => {
/* eslint-disable @typescript-eslint/naming-convention */
const { connector_type_id, group, id, params } = action;
return {
actionTypeId: connector_type_id,
group,
id,
params,
};
}),
producer: 'alertsFixture',
ruleTypeId: 'test.always-firing',
ruleTypeName: 'Test: Always Firing',
},
alertInfo: getAlertInfo(alertId, response.body.actions),
});
// @ts-expect-error _source: unknown
expect(alertSearchResult.body.hits.hits[0]._source.alertInfo.createdAt).to.match(
Expand Down Expand Up @@ -297,35 +301,7 @@ instanceStateValue: true
index: ES_TEST_INDEX_NAME,
reference,
},
alertInfo: {
id: alertId,
consumer: 'alertsFixture',
spaceId: space.id,
namespace: space.id,
name: 'abc',
enabled: true,
notifyWhen: 'onActiveAlert',
schedule: {
interval: '1m',
},
tags: ['tag-A', 'tag-B'],
throttle: '1m',
createdBy: user.fullName,
updatedBy: user.fullName,
actions: response.body.actions.map((action: any) => {
/* eslint-disable @typescript-eslint/naming-convention */
const { connector_type_id, group, id, params } = action;
return {
actionTypeId: connector_type_id,
group,
id,
params,
};
}),
producer: 'alertsFixture',
ruleTypeId: 'test.always-firing',
ruleTypeName: 'Test: Always Firing',
},
alertInfo: getAlertInfo(alertId, response.body.actions),
});

// @ts-expect-error _source: unknown
Expand Down Expand Up @@ -457,6 +433,8 @@ instanceStateValue: true
producer: 'alertsFixture',
ruleTypeId: 'test.always-firing',
ruleTypeName: 'Test: Always Firing',
muteAll: false,
snoozeSchedule: [],
});

// @ts-expect-error _source: unknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export function alertTests({ getService }: FtrProviderContext, space: Space) {
producer: 'alertsFixture',
ruleTypeId: 'test.always-firing',
ruleTypeName: 'Test: Always Firing',
muteAll: false,
snoozeSchedule: [],
},
};
if (expected.alertInfo.namespace === undefined) {
Expand Down

0 comments on commit 9958376

Please sign in to comment.