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] Fix incorrect time for dns histogram #83532

Merged
merged 34 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
58f8ec0
getSuitableUnit
angorayc Nov 9, 2020
ab2ee15
Merge branch 'master' of github.com:elastic/kibana into calendar-inte…
angorayc Nov 10, 2020
2eb6d17
update dns histogram query
angorayc Nov 10, 2020
e5356b1
update dns query
angorayc Nov 12, 2020
93ecd9e
update dns histogram query
angorayc Nov 12, 2020
49de18d
fix type error
angorayc Nov 16, 2020
8611973
Merge branch 'master' of github.com:elastic/kibana into calendar-inte…
angorayc Nov 16, 2020
a78a577
fix lint error
angorayc Nov 16, 2020
eadd57f
remove unused comments
angorayc Nov 17, 2020
987c436
fix histogram query size
angorayc Nov 17, 2020
b6b4490
revert change
angorayc Nov 17, 2020
d2c99d7
Merge branch 'master' of github.com:elastic/kibana into calendar-inte…
angorayc Nov 17, 2020
491acc0
Merge branch 'calendar-interval' of github.com:angorayc/kibana into c…
angorayc Nov 17, 2020
b49484c
fix unit test
angorayc Nov 17, 2020
b0a3079
Merge branch 'master' of github.com:elastic/kibana into calendar-inte…
angorayc Nov 17, 2020
d934574
fix dns request options
angorayc Nov 18, 2020
be1c2bd
Merge branch 'master' into calendar-interval
kibanamachine Nov 18, 2020
c67af56
clean up
angorayc Nov 18, 2020
80946c6
Merge branch 'calendar-interval' of github.com:angorayc/kibana into c…
angorayc Nov 18, 2020
cdb1b9f
cleanup types
angorayc Nov 19, 2020
852f0db
Merge branch 'master' into calendar-interval
kibanamachine Nov 23, 2020
8d52fe5
Merge branch 'master' of github.com:elastic/kibana into calendar-inte…
angorayc Nov 23, 2020
ff79765
Merge branch 'calendar-interval' of github.com:angorayc/kibana into c…
angorayc Nov 23, 2020
251e7df
fix dependency
angorayc Nov 23, 2020
79d087e
review
angorayc Nov 23, 2020
5bd67a5
review
angorayc Nov 23, 2020
bec1f1d
revert
angorayc Nov 23, 2020
c1b9e44
restore docValueFields
angorayc Nov 23, 2020
c9660a7
fix unit test
angorayc Nov 23, 2020
2bcdd8f
cleanup
angorayc Nov 23, 2020
3a3f7e3
restore docValueFields for dns histogram
angorayc Nov 24, 2020
d5ca920
review
angorayc Nov 24, 2020
46936c4
review
angorayc Nov 24, 2020
5258750
lint
angorayc Nov 24, 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 @@ -37,6 +37,7 @@ export interface MatrixHistogramRequestOptions extends RequestBasicOptions {
stackByField: string;
threshold?: { field: string | undefined; value: number } | undefined;
inspect?: Maybe<Inspect>;
isPtrIncluded?: boolean;
}

