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

Add searchDuration to EQL and Threshold rules #93149

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Changes from all 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
Expand Up @@ -12,6 +12,7 @@ import isEmpty from 'lodash/isEmpty';
import { chain, tryCatch } from 'fp-ts/lib/TaskEither';
import { flow } from 'fp-ts/lib/function';

import { performance } from 'perf_hooks';
import { toError, toPromise } from '../../../../common/fp_utils';

import {
Expand Down Expand Up @@ -50,6 +51,7 @@ import {
hasTimestampFields,
hasReadIndexPrivileges,
getRuleRangeTuples,
makeFloatString,
} from './utils';
import { signalParamsSchema } from './signal_params_schema';
import { siemRuleActionGroups } from './siem_rule_action_groups';
Expand Down Expand Up @@ -401,7 +403,11 @@ export const signalRulesAlertType = ({
lists: exceptionItems ?? [],
});

const { searchResult: thresholdResults, searchErrors } = await findThresholdSignals({
const {
searchResult: thresholdResults,
searchErrors,
searchDuration: thresholdSearchDuration,
} = await findThresholdSignals({
inputIndexPattern: inputIndex,
from,
to,
Expand Down Expand Up @@ -456,6 +462,7 @@ export const signalRulesAlertType = ({
createdSignalsCount: createdItemsCount,
createdSignals: createdItems,
bulkCreateTimes: bulkCreateDuration ? [bulkCreateDuration] : [],
searchAfterTimes: [thresholdSearchDuration],
}),
]);
} else if (isThreatMatchRule(type)) {
Expand Down Expand Up @@ -589,10 +596,14 @@ export const signalRulesAlertType = ({
exceptionItems ?? [],
eventCategoryOverride
);
const eqlSignalSearchStart = performance.now();
const response: EqlSignalSearchResponse = await services.callCluster(
'transport.request',
request
);
const eqlSignalSearchEnd = performance.now();
const eqlSearchDuration = makeFloatString(eqlSignalSearchEnd - eqlSignalSearchStart);
result.searchAfterTimes = [eqlSearchDuration];
let newSignals: WrappedSignalHit[] | undefined;
if (response.hits.sequences !== undefined) {
newSignals = response.hits.sequences.reduce(
Expand Down Expand Up @@ -633,7 +644,6 @@ export const signalRulesAlertType = ({

const fromInMs = parseScheduleDates(`now-${interval}`)?.format('x');
const toInMs = parseScheduleDates('now')?.format('x');

const resultsLink = getNotificationResultsLink({
from: fromInMs,
to: toInMs,
Expand Down