Skip to content

Commit

Permalink
[Security Solution] Remove active patterns from Sourcerer (#190020)
Browse files Browse the repository at this point in the history
## Summary

Another round of field removal, this time I am replacing the
`activePatterns` field with `dataView.title` based logic for active
pattern retrieval.

This is mostly about upgrade flow for sourcerer going from stack v7 to
8.
  • Loading branch information
lgestc authored Aug 19, 2024
1 parent 51df059 commit d1c4bb3
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe('useThreatIntelligenceDetails', () => {
dataViewId: '',
loading: false,
indicesExist: true,
patternList: [],
selectedPatterns: [],
indexPattern: { fields: [], title: '' },
sourcererDataView: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import type { ReactWrapper } from 'enzyme';
import { mount } from 'enzyme';

import { SourcererScopeName } from '../store/model';
import { type SelectedDataView, SourcererScopeName } from '../store/model';
import { Sourcerer } from '.';
import { sourcererActions, sourcererModel } from '../store';
import { createMockStore, mockGlobalState, TestProviders } from '../../common/mock';
Expand Down Expand Up @@ -74,9 +74,13 @@ const { id, patternList, title } = mockGlobalState.sourcerer.defaultDataView;
const patternListNoSignals = sortWithExcludesAtEnd(
patternList.filter((p) => p !== mockGlobalState.sourcerer.signalIndexName)
);
const sourcererDataView = {
const sourcererDataView: Partial<SelectedDataView> = {
indicesExist: true,
loading: false,
sourcererDataView: {
title:
'apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,logs-*,packetbeat-*,traces-apm*,winlogbeat-*,-*elastic-cloud-logs-*',
},
};

describe('Sourcerer component', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,19 @@ export const Sourcerer = React.memo<SourcererComponentProps>(({ scope: scopeId }
}
}, [isDetectionsSourcerer, isTimelineSourcerer, pollForSignalIndex]);

const { activePatterns, indicesExist, loading } = useSourcererDataView(scopeId);
const { indicesExist, loading, sourcererDataView } = useSourcererDataView(scopeId);

const activePatterns = useMemo(
() => (sourcererDataView?.title || '')?.split(',').filter(Boolean) as string[],
[sourcererDataView?.title]
);

const [missingPatterns, setMissingPatterns] = useState<string[]>(
activePatterns && activePatterns.length > 0
? sourcererMissingPatterns.filter((p) => activePatterns.includes(p))
: []
);

useEffect(() => {
if (activePatterns && activePatterns.length > 0) {
setMissingPatterns(sourcererMissingPatterns.filter((p) => activePatterns.includes(p)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { ReactWrapper } from 'enzyme';
import { mount } from 'enzyme';
import { cloneDeep } from 'lodash';

import { initialSourcererState, SourcererScopeName } from '../store/model';
import { initialSourcererState, type SelectedDataView, SourcererScopeName } from '../store/model';
import { Sourcerer } from '.';
import { sourcererActions, sourcererModel } from '../store';
import { createMockStore, mockGlobalState, TestProviders } from '../../common/mock';
Expand Down Expand Up @@ -74,9 +74,12 @@ const { id, patternList } = mockGlobalState.sourcerer.defaultDataView;
const patternListNoSignals = sortWithExcludesAtEnd(
patternList.filter((p) => p !== mockGlobalState.sourcerer.signalIndexName)
);
const sourcererDataView = {
const sourcererDataView: Partial<SelectedDataView> = {
indicesExist: true,
loading: false,
sourcererDataView: {
title: 'myFakebeat-*',
},
};

describe('No data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ describe('Sourcerer integration tests', () => {

(useSourcererDataView as jest.Mock).mockReturnValue({
...sourcererDataView,
activePatterns: ['myFakebeat-*'],
});
jest.clearAllMocks();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ export const mockSourcererScope: SelectedDataView = {
indicesExist: true,
loading: false,
dataViewId: mockGlobalState.sourcerer.defaultDataView.id,
patternList: mockPatterns,
};
15 changes: 1 addition & 14 deletions x-pack/plugins/security_solution/public/sourcerer/store/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,8 @@ export interface SelectedDataView {
indicesExist: boolean;
/** is an update being made to the data view */
loading: boolean;
/**
* @deprecated use sourcererDataView.title or sourcererDataView.matchedIndices
* all active & inactive patterns from SourcererDataView['title']
*/
patternList: string[];
/**
* @deprecated use sourcererDataView.title or sourcererDataView.matchedIndices
* all selected patterns from SourcererScope['selectedPatterns'] */
/* all selected patterns from SourcererScope['selectedPatterns'] */
selectedPatterns: SourcererScope['selectedPatterns'];
/**
* @deprecated use sourcererDataView.title or sourcererDataView.matchedIndices
* active patterns when dataViewId == null
*/
activePatterns?: string[];

/**
* Easier to add this additional data rather than
* try to extend the SelectedDataView type from DataView.
Expand Down

0 comments on commit d1c4bb3

Please sign in to comment.