Skip to content

Commit

Permalink
[Security Solution] Remove docValueFields usage from security_soultio…
Browse files Browse the repository at this point in the history
…n and timelines plugins (#137802)

* [Security Solution] Remove docValueFields usage from security_soultion and timelines plugins

* [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix'

* Fixed tests

* Fixed type checkes

* Removed unused type

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* Fixed tests

* Fixed FTR

* Fixed unit test

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
YulNaumenko and kibanamachine authored Aug 23, 2022
1 parent 1a70f6f commit 1ae09bc
Show file tree
Hide file tree
Showing 62 changed files with 46 additions and 621 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export type {
SortField,
TimerangeInput,
PaginationInputPaginated,
DocValueFields,
CursorType,
TotalValue,
} from '@kbn/timelines-plugin/common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@ export type {
BrowserField,
BrowserFields,
} from '@kbn/timelines-plugin/common';
export {
EMPTY_BROWSER_FIELDS,
EMPTY_DOCVALUE_FIELD,
EMPTY_INDEX_FIELDS,
} from '@kbn/timelines-plugin/common';
export { EMPTY_BROWSER_FIELDS, EMPTY_INDEX_FIELDS } from '@kbn/timelines-plugin/common';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { IEsSearchRequest } from '@kbn/data-plugin/common';
import type { ESQuery } from '../../typed_json';
import type {
Expand Down Expand Up @@ -120,7 +119,6 @@ export interface RequestBasicOptions extends IEsSearchRequest {
timerange: TimerangeInput;
filterQuery: ESQuery | string | undefined;
defaultIndex: string[];
docValueFields?: estypes.QueryDslFieldAndFormat[];
factoryQueryType?: FactoryQueryTypes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const HistogramPanel = styled(Panel)<{ height?: number }>`
export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> = ({
chartHeight,
defaultStackByOption,
docValueFields,
endDate,
errorMessage,
filterQuery,
Expand Down Expand Up @@ -176,7 +175,6 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
stackByField: selectedStackByOption.value,
runtimeMappings,
isPtrIncluded,
docValueFields,
skip: querySkip,
};
const [loading, { data, inspect, totalCount, refetch }] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { InputsModelId } from '../../store/inputs/constants';
import type { MatrixHistogramType } from '../../../../common/search_strategy/security_solution';
import type { UpdateDateRange } from '../charts/common';
import type { GlobalTimeArgs } from '../../containers/use_global_time';
import type { DocValueFields } from '../../../../common/search_strategy';
import type { FieldValueThreshold } from '../../../detections/components/rules/threshold_input';
import type { GetLensAttributes, LensAttributes } from '../visualization_actions/types';

Expand Down Expand Up @@ -66,7 +65,6 @@ interface MatrixHistogramBasicProps {
}

export interface MatrixHistogramQueryProps {
docValueFields?: DocValueFields[];
endDate: string;
errorMessage: string;
indexNames: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

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

Expand Down Expand Up @@ -48,7 +48,6 @@ export interface UseMatrixHistogramArgs {
}

export const useMatrixHistogram = ({
docValueFields,
endDate,
errorMessage,
filterQuery,
Expand Down Expand Up @@ -88,7 +87,6 @@ export const useMatrixHistogram = ({
runtimeMappings,
threshold,
...(isPtrIncluded != null ? { isPtrIncluded } : {}),
...(!isEmpty(docValueFields) ? { docValueFields } : {}),
...(includeMissingData != null ? { includeMissingData } : {}),
});
const { addError, addWarning } = useAppToasts();
Expand Down Expand Up @@ -171,7 +169,6 @@ export const useMatrixHistogram = ({
stackByField,
threshold,
...(isPtrIncluded != null ? { isPtrIncluded } : {}),
...(!isEmpty(docValueFields) ? { docValueFields } : {}),
};
if (!deepEqual(prevRequest, myRequest)) {
return myRequest;
Expand All @@ -187,7 +184,6 @@ export const useMatrixHistogram = ({
histogramType,
threshold,
isPtrIncluded,
docValueFields,
]);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ describe('source/index.tsx', () => {
expect(payload.id).toEqual('neato');
expect(Object.keys(payload.browserFields)).toHaveLength(12);
expect(Object.keys(payload.indexFields)).toHaveLength(mocksSource.indexFields.length);
expect(payload.docValueFields).toEqual([{ field: '@timestamp' }]);
});

it('should reuse the result for dataView info when cleanCache not passed', async () => {
Expand All @@ -120,23 +119,18 @@ describe('source/index.tsx', () => {

await indexFieldsSearch!({ dataViewId: 'neato' });
const {
payload: { browserFields, indexFields, docValueFields },
payload: { browserFields, indexFields },
} = mockDispatch.mock.calls[1][0];

mockDispatch.mockClear();

await indexFieldsSearch!({ dataViewId: 'neato' });
const {
payload: {
browserFields: newBrowserFields,
indexFields: newIndexFields,
docValueFields: newDocValueFields,
},
payload: { browserFields: newBrowserFields, indexFields: newIndexFields },
} = mockDispatch.mock.calls[1][0];

expect(browserFields).toBe(newBrowserFields);
expect(indexFields).toBe(newIndexFields);
expect(docValueFields).toBe(newDocValueFields);
});

it('should not reuse the result for dataView info when cleanCache passed', async () => {
Expand All @@ -154,23 +148,18 @@ describe('source/index.tsx', () => {

await indexFieldsSearch!({ dataViewId: 'neato' });
const {
payload: { browserFields, indexFields, docValueFields },
payload: { browserFields, indexFields },
} = mockDispatch.mock.calls[1][0];

mockDispatch.mockClear();

await indexFieldsSearch!({ dataViewId: 'neato', cleanCache: true });
const {
payload: {
browserFields: newBrowserFields,
indexFields: newIndexFields,
docValueFields: newDocValueFields,
},
payload: { browserFields: newBrowserFields, indexFields: newIndexFields },
} = mockDispatch.mock.calls[1][0];

expect(browserFields).not.toBe(newBrowserFields);
expect(indexFields).not.toBe(newIndexFields);
expect(docValueFields).not.toBe(newDocValueFields);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { Subscription } from 'rxjs';
import type {
BrowserField,
BrowserFields,
DocValueFields,
IndexField,
IndexFieldsStrategyRequest,
IndexFieldsStrategyResponse,
Expand All @@ -26,7 +25,7 @@ import * as i18n from './translations';
import { useAppToasts } from '../../hooks/use_app_toasts';
import { getDataViewStateFromIndexFields } from './use_data_view';

export type { BrowserField, BrowserFields, DocValueFields };
export type { BrowserField, BrowserFields };

export function getAllBrowserFields(browserFields: BrowserFields): Array<Partial<BrowserField>> {
const result: Array<Partial<BrowserField>> = [];
Expand Down Expand Up @@ -86,11 +85,8 @@ export const getBrowserFields = memoizeOne(

const DEFAULT_BROWSER_FIELDS = {};
const DEFAULT_INDEX_PATTERNS = { fields: [], title: '' };
const DEFAULT_DOC_VALUE_FIELDS: DocValueFields[] = [];

interface FetchIndexReturn {
browserFields: BrowserFields;
docValueFields: DocValueFields[];
indexes: string[];
indexExists: boolean;
indexPatterns: DataViewBase;
Expand All @@ -112,7 +108,6 @@ export const useFetchIndex = (

const [state, setState] = useState<FetchIndexReturn>({
browserFields: DEFAULT_BROWSER_FIELDS,
docValueFields: DEFAULT_DOC_VALUE_FIELDS,
indexes: indexNames,
indexExists: true,
indexPatterns: DEFAULT_INDEX_PATTERNS,
Expand Down Expand Up @@ -140,14 +135,13 @@ export const useFetchIndex = (
const stringifyIndices = response.indicesExist.sort().join();

previousIndexesName.current = response.indicesExist;
const { browserFields, docValueFields } = getDataViewStateFromIndexFields(
const { browserFields } = getDataViewStateFromIndexFields(
stringifyIndices,
response.indexFields
);
setLoading(false);
setState({
browserFields,
docValueFields,
indexes: response.indicesExist,
indexExists: response.indicesExist.length > 0,
indexPatterns: getIndexFields(stringifyIndices, response.indexFields),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import type { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { DEFAULT_INDEX_PATTERN } from '../../../../common/constants';
import type { DocValueFields } from '../../../../common/search_strategy';
import type { BrowserFields } from '../../../../common/search_strategy/index_fields';

export const mocksSource = {
Expand Down Expand Up @@ -957,17 +956,6 @@ export const mockBrowserFields: BrowserFields = {
},
};

export const mockDocValueFields: DocValueFields[] = [
{
field: '@timestamp',
format: 'date_time',
},
{
field: 'event.end',
format: 'date_time',
},
];

export const mockRuntimeMappings: MappingRuntimeFields = {
'@a.runtime.field': {
script: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import memoizeOne from 'memoize-one';
import { omit, pick } from 'lodash/fp';
import type {
BrowserField,
DocValueFields,
IndexField,
IndexFieldsStrategyRequest,
IndexFieldsStrategyResponse,
Expand Down Expand Up @@ -40,7 +39,6 @@ type DangerCastForBrowserFieldsMutation = Record<
>;
interface DataViewInfo {
browserFields: DangerCastForBrowserFieldsMutation;
docValueFields: DocValueFields[];
indexFields: FieldSpec[];
}

Expand Down Expand Up @@ -69,17 +67,10 @@ export const getDataViewStateFromIndexFields = memoizeOne(
pick(['name', 'searchable', 'type', 'aggregatable', 'esTypes', 'subType'], field)
);

// mutate docValueFields
if (field.readFromDocValues && acc.docValueFields.length < 100) {
acc.docValueFields.push({
field: field.name,
});
}
return acc;
},
{
browserFields: {},
docValueFields: [],
indexFields: [],
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ export const useSourcererDataView = (
() => ({
browserFields: sourcererDataView.browserFields,
dataViewId: sourcererDataView.id,
docValueFields: sourcererDataView.docValueFields,
indexPattern: {
fields: sourcererDataView.indexFields,
title: selectedPatterns.join(','),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
interface SelectedDataView {
browserFields: SourcererDataView['browserFields'];
dataViewId: string | null; // null if legacy pre-8.0 timeline
docValueFields: SourcererDataView['docValueFields'];
/**
* DataViewBase with enhanced index fields used in timelines
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ import type { ManagementState } from '../../management/types';
import { initialSourcererState, SourcererScopeName } from '../store/sourcerer/model';
import { allowedExperimentalValues } from '../../../common/experimental_features';
import { getScopePatternListSelection } from '../store/sourcerer/helpers';
import {
mockBrowserFields,
mockDocValueFields,
mockIndexFields,
mockRuntimeMappings,
} from '../containers/source/mock';
import { mockBrowserFields, mockIndexFields, mockRuntimeMappings } from '../containers/source/mock';
import { usersModel } from '../../users/store';
import { UsersFields } from '../../../common/search_strategy/security_solution/users/common';

Expand All @@ -49,7 +44,6 @@ export const mockSourcererState = {
defaultDataView: {
...initialSourcererState.defaultDataView,
browserFields: mockBrowserFields,
docValueFields: mockDocValueFields,
id: DEFAULT_DATA_VIEW_ID,
indexFields: mockIndexFields,
loading: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const actionCreator = actionCreatorFactory('x-pack/security_solution/local/sourc

export const setDataView = actionCreator<{
browserFields: SourcererDataView['browserFields'];
docValueFields: SourcererDataView['docValueFields'];
id: SourcererDataView['id'];
indexFields: SourcererDataView['indexFields'];
loading: SourcererDataView['loading'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
*/

import type { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { BrowserFields, DocValueFields } from '@kbn/timelines-plugin/common';
import {
EMPTY_BROWSER_FIELDS,
EMPTY_DOCVALUE_FIELD,
EMPTY_INDEX_FIELDS,
} from '@kbn/timelines-plugin/common';
import type { BrowserFields } from '@kbn/timelines-plugin/common';
import { EMPTY_BROWSER_FIELDS, EMPTY_INDEX_FIELDS } from '@kbn/timelines-plugin/common';
import type { SecuritySolutionDataViewBase } from '../../types';
/** Uniquely identifies a Sourcerer Scope */
export enum SourcererScopeName {
Expand Down Expand Up @@ -64,8 +60,6 @@ export interface SourcererDataView extends KibanaDataView {
* category, description, format
* indices the field is included in etc*/
browserFields: BrowserFields;
/** query DSL field and format */
docValueFields: DocValueFields[];
/** comes from dataView.fields.toSpec() */
indexFields: SecuritySolutionDataViewBase['fields'];
/** set when data view fields are fetched */
Expand All @@ -84,7 +78,6 @@ export interface SourcererDataView extends KibanaDataView {
export interface SelectedDataView {
browserFields: SourcererDataView['browserFields'];
dataViewId: string | null; // null if legacy pre-8.0 timeline
docValueFields: SourcererDataView['docValueFields'];
/**
* DataViewBase with enhanced index fields used in timelines
*/
Expand Down Expand Up @@ -131,7 +124,6 @@ export const initSourcererScope: Omit<SourcererScope, 'id'> = {
};
export const initDataView = {
browserFields: EMPTY_BROWSER_FIELDS,
docValueFields: EMPTY_DOCVALUE_FIELD,
id: '',
indexFields: EMPTY_INDEX_FIELDS,
loading: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ interface SourcererDataView extends KibanaDataView {
* indices the field is included in etc*/
browserFields: BrowserFields;
/** query DSL field and format */
docValueFields: DocValueFields[];
/** comes from dataView.fields.toSpec() */
indexFields: SecuritySolutionDataViewBase['fields'];
/** set when data view fields are fetched */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { merge } from '@kbn/std';
import { isPlainObject } from 'lodash';
import type { Ecs } from '@kbn/cases-plugin/common';

// TODO we need to allow -> docValueFields: [{ field: "@timestamp" }],
export const buildAlertsQuery = (alertIds: string[]) => {
if (alertIds.length === 0) {
return {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,6 @@ const StepDefineRuleComponent: FC<StepDefineRuleProps> = ({
component={QueryBarDefineRule}
componentProps={{
browserFields,
// docValueFields,
// runtimeMappings,
idAria: 'detectionEngineStepDefineRuleQueryBar',
indexPattern,
Expand Down
Loading

0 comments on commit 1ae09bc

Please sign in to comment.