Skip to content

Commit ffc649a

Browse files
committed
Add searchDuration to EQL and Threshold rules (#93149)
Closes #82861.
1 parent 9fd352b commit ffc649a

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Logger, KibanaRequest } from 'src/core/server';
1111
import isEmpty from 'lodash/isEmpty';
1212
import { chain, tryCatch } from 'fp-ts/lib/TaskEither';
1313
import { flow } from 'fp-ts/lib/function';
14+
import { performance } from 'perf_hooks';
1415

1516
import { toError, toPromise } from '../../../../common/fp_utils';
1617

@@ -52,6 +53,7 @@ import {
5253
checkPrivileges,
5354
hasTimestampFields,
5455
hasReadIndexPrivileges,
56+
makeFloatString,
5557
} from './utils';
5658
import { signalParamsSchema } from './signal_params_schema';
5759
import { siemRuleActionGroups } from './siem_rule_action_groups';
@@ -409,7 +411,11 @@ export const signalRulesAlertType = ({
409411
lists: exceptionItems ?? [],
410412
});
411413

412-
const { searchResult: thresholdResults, searchErrors } = await findThresholdSignals({
414+
const {
415+
searchResult: thresholdResults,
416+
searchErrors,
417+
searchDuration: thresholdSearchDuration,
418+
} = await findThresholdSignals({
413419
inputIndexPattern: inputIndex,
414420
from,
415421
to,
@@ -464,6 +470,7 @@ export const signalRulesAlertType = ({
464470
createdSignalsCount: createdItemsCount,
465471
createdSignals: createdItems,
466472
bulkCreateTimes: bulkCreateDuration ? [bulkCreateDuration] : [],
473+
searchAfterTimes: [thresholdSearchDuration],
467474
}),
468475
]);
469476
} else if (isThreatMatchRule(type)) {
@@ -599,10 +606,14 @@ export const signalRulesAlertType = ({
599606
exceptionItems ?? [],
600607
eventCategoryOverride
601608
);
609+
const eqlSignalSearchStart = performance.now();
602610
const response: EqlSignalSearchResponse = await services.callCluster(
603611
'transport.request',
604612
request
605613
);
614+
const eqlSignalSearchEnd = performance.now();
615+
const eqlSearchDuration = makeFloatString(eqlSignalSearchEnd - eqlSignalSearchStart);
616+
result.searchAfterTimes = [eqlSearchDuration];
606617
let newSignals: WrappedSignalHit[] | undefined;
607618
if (response.hits.sequences !== undefined) {
608619
newSignals = response.hits.sequences.reduce(
@@ -643,7 +654,6 @@ export const signalRulesAlertType = ({
643654

644655
const fromInMs = parseScheduleDates(`now-${interval}`)?.format('x');
645656
const toInMs = parseScheduleDates('now')?.format('x');
646-
647657
const resultsLink = getNotificationResultsLink({
648658
from: fromInMs,
649659
to: toInMs,

0 commit comments

Comments
 (0)