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] Refactor MatrixHistogram to use Search Strategy #76603

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
60bb91d
add search strategy of uncommon processes
angorayc Aug 27, 2020
5c0ce3e
fixup
angorayc Sep 2, 2020
8549295
fix host.name
angorayc Sep 2, 2020
cc35b35
[Security Solution] Refactor MatrixHistogram to use Search Strategy
patrykkopycinski Sep 3, 2020
1bbaef8
fix i18n
patrykkopycinski Sep 3, 2020
e620159
Merge branch 'master' of github.com:elastic/kibana into searchStrateg…
angorayc Sep 3, 2020
99c29c8
remove comment
angorayc Sep 3, 2020
2cacfe4
Merge remote-tracking branch 'upstream/master' into searchStrategy-un…
angorayc Sep 3, 2020
ffc3361
review
angorayc Sep 3, 2020
d73ffc8
Merge branch 'master' of github.com:elastic/kibana into searchStrateg…
angorayc Sep 3, 2020
5d2f638
Merge branch 'master' of github.com:elastic/kibana into feat/matrix-h…
patrykkopycinski Sep 4, 2020
6f248e9
revert path for libs
angorayc Sep 4, 2020
bb73c1f
fix path
angorayc Sep 4, 2020
a5029ff
revert
angorayc Sep 4, 2020
831453f
remove additional lines
angorayc Sep 4, 2020
9fc1981
remove comment
angorayc Sep 4, 2020
4457d19
Merge branch 'searchStrategy-uncommonprocesses' of github.com:angoray…
patrykkopycinski Sep 4, 2020
fdb2909
Fix query
patrykkopycinski Sep 4, 2020
5d99c6c
Merge branch 'master' into feat/matrix-histogram-search-strategy
elasticmachine Sep 4, 2020
d547493
Merge branch 'master' into feat/matrix-histogram-search-strategy
patrykkopycinski Sep 4, 2020
9f32421
Update index.ts
patrykkopycinski Sep 7, 2020
3145116
Merge branch 'master' into feat/matrix-histogram-search-strategy
elasticmachine Sep 7, 2020
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 @@ -4,11 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

export * from './authentications';
export * from './all';
export * from './authentications';
patrykkopycinski marked this conversation as resolved.
Show resolved Hide resolved
export * from './common';
export * from './overview';
export * from './first_last_seen';
export * from './overview';
export * from './uncommon_processes';

