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

[SIEM] [Detection Engine] Fixes histogram intervals #55969

Merged
merged 3 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -73,6 +73,7 @@ const MyEuiFlexGroup = styled(EuiFlexGroup)`

interface SearchTimelineSuperSelectProps {
isDisabled: boolean;
hideUntitled?: boolean;
timelineId: string | null;
timelineTitle: string | null;
onTimelineChange: (timelineTitle: string, timelineId: string | null) => void;
Expand Down Expand Up @@ -101,6 +102,7 @@ const POPOVER_HEIGHT = 260;
const TIMELINE_ITEM_HEIGHT = 50;
const SearchTimelineSuperSelectComponent: React.FC<SearchTimelineSuperSelectProps> = ({
isDisabled,
hideUntitled = false,
timelineId,
timelineTitle,
onTimelineChange,
Expand Down Expand Up @@ -287,7 +289,11 @@ const SearchTimelineSuperSelectComponent: React.FC<SearchTimelineSuperSelectProp
rowHeight: TIMELINE_ITEM_HEIGHT,
showIcons: false,
virtualizedProps: ({
onScroll: handleOnScroll.bind(null, timelines.length, totalCount),
onScroll: handleOnScroll.bind(
null,
timelines.filter(t => !hideUntitled || t.title !== '').length,
totalCount
),
} as unknown) as ListProps,
}}
renderOption={renderTimelineOption}
Expand All @@ -308,18 +314,20 @@ const SearchTimelineSuperSelectComponent: React.FC<SearchTimelineSuperSelectProp
...(!onlyFavorites && searchTimelineValue === ''
? getBasicSelectableOptions(timelineId == null ? '-1' : timelineId)
: []),
...timelines.map(
(t, index) =>
({
description: t.description,
favorite: t.favorite,
label: t.title,
id: t.savedObjectId,
key: `${t.title}-${index}`,
title: t.title,
checked: t.savedObjectId === timelineId ? 'on' : undefined,
} as Option)
),
...timelines
.filter(t => !hideUntitled || t.title !== '')
.map(
(t, index) =>
({
description: t.description,
favorite: t.favorite,
label: t.title,
id: t.savedObjectId,
key: `${t.title}-${index}`,
title: t.title,
checked: t.savedObjectId === timelineId ? 'on' : undefined,
} as Option)
),
]}
>
{(list, search) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,14 @@ export const getSignalsHistogramQuery = (
},
aggs: {
signals: {
auto_date_histogram: {
date_histogram: {
field: '@timestamp',
buckets: 36,
fixed_interval: `${Math.floor((to - from) / 32)}ms`,
min_doc_count: 0,
extended_bounds: {
min: from,
max: to,
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const PickTimeline = ({
>
<SearchTimelineSuperSelect
isDisabled={isDisabled}
hideUntitled={true}
timelineId={timelineId}
timelineTitle={timelineTitle}
onTimelineChange={handleOnTimelineChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const NAVIGATION_EVENTS_TITLE = i18n.translate('xpack.siem.hosts.navigati
});

export const NAVIGATION_ALERTS_TITLE = i18n.translate('xpack.siem.hosts.navigation.alertsTitle', {
defaultMessage: 'Alerts',
defaultMessage: 'External alerts',
});

export const ERROR_FETCHING_AUTHENTICATIONS_DATA = i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const NAVIGATION_ANOMALIES_TITLE = i18n.translate(
);

export const NAVIGATION_ALERTS_TITLE = i18n.translate('xpack.siem.network.navigation.alertsTitle', {
defaultMessage: 'Alerts',
defaultMessage: 'External alerts',
});

export const DOMAINS_COUNT_BY = (groupByField: string) =>
Expand Down
19 changes: 9 additions & 10 deletions x-pack/legacy/plugins/siem/server/lib/alerts/query.dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { createQueryFilterClauses, calculateTimeseriesInterval } from '../../utils/build_query';
import { createQueryFilterClauses, calculateTimeSeriesInterval } from '../../utils/build_query';
import { buildTimelineQuery } from '../events/query.dsl';
import { RequestOptions, MatrixHistogramRequestOptions } from '../framework';

Expand Down Expand Up @@ -68,18 +68,17 @@ export const buildAlertsHistogramQuery = ({
];

const getHistogramAggregation = () => {
const interval = calculateTimeseriesInterval(from, to);
const interval = calculateTimeSeriesInterval(from, to);
const histogramTimestampField = '@timestamp';
const dateHistogram = {
date_histogram: {
field: histogramTimestampField,
fixed_interval: `${interval}s`,
},
};
const autoDateHistogram = {
auto_date_histogram: {
field: histogramTimestampField,
buckets: 36,
fixed_interval: interval,
min_doc_count: 0,
extended_bounds: {
min: from,
max: to,
},
},
};
return {
Expand All @@ -93,7 +92,7 @@ export const buildAlertsHistogramQuery = ({
size: 10,
},
aggs: {
alerts: interval ? dateHistogram : autoDateHistogram,
alerts: dateHistogram,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { createQueryFilterClauses, calculateTimeseriesInterval } from '../../utils/build_query';
import { createQueryFilterClauses, calculateTimeSeriesInterval } from '../../utils/build_query';
import { MatrixHistogramRequestOptions } from '../framework';

export const buildAnomaliesOverTimeQuery = ({
Expand All @@ -26,18 +26,17 @@ export const buildAnomaliesOverTimeQuery = ({
];

const getHistogramAggregation = () => {
const interval = calculateTimeseriesInterval(from, to);
const interval = calculateTimeSeriesInterval(from, to);
const histogramTimestampField = 'timestamp';
const dateHistogram = {
date_histogram: {
field: histogramTimestampField,
fixed_interval: `${interval}s`,
},
};
const autoDateHistogram = {
auto_date_histogram: {
field: histogramTimestampField,
buckets: 36,
fixed_interval: interval,
min_doc_count: 0,
extended_bounds: {
min: from,
max: to,
},
},
};
return {
Expand All @@ -50,7 +49,7 @@ export const buildAnomaliesOverTimeQuery = ({
size: 10,
},
aggs: {
anomalies: interval ? dateHistogram : autoDateHistogram,
anomalies: dateHistogram,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { createQueryFilterClauses, calculateTimeseriesInterval } from '../../utils/build_query';
import { createQueryFilterClauses, calculateTimeSeriesInterval } from '../../utils/build_query';
import { MatrixHistogramRequestOptions } from '../framework';

export const buildAuthenticationsOverTimeQuery = ({
Expand All @@ -28,18 +28,17 @@ export const buildAuthenticationsOverTimeQuery = ({
];

const getHistogramAggregation = () => {
const interval = calculateTimeseriesInterval(from, to);
const interval = calculateTimeSeriesInterval(from, to);
const histogramTimestampField = '@timestamp';
const dateHistogram = {
date_histogram: {
field: histogramTimestampField,
fixed_interval: `${interval}s`,
},
};
const autoDateHistogram = {
auto_date_histogram: {
field: histogramTimestampField,
buckets: 36,
fixed_interval: interval,
min_doc_count: 0,
extended_bounds: {
min: from,
max: to,
},
},
};
return {
Expand All @@ -53,7 +52,7 @@ export const buildAuthenticationsOverTimeQuery = ({
size: 2,
},
aggs: {
events: interval ? dateHistogram : autoDateHistogram,
events: dateHistogram,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { createQueryFilterClauses, calculateTimeseriesInterval } from '../../utils/build_query';
import { createQueryFilterClauses, calculateTimeSeriesInterval } from '../../utils/build_query';
import { MatrixHistogramRequestOptions } from '../framework';

export const buildEventsOverTimeQuery = ({
Expand All @@ -28,18 +28,17 @@ export const buildEventsOverTimeQuery = ({
];

const getHistogramAggregation = () => {
const interval = calculateTimeseriesInterval(from, to);
const interval = calculateTimeSeriesInterval(from, to);
const histogramTimestampField = '@timestamp';
const dateHistogram = {
date_histogram: {
field: histogramTimestampField,
fixed_interval: `${interval}s`,
},
};
const autoDateHistogram = {
auto_date_histogram: {
field: histogramTimestampField,
buckets: 36,
fixed_interval: interval,
min_doc_count: 0,
extended_bounds: {
min: from,
max: to,
},
},
};
return {
Expand All @@ -53,7 +52,7 @@ export const buildEventsOverTimeQuery = ({
size: 10,
},
aggs: {
events: interval ? dateHistogram : autoDateHistogram,
events: dateHistogram,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { createQueryFilterClauses, calculateTimeseriesInterval } from '../../utils/build_query';
import { createQueryFilterClauses, calculateTimeSeriesInterval } from '../../utils/build_query';
import { MatrixHistogramRequestOptions } from '../framework';

export const buildDnsHistogramQuery = ({
Expand All @@ -29,12 +29,12 @@ export const buildDnsHistogramQuery = ({
];

const getHistogramAggregation = () => {
const interval = calculateTimeseriesInterval(from, to);
const interval = calculateTimeSeriesInterval(from, to);
const histogramTimestampField = '@timestamp';
const dateHistogram = {
date_histogram: {
field: histogramTimestampField,
fixed_interval: `${interval}s`,
fixed_interval: interval,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ export const calculateAuto = {
}),
};

export const calculateTimeseriesInterval = (
lowerBoundInMsSinceEpoch: number,
upperBoundInMsSinceEpoch: number
) => {
const duration = moment.duration(upperBoundInMsSinceEpoch - lowerBoundInMsSinceEpoch, 'ms');

const matchedInterval = calculateAuto.near(50, duration);

return matchedInterval ? Math.max(matchedInterval.asSeconds(), 1) : null;
export const calculateTimeSeriesInterval = (from: number, to: number) => {
return `${Math.floor((to - from) / 32)}ms`;
};