Skip to content
Merged
Show file tree
Hide file tree
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 @@ -16,6 +16,7 @@ import {
ExceptionListItemSchema,
CreateExceptionListItemSchema,
} from '../../../lists/common/schemas';
import { ESBoolQuery } from '../typed_json';
import { buildExceptionListQueries } from './build_exceptions_query';
import {
Query as QueryString,
Expand All @@ -31,7 +32,7 @@ export const getQueryFilter = (
index: Index,
lists: Array<ExceptionListItemSchema | CreateExceptionListItemSchema>,
excludeExceptions: boolean = true
) => {
): ESBoolQuery => {
const indexPattern: IIndexPattern = {
fields: [],
title: index.join(),
Expand Down
19 changes: 18 additions & 1 deletion x-pack/plugins/security_solution/common/typed_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { DslQuery, Filter } from 'src/plugins/data/common';

import { JsonObject } from '../../../../src/plugins/kibana_utils/common';

export type ESQuery = ESRangeQuery | ESQueryStringQuery | ESMatchQuery | ESTermQuery | JsonObject;
export type ESQuery =
| ESRangeQuery
| ESQueryStringQuery
| ESMatchQuery
| ESTermQuery
| ESBoolQuery
| JsonObject;

export interface ESRangeQuery {
range: {
Expand Down Expand Up @@ -37,3 +45,12 @@ export interface ESQueryStringQuery {
export interface ESTermQuery {
term: Record<string, string>;
}

export interface ESBoolQuery {
bool: {
must: DslQuery[];
filter: Filter[];
should: never[];
must_not: Filter[];
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export type MatrixHistogramComponentProps = MatrixHistogramProps &
defaultStackByOption: MatrixHistogramOption;
errorMessage: string;
headerChildren?: React.ReactNode;
footerChildren?: React.ReactNode;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed these changes as I'm no longer using this component.

hideHistogramIfEmpty?: boolean;
histogramType: MatrixHistogramType;
id: string;
Expand All @@ -48,7 +47,6 @@ export type MatrixHistogramComponentProps = MatrixHistogramProps &
subtitle?: string | GetSubTitle;
timelineId?: string;
title: string | GetTitle;
yTitle?: string | undefined;
};

const DEFAULT_PANEL_HEIGHT = 300;
Expand All @@ -70,7 +68,6 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
errorMessage,
filterQuery,
headerChildren,
footerChildren,
histogramType,
hideHistogramIfEmpty = false,
id,
Expand All @@ -89,7 +86,6 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
title,
titleSize,
yTickFormatter,
yTitle,
}) => {
const dispatch = useDispatch();
const handleBrushEnd = useCallback(
Expand Down Expand Up @@ -118,18 +114,8 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
onBrushEnd: handleBrushEnd,
yTickFormatter,
showLegend,
yTitle,
}),
[
chartHeight,
startDate,
legendPosition,
endDate,
handleBrushEnd,
yTickFormatter,
showLegend,
yTitle,
]
[chartHeight, startDate, legendPosition, endDate, handleBrushEnd, yTickFormatter, showLegend]
);
const [isInitialLoading, setIsInitialLoading] = useState(true);
const [selectedStackByOption, setSelectedStackByOption] = useState<MatrixHistogramOption>(
Expand Down Expand Up @@ -243,11 +229,6 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
timelineId={timelineId}
/>
)}
{footerChildren != null && (
<EuiFlexGroup gutterSize="none" direction="row">
{footerChildren}
</EuiFlexGroup>
)}
</HistogramPanel>
</InspectButtonContainer>
{showSpacer && <EuiSpacer data-test-subj="spacer" size="l" />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface MatrixHistogramQueryProps {
startDate: string;
histogramType: MatrixHistogramType;
threshold?: { field: string | undefined; value: number } | undefined;
skip?: boolean;
}

export interface MatrixHistogramProps extends MatrixHistogramBasicProps {
Expand Down Expand Up @@ -105,7 +106,6 @@ export interface BarchartConfigs {
yTickFormatter: TickFormatter;
tickSize: number;
};
yAxisTitle: string | undefined;
settings: {
legendPosition: Position;
onBrushEnd: UpdateDateRange;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface GetBarchartConfigsProps {
onBrushEnd: UpdateDateRange;
yTickFormatter?: (value: number) => string;
showLegend?: boolean;
yTitle?: string | undefined;
}

export const DEFAULT_CHART_HEIGHT = 174;
Expand All @@ -33,7 +32,6 @@ export const getBarchartConfigs = ({
onBrushEnd,
yTickFormatter,
showLegend,
yTitle,
}: GetBarchartConfigsProps): BarchartConfigs => ({
series: {
xScaleType: ScaleType.Time,
Expand All @@ -45,7 +43,6 @@ export const getBarchartConfigs = ({
yTickFormatter: yTickFormatter != null ? yTickFormatter : DEFAULT_Y_TICK_FORMATTER,
tickSize: 8,
},
yAxisTitle: yTitle,
settings: {
legendPosition: legendPosition ?? Position.Right,
onBrushEnd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ import { getInspectResponse } from '../../../helpers';
import { InspectResponse } from '../../../types';
import * as i18n from './translations';

export type Buckets = Array<{
key: string;
doc_count: number;
}>;

const bucketEmpty: Buckets = [];

export interface UseMatrixHistogramArgs {
data: MatrixHistogramData[];
inspect: InspectResponse;
Expand All @@ -49,7 +56,12 @@ export const useMatrixHistogram = ({
stackByField,
startDate,
threshold,
}: MatrixHistogramQueryProps): [boolean, UseMatrixHistogramArgs] => {
skip = false,
}: MatrixHistogramQueryProps): [
boolean,
UseMatrixHistogramArgs,
(to: string, from: string) => void
] => {
const { data, notifications } = useKibana().services;
const refetch = useRef<inputsModel.Refetch>(noop);
const abortCtrl = useRef(new AbortController());
Expand Down Expand Up @@ -98,10 +110,11 @@ export const useMatrixHistogram = ({
next: (response) => {
if (isCompleteResponse(response)) {
if (!didCancel) {
const histogramBuckets: Array<{
key: string;
doc_count: number;
}> = getOr([], 'rawResponse.aggregations.eventActionGroup.buckets', response);
const histogramBuckets: Buckets = getOr(
bucketEmpty,
'rawResponse.aggregations.eventActionGroup.buckets',
response
);
setLoading(false);
setMatrixHistogramResponse((prevResponse) => ({
...prevResponse,
Expand All @@ -123,10 +136,12 @@ export const useMatrixHistogram = ({
}
},
error: (msg) => {
if (!didCancel) {
setLoading(false);
}
if (!(msg instanceof AbortError)) {
notifications.toasts.addDanger({
notifications.toasts.addError(msg, {
title: errorMessage ?? i18n.FAIL_MATRIX_HISTOGRAM,
text: msg.message,
});
}
},
Expand Down Expand Up @@ -166,8 +181,24 @@ export const useMatrixHistogram = ({
}, [indexNames, endDate, filterQuery, startDate, stackByField, histogramType, threshold]);

useEffect(() => {
hostsSearch(matrixHistogramRequest);
}, [matrixHistogramRequest, hostsSearch]);
if (!skip) {
hostsSearch(matrixHistogramRequest);
}
}, [matrixHistogramRequest, hostsSearch, skip]);

const runMatrixHistogramSearch = useCallback(
(to: string, from: string) => {
hostsSearch({
...matrixHistogramRequest,
timerange: {
interval: '12h',
from,
to,
},
});
},
[matrixHistogramRequest, hostsSearch]
);

return [loading, matrixHistogramResponse];
return [loading, matrixHistogramResponse, runMatrixHistogramSearch];
};
68 changes: 0 additions & 68 deletions x-pack/plugins/security_solution/public/common/hooks/eql/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { Unit } from '@elastic/datemath';

import { DataPublicPluginStart } from '../../../../../../../src/plugins/data/public';
import {
Expand All @@ -16,10 +15,6 @@ import {
isErrorResponse,
isValidationErrorResponse,
} from '../../../../common/search_strategy/eql';
import { getEqlAggsData, getSequenceAggs } from './helpers';
import { EqlPreviewResponse, Source } from './types';
import { hasEqlSequenceQuery } from '../../../../common/detection_engine/utils';
import { EqlSearchResponse } from '../../../../common/detection_engine/types';

interface Params {
index: string[];
Expand Down Expand Up @@ -56,66 +51,3 @@ export const validateEql = async ({
return { valid: true, errors: [] };
}
};

interface AggsParams {
data: DataPublicPluginStart;
index: string[];
interval: Unit;
fromTime: string;
query: string;
toTime: string;
signal: AbortSignal;
}

export const getEqlPreview = async ({
data,
index,
interval,
query,
fromTime,
toTime,
signal,
}: AggsParams): Promise<EqlPreviewResponse> => {
try {
const response = await data.search
.search<EqlSearchStrategyRequest, EqlSearchStrategyResponse<EqlSearchResponse<Source>>>(
{
params: {
// @ts-expect-error allow_no_indices is missing on EqlSearch
allow_no_indices: true,
index: index.join(),
body: {
filter: {
range: {
'@timestamp': {
gte: toTime,
lte: fromTime,
format: 'strict_date_optional_time',
},
},
},
query,
// EQL requires a cap, otherwise it defaults to 10
// It also sorts on ascending order, capping it at
// something smaller like 20, made it so that some of
// the more recent events weren't returned
size: 100,
},
},
},
{
strategy: 'eql',
abortSignal: signal,
}
)
.toPromise();

if (hasEqlSequenceQuery(query)) {
return getSequenceAggs(response, interval, toTime, fromTime);
} else {
return getEqlAggsData(response, interval, toTime, fromTime);
}
} catch (err) {
throw new Error(JSON.stringify(err));
}
};
Loading