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

[Security Solution][Alerts] Remove dead legacy signals code #128328

Merged
merged 5 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -0,0 +1,22 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { alertsMock } from '../../../alerting/server/mocks';
import { PersistenceServices } from './persistence_types';

export const createPersistenceServicesMock = (): jest.Mocked<PersistenceServices> => {
return {
alertWithPersistence: jest.fn(),
};
};

export const createPersistenceExecutorOptionsMock = () => {
return {
...alertsMock.createAlertServices(),
...createPersistenceServicesMock(),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { isEmpty } from 'lodash';

import { parseScheduleDates } from '@kbn/securitysolution-io-ts-utils';
import { ListArray } from '@kbn/securitysolution-io-ts-list-types';
import agent from 'elastic-apm-node';

import { createPersistenceRuleTypeWrapper } from '../../../../../rule_registry/server';
Expand All @@ -19,11 +18,7 @@ import {
getRuleRangeTuples,
hasReadIndexPrivileges,
hasTimestampFields,
isEqlParams,
isQueryParams,
isSavedQueryParams,
isThreatParams,
isThresholdParams,
isMachineLearningParams,
} from '../signals/utils';
import { DEFAULT_MAX_SIGNALS, DEFAULT_SEARCH_AFTER_PAGE_SIZE } from '../../../../common/constants';
import { CreateSecurityRuleTypeWrapper } from './types';
Expand Down Expand Up @@ -132,22 +127,13 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =
...params,
name,
id: alertId,
} as unknown as NotificationRuleTypeParams;
};

// check if rule has permissions to access given index pattern
// move this collection of lines into a function in utils
// so that we can use it in create rules route, bulk, etc.
try {
// Typescript 4.1.3 can't figure out that `!isMachineLearningParams(params)` also excludes the only rule type
// of rule params that doesn't include `params.index`, but Typescript 4.3.5 does compute the stricter type correctly.
// When we update Typescript to >= 4.3.5, we can replace this logic with `!isMachineLearningParams(params)` again.
if (
isEqlParams(params) ||
isThresholdParams(params) ||
isQueryParams(params) ||
isSavedQueryParams(params) ||
isThreatParams(params)
) {
if (!isMachineLearningParams(params)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const index = params.index;
const hasTimestampOverride = !!timestampOverride;

Expand All @@ -169,17 +155,15 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =
{
index,
fields: hasTimestampOverride
? ['@timestamp', timestampOverride as string]
? ['@timestamp', timestampOverride]
: ['@timestamp'],
include_unmapped: true,
},
{ meta: true }
)
);
wroteWarningStatus = await hasTimestampFields({
timestampField: hasTimestampOverride
? (timestampOverride as string)
: '@timestamp',
timestampField: hasTimestampOverride ? timestampOverride : '@timestamp',
timestampFieldCapsResponse: timestampFieldCaps,
inputIndices,
ruleExecutionLogger,
Expand All @@ -201,8 +185,8 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =
const { tuples, remainingGap } = getRuleRangeTuples({
logger,
previousStartedAt,
from: from as string,
to: to as string,
from,
to,
interval,
maxSignals: maxSignals ?? DEFAULT_MAX_SIGNALS,
buildRuleMessage,
Expand Down Expand Up @@ -235,7 +219,7 @@ export const createSecurityRuleTypeWrapper: CreateSecurityRuleTypeWrapper =

const exceptionItems = await getExceptions({
client: exceptionsClient,
lists: (params.exceptionsList as ListArray) ?? [],
lists: params.exceptionsList,
});

const bulkCreate = bulkCreateFactory(
Expand Down
Loading