export enum HostsQueries {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import {
NetworkTopNFlowStrategyResponse,
NetworkTopNFlowRequestOptions,
} from './network';
import {
MatrixHistogramQuery,
MatrixHistogramRequestOptions,
MatrixHistogramStrategyResponse,
} from './matrix_histogram';
import {
DocValueFields,
TimerangeInput,
Expand All @@ -39,9 +44,10 @@ import {
} from '../common';

export * from './hosts';
export * from './matrix_histogram';
export * from './network';

export type FactoryQueryTypes = HostsQueries | NetworkQueries;
export type FactoryQueryTypes = HostsQueries | NetworkQueries | typeof MatrixHistogramQuery;

export interface RequestBasicOptions extends IEsSearchRequest {
timerange: TimerangeInput;
Expand Down Expand Up @@ -81,6 +87,8 @@ export type StrategyResponseType<T extends FactoryQueryTypes> = T extends HostsQ
? NetworkTopCountriesStrategyResponse
: T extends NetworkQueries.topNFlow
? NetworkTopNFlowStrategyResponse
: T extends typeof MatrixHistogramQuery
? MatrixHistogramStrategyResponse
: never;

export type StrategyRequestType<T extends FactoryQueryTypes> = T extends HostsQueries.hosts
Expand All @@ -101,4 +109,6 @@ export type StrategyRequestType<T extends FactoryQueryTypes> = T extends HostsQu
? NetworkTopCountriesRequestOptions
: T extends NetworkQueries.topNFlow
? NetworkTopNFlowRequestOptions
: T extends typeof MatrixHistogramQuery
? MatrixHistogramRequestOptions
: never;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { HistogramBucket } from '../common';

export interface AlertsGroupData {
key: string;
doc_count: number;
alerts: {
buckets: HistogramBucket[];
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { SearchHit } from '../../../common';

interface AnomaliesOverTimeHistogramData {
key_as_string: string;
key: number;
doc_count: number;
}

export interface AnomaliesActionGroupData {
key: number;
anomalies: {
bucket: AnomaliesOverTimeHistogramData[];
};
doc_count: number;
}

export interface AnomalySource {
[field: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
}

export interface AnomalyHit extends SearchHit {
sort: string[];
_source: AnomalySource;
aggregations: {
[agg: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export interface AuthenticationsOverTimeHistogramData {
key_as_string: string;
key: number;
doc_count: number;
}

export interface AuthenticationsActionGroupData {
key: number;
events: {
bucket: AuthenticationsOverTimeHistogramData[];
};
doc_count: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export interface HistogramBucket {
key: number;
doc_count: number;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export interface DnsHistogramSubBucket {
key: string;
doc_count: number;
orderAgg: {
value: number;
};
}
interface DnsHistogramBucket {
doc_count_error_upper_bound: number;
sum_other_doc_count: number;
buckets: DnsHistogramSubBucket[];
}

export interface DnsHistogramGroupData {
key: number;
doc_count: number;
key_as_string: string;
histogram: DnsHistogramBucket;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { SearchHit } from '../../../common';

interface EventsMatrixHistogramData {
key_as_string: string;
key: number;
doc_count: number;
}

export interface EventSource {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[field: string]: any;
}

export interface EventsActionGroupData {
key: number;
events: {
bucket: EventsMatrixHistogramData[];
};
doc_count: number;
}

export interface EventHit extends SearchHit {
sort: string[];
_source: EventSource;
aggregations: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[agg: string]: any;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { IEsSearchResponse } from '../../../../../../../src/plugins/data/common';
import { AuthenticationHit } from '../hosts';
import { Inspect, Maybe, TimerangeInput } from '../../common';
import { RequestBasicOptions } from '../';
import { AlertsGroupData } from './alerts';
import { AnomaliesActionGroupData, AnomalyHit } from './anomalies';
import { DnsHistogramGroupData } from './dns';
import { AuthenticationsActionGroupData } from './authentications';
import { EventsActionGroupData, EventHit } from './events';

export * from './alerts';
export * from './anomalies';
export * from './authentications';
export * from './common';
export * from './dns';
export * from './events';

export const MatrixHistogramQuery = 'matrixHistogram';

export enum MatrixHistogramType {
authentications = 'authentications',
anomalies = 'anomalies',
events = 'events',
alerts = 'alerts',
dns = 'dns',
}

export interface MatrixHistogramRequestOptions extends RequestBasicOptions {
timerange: TimerangeInput;
histogramType: MatrixHistogramType;
stackByField: string;
inspect?: Maybe<Inspect>;
}

export interface MatrixHistogramStrategyResponse extends IEsSearchResponse {
inspect?: Maybe<Inspect>;
matrixHistogramData: MatrixHistogramData[];
totalCount: number;
}

export interface MatrixHistogramData {
x?: Maybe<number>;
y?: Maybe<number>;
g?: Maybe<string>;
}

export interface MatrixHistogramBucket {
key: number;
doc_count: number;
}

export interface MatrixHistogramSchema<T> {
buildDsl: (options: MatrixHistogramRequestOptions) => {};
aggName: string;
parseKey: string;
parser?: <T>(data: MatrixHistogramParseData<T>, keyBucket: string) => MatrixHistogramData[];
}

export type MatrixHistogramParseData<T> = T extends MatrixHistogramType.alerts
? AlertsGroupData[]
: T extends MatrixHistogramType.anomalies
? AnomaliesActionGroupData[]
: T extends MatrixHistogramType.dns
? DnsHistogramGroupData[]
: T extends MatrixHistogramType.authentications
? AuthenticationsActionGroupData[]
: T extends MatrixHistogramType.events
? EventsActionGroupData[]
: never;

export type MatrixHistogramHit<T> = T extends MatrixHistogramType.alerts
? EventHit
: T extends MatrixHistogramType.anomalies
? AnomalyHit
: T extends MatrixHistogramType.dns
? EventHit
: T extends MatrixHistogramType.authentications
? AuthenticationHit
: T extends MatrixHistogramType.events
? EventHit
: never;

export type MatrixHistogramDataConfig = Record<
MatrixHistogramType,
MatrixHistogramSchema<MatrixHistogramType>
>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import * as i18n from './translations';
import { MatrixHistogramOption, MatrixHistogramConfigs } from '../matrix_histogram/types';
import { HistogramType } from '../../../graphql/types';
import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution/matrix_histogram';

export const alertsStackByOptions: MatrixHistogramOption[] = [
{
Expand All @@ -25,7 +25,7 @@ export const histogramConfigs: MatrixHistogramConfigs = {
defaultStackByOption:
alertsStackByOptions.find((o) => o.text === DEFAULT_STACK_BY) ?? alertsStackByOptions[1],
errorMessage: i18n.ERROR_FETCHING_ALERTS_DATA,
histogramType: HistogramType.alerts,
histogramType: MatrixHistogramType.alerts,
stackByOptions: alertsStackByOptions,
subtitle: undefined,
title: i18n.ALERTS_GRAPH_TITLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,40 @@ import { AlertsComponentsProps } from './types';
import { AlertsTable } from './alerts_table';
import * as i18n from './translations';
import { useUiSetting$ } from '../../lib/kibana';
import { MatrixHistogramContainer } from '../matrix_histogram';
import { MatrixHistogram } from '../matrix_histogram';
import { histogramConfigs } from './histogram_configs';
import { MatrixHistogramConfigs } from '../matrix_histogram/types';
const ID = 'alertsOverTimeQuery';

export const AlertsView = ({
const ID = 'alertsHistogramQuery';

const AlertsViewComponent: React.FC<AlertsComponentsProps> = ({
timelineId,
deleteQuery,
endDate,
filterQuery,
pageFilters,
setQuery,
startDate,
type,
}: AlertsComponentsProps) => {
}) => {
const [defaultNumberFormat] = useUiSetting$<string>(DEFAULT_NUMBER_FORMAT);
const { globalFullScreen } = useFullScreen();

const getSubtitle = useCallback(
(totalCount: number) =>
`${i18n.SHOWING}: ${numeral(totalCount).format(defaultNumberFormat)} ${i18n.UNIT(
totalCount
)}`,
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
[defaultNumberFormat]
);
const { globalFullScreen } = useFullScreen();

const alertsHistogramConfigs: MatrixHistogramConfigs = useMemo(
() => ({
...histogramConfigs,
subtitle: getSubtitle,
}),
[getSubtitle]
);

useEffect(() => {
return () => {
if (deleteQuery) {
Expand All @@ -56,14 +58,12 @@ export const AlertsView = ({
return (
<>
{!globalFullScreen && (
<MatrixHistogramContainer
<MatrixHistogram
endDate={endDate}
filterQuery={filterQuery}
id={ID}
setQuery={setQuery}
sourceId="default"
startDate={startDate}
type={type}
{...alertsHistogramConfigs}
/>
)}
Expand All @@ -76,4 +76,7 @@ export const AlertsView = ({
</>
);
};
AlertsView.displayName = 'AlertsView';

AlertsViewComponent.displayName = 'AlertsViewComponent';

export const AlertsView = React.memo(AlertsViewComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type CommonQueryProps = HostsComponentsQueryProps | NetworkComponentQueryProps;
export interface AlertsComponentsProps
extends Pick<
CommonQueryProps,
'deleteQuery' | 'endDate' | 'filterQuery' | 'skip' | 'setQuery' | 'startDate' | 'type'
'deleteQuery' | 'endDate' | 'filterQuery' | 'skip' | 'setQuery' | 'startDate'
> {
timelineId: TimelineIdLiteral;
pageFilters: Filter[];
Expand Down
Loading