export interface MatrixHistogramStrategyResponse extends IEsSearchResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const checkIfAnyValidSeriesExist = (
!checkIfAllValuesAreZero(data) &&
data.some(checkIfAllTheDataInTheSeriesAreValid);

const yAccessors = ['y'];
const splitSeriesAccessors = ['g'];

// Bar chart rotation: https://ela.st/chart-rotations
export const BarChartBaseComponent = ({
data,
Expand Down Expand Up @@ -86,9 +89,9 @@ export const BarChartBaseComponent = ({
xScaleType={getOr(ScaleType.Linear, 'configs.series.xScaleType', chartConfigs)}
yScaleType={getOr(ScaleType.Linear, 'configs.series.yScaleType', chartConfigs)}
xAccessor="x"
yAccessors={['y']}
yAccessors={yAccessors}
timeZone={timeZone}
splitSeriesAccessors={['g']}
splitSeriesAccessors={splitSeriesAccessors}
data={series.value!}
stackAccessors={get('configs.series.stackAccessors', chartConfigs)}
color={series.color ? series.color : undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const HistogramPanel = styled(Panel)<{ height?: number }>`
export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> = ({
chartHeight,
defaultStackByOption,
docValueFields,
endDate,
errorMessage,
filterQuery,
Expand All @@ -72,6 +73,7 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
hideHistogramIfEmpty = false,
id,
indexNames,
isPtrIncluded,
legendPosition,
mapping,
panelHeight = DEFAULT_PANEL_HEIGHT,
Expand Down Expand Up @@ -138,6 +140,8 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
indexNames,
startDate,
stackByField: selectedStackByOption.value,
isPtrIncluded,
docValueFields,
});

const titleWithStackByField = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { InputsModelId } from '../../store/inputs/constants';
import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution';
import { UpdateDateRange } from '../charts/common';
import { GlobalTimeArgs } from '../../containers/use_global_time';
import { DocValueFields } from '../../../../common/search_strategy';

export type MatrixHistogramMappingTypes = Record<
string,
Expand Down Expand Up @@ -57,6 +58,7 @@ interface MatrixHistogramBasicProps {
}

export interface MatrixHistogramQueryProps {
docValueFields?: DocValueFields[];
endDate: string;
errorMessage: string;
indexNames: string[];
Expand All @@ -72,6 +74,7 @@ export interface MatrixHistogramQueryProps {
histogramType: MatrixHistogramType;
threshold?: { field: string | undefined; value: number } | undefined;
skip?: boolean;
isPtrIncluded?: boolean;
}

export interface MatrixHistogramProps extends MatrixHistogramBasicProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import deepEqual from 'fast-deep-equal';
import { getOr, noop } from 'lodash/fp';
import { getOr, isEmpty, noop } from 'lodash/fp';
import { useCallback, useEffect, useRef, useState } from 'react';

import { MatrixHistogramQueryProps } from '../../components/matrix_histogram/types';
Expand Down Expand Up @@ -43,11 +43,13 @@ export interface UseMatrixHistogramArgs {
}

export const useMatrixHistogram = ({
docValueFields,
endDate,
errorMessage,
filterQuery,
histogramType,
indexNames,
isPtrIncluded,
stackByField,
startDate,
threshold,
Expand Down Expand Up @@ -76,6 +78,8 @@ export const useMatrixHistogram = ({
},
stackByField,
threshold,
...(isPtrIncluded != null ? { isPtrIncluded } : {}),
...(!isEmpty(docValueFields) ? { docValueFields } : {}),
});

const [matrixHistogramResponse, setMatrixHistogramResponse] = useState<UseMatrixHistogramArgs>({
Expand Down Expand Up @@ -167,13 +171,25 @@ export const useMatrixHistogram = ({
},
stackByField,
threshold,
...(isPtrIncluded != null ? { isPtrIncluded } : {}),
...(!isEmpty(docValueFields) ? { docValueFields } : {}),
};
if (!deepEqual(prevRequest, myRequest)) {
return myRequest;
}
return prevRequest;
});
}, [indexNames, endDate, filterQuery, startDate, stackByField, histogramType, threshold]);
}, [
indexNames,
endDate,
filterQuery,
startDate,
stackByField,
histogramType,
threshold,
isPtrIncluded,
docValueFields,
]);

useEffect(() => {
if (!skip) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@ import { inputsModel } from '../../../common/store';
import { useShallowEqualSelector } from '../../../common/hooks/use_selector';
import { useKibana } from '../../../common/lib/kibana';
import { createFilter } from '../../../common/containers/helpers';
import { NetworkDnsEdges, PageInfoPaginated } from '../../../../common/search_strategy';
import { generateTablePaginationOptions } from '../../../common/components/paginated_table/helpers';
import { networkModel, networkSelectors } from '../../store';
import {
DocValueFields,
NetworkQueries,
NetworkDnsRequestOptions,
NetworkDnsStrategyResponse,
MatrixOverOrdinalHistogramData,
} from '../../../../common/search_strategy/security_solution/network';
NetworkDnsEdges,
PageInfoPaginated,
} from '../../../../common/search_strategy';
import { isCompleteResponse, isErrorResponse } from '../../../../../../../src/plugins/data/common';
import { AbortError } from '../../../../../../../src/plugins/kibana_utils/common';
import * as i18n from './translations';
import { getInspectResponse } from '../../../helpers';
import { InspectResponse } from '../../../types';

export * from './histogram';

const ID = 'networkDnsQuery';

export interface NetworkDnsArgs {
Expand All @@ -47,6 +47,7 @@ export interface NetworkDnsArgs {

interface UseNetworkDns {
id?: string;
docValueFields: DocValueFields[];
indexNames: string[];
type: networkModel.NetworkType;
filterQuery?: ESTermQuery | string;
Expand All @@ -56,6 +57,7 @@ interface UseNetworkDns {
}

export const useNetworkDns = ({
docValueFields,
endDate,
filterQuery,
indexNames,
Expand All @@ -74,6 +76,7 @@ export const useNetworkDns = ({
!skip
? {
defaultIndex: indexNames,
docValueFields: docValueFields ?? [],
factoryQueryType: NetworkQueries.dns,
filterQuery: createFilter(filterQuery),
isPtrIncluded,
Expand Down Expand Up @@ -190,6 +193,7 @@ export const useNetworkDns = ({
const myRequest = {
...(prevRequest ?? {}),
defaultIndex: indexNames,
docValueFields: docValueFields ?? [],
isPtrIncluded,
factoryQueryType: NetworkQueries.dns,
filterQuery: createFilter(filterQuery),
Expand All @@ -206,7 +210,18 @@ export const useNetworkDns = ({
}
return prevRequest;
});
}, [activePage, indexNames, endDate, filterQuery, limit, startDate, sort, skip, isPtrIncluded]);
}, [
activePage,
indexNames,
endDate,
filterQuery,
limit,
startDate,
sort,
skip,
isPtrIncluded,
docValueFields,
]);

useEffect(() => {
networkDnsSearch(networkDnsRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, { useEffect, useCallback, useMemo } from 'react';
import { getOr } from 'lodash/fp';

import { NetworkDnsTable } from '../../components/network_dns_table';
import { useNetworkDns, HISTOGRAM_ID } from '../../containers/network_dns';
import { useNetworkDns } from '../../containers/network_dns';
import { manageQuery } from '../../../common/components/page/manage_query';

import { NetworkComponentQueryProps } from './types';
Expand All @@ -20,6 +20,10 @@ import {
import * as i18n from '../translations';
import { MatrixHistogram } from '../../../common/components/matrix_histogram';
import { MatrixHistogramType } from '../../../../common/search_strategy/security_solution';
import { networkSelectors } from '../../store';
import { useShallowEqualSelector } from '../../../common/hooks/use_selector';

const HISTOGRAM_ID = 'networkDnsHistogramQuery';

const NetworkDnsTableManage = manageQuery(NetworkDnsTable);

Expand All @@ -43,6 +47,7 @@ export const histogramConfigs: Omit<MatrixHistogramConfigs, 'title'> = {

const DnsQueryTabBodyComponent: React.FC<NetworkComponentQueryProps> = ({
deleteQuery,
docValueFields,
endDate,
filterQuery,
indexNames,
Expand All @@ -51,6 +56,9 @@ const DnsQueryTabBodyComponent: React.FC<NetworkComponentQueryProps> = ({
setQuery,
type,
}) => {
const getNetworkDnsSelector = networkSelectors.dnsSelector();
const { isPtrIncluded } = useShallowEqualSelector(getNetworkDnsSelector);

useEffect(() => {
return () => {
if (deleteQuery) {
Expand All @@ -63,6 +71,7 @@ const DnsQueryTabBodyComponent: React.FC<NetworkComponentQueryProps> = ({
loading,
{ totalCount, networkDns, pageInfo, loadPage, id, inspect, isInspected, refetch },
] = useNetworkDns({
docValueFields: docValueFields ?? [],
endDate,
filterQuery,
indexNames,
Expand All @@ -87,9 +96,11 @@ const DnsQueryTabBodyComponent: React.FC<NetworkComponentQueryProps> = ({
return (
<>
<MatrixHistogram
id={HISTOGRAM_ID}
isPtrIncluded={isPtrIncluded}
docValueFields={docValueFields}
endDate={endDate}
filterQuery={filterQuery}
id={HISTOGRAM_ID}
indexNames={indexNames}
setQuery={setQuery}
showLegend={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { UpdateDateRange } from '../../../common/components/charts/common';
export const NetworkRoutes = React.memo<NetworkRoutesProps>(
({
networkPagePath,
docValueFields,
type,
to,
filterQuery,
Expand Down Expand Up @@ -107,7 +108,7 @@ export const NetworkRoutes = React.memo<NetworkRoutesProps>(
return (
<Switch>
<Route path={`/:tabName(${NetworkRouteType.dns})`}>
<DnsQueryTabBody {...tabProps} />
<DnsQueryTabBody {...tabProps} docValueFields={docValueFields} />
</Route>
<Route path={`/:tabName(${NetworkRouteType.flows})`}>
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { GlobalTimeArgs } from '../../../common/containers/use_global_time';

import { SetAbsoluteRangeDatePicker } from '../types';
import { NarrowDateRange } from '../../../common/components/ml/types';
import { DocValueFields } from '../../../common/containers/source';

interface QueryTabBodyProps extends Pick<GlobalTimeArgs, 'setQuery' | 'deleteQuery'> {
skip: boolean;
Expand All @@ -25,7 +26,9 @@ interface QueryTabBodyProps extends Pick<GlobalTimeArgs, 'setQuery' | 'deleteQue
indexNames: string[];
}

export type NetworkComponentQueryProps = QueryTabBodyProps;
export type NetworkComponentQueryProps = QueryTabBodyProps & {
docValueFields?: DocValueFields[];
};

export type IPsQueryTabBodyProps = QueryTabBodyProps & {
indexPattern: IIndexPattern;
Expand All @@ -42,6 +45,7 @@ export type HttpQueryTabBodyProps = QueryTabBodyProps & {
};

export type NetworkRoutesProps = GlobalTimeArgs & {
docValueFields: DocValueFields[];
networkPagePath: string;
type: networkModel.NetworkType;
filterQuery?: string | ESTermQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const NetworkComponent = React.memo<NetworkComponentProps & PropsFromRedux>(
</Display>

<NetworkRoutes
docValueFields={docValueFields}
filterQuery={tabsFilterQuery}
from={from}
isInitializing={isInitializing}
Expand Down
Loading