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

Disable esql on serverless #7

Closed
wants to merge 85 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
ed21335
fix: saved search incremental
logeekal Aug 23, 2023
c2dce33
incremental save
logeekal Aug 28, 2023
b1760e0
incremental save with timeline savedSearchId server
logeekal Aug 31, 2023
1268184
feat: saved search working + cypress
logeekal Sep 4, 2023
9d47ec0
fix: removed unnecessary changes
logeekal Sep 4, 2023
46389bc
fix types
logeekal Sep 4, 2023
0477eab
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Sep 4, 2023
28c82c5
Merge branch 'main' into feat/saved_search
logeekal Sep 4, 2023
0f3c9f3
Merge branch 'main' into feat/saved_search
logeekal Sep 4, 2023
62ac64c
fix: optimization
logeekal Sep 4, 2023
df9b099
fix: add cypress+ unit tests
logeekal Sep 5, 2023
6341631
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 5, 2023
06c77f7
fix: jest tests
logeekal Sep 5, 2023
5ee7334
Merge branch 'main' into feat/saved_search
logeekal Sep 5, 2023
1bda7ce
fix: mocks and tests
logeekal Sep 6, 2023
f7515a9
fix: tests
logeekal Sep 6, 2023
790a9dc
refactor: tests + logic
logeekal Sep 6, 2023
3cd9459
fix:types
logeekal Sep 6, 2023
caf2f3e
Merge branch 'main' into feat/saved_search
logeekal Sep 6, 2023
b8b7ff3
skip tests in error
logeekal Sep 6, 2023
7e1cb25
fix: cypress tags
logeekal Sep 6, 2023
c322fcd
fix: more experiments with cypress tags
logeekal Sep 6, 2023
2591802
cypress tags fix retry
logeekal Sep 6, 2023
a0e1309
skip complete suite in serverless
logeekal Sep 6, 2023
b8e5cd5
remove serverless tag
logeekal Sep 6, 2023
c91280e
skipped test becuase of failure in serverless
logeekal Sep 6, 2023
42c52e6
Merge branch 'main' into feat/saved_search
logeekal Sep 7, 2023
c9188ea
tests: discover mock + tests
logeekal Sep 7, 2023
9bd3fc7
fix: test format
logeekal Sep 7, 2023
afcb9c5
change resetAllMocks 👉🏽 clrAllMocks
logeekal Sep 7, 2023
be44ae3
chang more unncessary resetAllMocks 👉🏽 earAllMocks
logeekal Sep 7, 2023
6b036e9
Merge branch 'main' into feat/saved_search
kibanamachine Sep 12, 2023
2f706ca
Merge branch 'main' into feat/saved_search
michaelolo24 Sep 13, 2023
3594c2b
fix: saved search incremental
logeekal Aug 23, 2023
d13ce0b
pr feedback updates and fix autosave
michaelolo24 Sep 13, 2023
2435c61
additional pr feedback
michaelolo24 Sep 13, 2023
880a0ca
Merge branch 'main' into feat/saved_search
michaelolo24 Sep 19, 2023
7601d7d
ESQL tab in ess
michaelolo24 Sep 20, 2023
1582182
proper check for esql
michaelolo24 Sep 20, 2023
85c07df
fix serverless check
michaelolo24 Sep 20, 2023
3fe13fd
fix: timeline state restore when refreshing the page
logeekal Sep 26, 2023
43034c3
fix: search source fields
logeekal Sep 26, 2023
d0096fc
fix: null saved search
logeekal Sep 26, 2023
71169e5
removed focused test pragma
logeekal Sep 26, 2023
d743146
Merged main -> current branch
logeekal Sep 26, 2023
c439875
remove timeline loading check
michaelolo24 Sep 26, 2023
3fe85bf
remove autosave trigger
michaelolo24 Sep 26, 2023
6293c62
revert changes
michaelolo24 Sep 26, 2023
c0263ca
add extra line
michaelolo24 Sep 26, 2023
a393ff3
Merge branch 'feat/saved_search' into update-discover-saved-search-work
michaelolo24 Sep 26, 2023
6993479
fix jest tests
logeekal Sep 26, 2023
e99dc7d
Merge pull request #2 from michaelolo24/update-discover-saved-search-…
logeekal Sep 26, 2023
76e6137
Merge branch 'main' into feat/saved_search
logeekal Sep 26, 2023
9eb6c54
Merge branch 'feat/saved_search' into discover-esql-in-timeline
michaelolo24 Sep 26, 2023
1c0f60b
Merge branch 'main' into discover-esql-in-timeline
michaelolo24 Sep 26, 2023
e0216db
fix: review feedback
logeekal Sep 27, 2023
95d0bf3
fix loading saved esql query
michaelolo24 Sep 27, 2023
cf3e321
Merge branch 'feat/saved_search' into discover-esql-in-timeline
michaelolo24 Sep 27, 2023
c19066d
default to esql only behind feature flag
michaelolo24 Sep 27, 2023
84ce40c
default to esql only behind feature flag
michaelolo24 Sep 27, 2023
163c8ab
working on cypress tests
michaelolo24 Sep 27, 2023
778b6b8
default experimental features to true
michaelolo24 Sep 28, 2023
3811e4e
Merge remote-tracking branch 'upstream/main' into discover-esql-in-ti…
michaelolo24 Sep 29, 2023
5b517f8
fix: set esql default state
logeekal Sep 29, 2023
b1a42a4
fix: initial load ES|QL default state
logeekal Sep 29, 2023
b231d3b
ESQL cypress updates WIP
michaelolo24 Sep 29, 2023
d090ce1
fix: cypress tests
logeekal Sep 29, 2023
a0e2398
remove unused const
michaelolo24 Sep 29, 2023
214b88b
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Sep 29, 2023
fc63b67
fix test util, add tech preview badge, hide dataview selector
michaelolo24 Oct 1, 2023
f340b0c
Merge remote-tracking branch 'upstream/main' into discover-esql-in-ti…
michaelolo24 Oct 1, 2023
e454566
add missing boolean check and fix test mocks
michaelolo24 Oct 1, 2023
339d769
check for underlying OS
michaelolo24 Oct 1, 2023
b71f48f
Merge remote-tracking branch 'upstream/main' into discover-esql-in-ti…
michaelolo24 Oct 1, 2023
9c06546
Add check for test and add unit test
michaelolo24 Oct 1, 2023
73b23a2
Make prop optional
michaelolo24 Oct 1, 2023
1f4cd68
fix flakyness
michaelolo24 Oct 2, 2023
1a7b1f6
Fix type check, cypress should only run in ess
michaelolo24 Oct 2, 2023
fca4502
Fix mock and add default index pattern
michaelolo24 Oct 2, 2023
75a8e7b
Use empty string instead
michaelolo24 Oct 2, 2023
a747406
remove optional chaining
michaelolo24 Oct 2, 2023
f631893
Merge remote-tracking branch 'upstream/main' into discover-esql-in-ti…
michaelolo24 Oct 2, 2023
f475d93
disable timeline esql tab on serverless
michaelolo24 Oct 2, 2023
b8fa059
Merge remote-tracking branch 'upstream/main' into discover-esql-in-ti…
michaelolo24 Oct 2, 2023
4cfa26b
Merge branch 'discover-esql-in-timeline' into disable-esql-on-serverless
michaelolo24 Oct 2, 2023
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
1 change: 0 additions & 1 deletion config/serverless.security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ xpack.fleet.internal.registry.spec.max: '3.0'

# Serverless security specific options
xpack.securitySolution.enableExperimental:
- discoverInTimeline
- esqlRulesDisabled

xpack.ml.ad.enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const mockSearchBarCustomizationWithCustomSearchBar: SearchBarCustomization = {
CustomSearchBar: MockCustomSearchBar,
};

const mockSearchBarCustomizationWithHiddenDataViewPicker: SearchBarCustomization = {
id: 'search_bar',
hideDataViewPicker: true,
};

let mockUseCustomizations = false;

jest.mock('../../../../customizations', () => ({
Expand Down Expand Up @@ -256,5 +261,23 @@ describe('Discover topnav component', () => {
).find(mockSearchBarCustomization.CustomDataViewPicker!);
expect(dataViewPickerOverride.length).toBe(1);
});

it('should not render the dataView picker when hideDataViewPicker is true', () => {
(useDiscoverCustomization as jest.Mock).mockImplementation((id: DiscoverCustomizationId) => {
if (id === 'search_bar') {
return mockSearchBarCustomizationWithHiddenDataViewPicker;
}
});

const props = getProps();
const component = mountWithIntl(
<DiscoverMainProvider value={props.stateContainer}>
<DiscoverTopNav {...props} />
</DiscoverMainProvider>
);

const topNav = component.find(mockDiscoverService.navigation.ui.AggregateQueryTopNavMenu);
expect(topNav.prop('dataViewPickerComponentProps')).toBeUndefined();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const DiscoverTopNav = ({
}, [dataViewEditor, stateContainer]);

const topNavCustomization = useDiscoverCustomization('top_nav');

const topNavMenu = useMemo(
() =>
getTopNavLinks({
Expand Down Expand Up @@ -171,6 +172,17 @@ export const DiscoverTopNav = ({
if (isESQLModeEnabled) {
supportedTextBasedLanguages.push('ESQL');
}

const searchBarCustomization = useDiscoverCustomization('search_bar');

const SearchBar = useMemo(
() => searchBarCustomization?.CustomSearchBar ?? AggregateQueryTopNavMenu,
[searchBarCustomization?.CustomSearchBar, AggregateQueryTopNavMenu]
);

const shouldHideDefaultDataviewPicker =
!!searchBarCustomization?.CustomDataViewPicker || !!searchBarCustomization?.hideDataViewPicker;

const dataViewPickerProps: DataViewPickerProps = {
trigger: {
label: dataView?.getName() || '',
Expand Down Expand Up @@ -201,13 +213,6 @@ export const DiscoverTopNav = ({
[services, stateContainer]
);

const searchBarCustomization = useDiscoverCustomization('search_bar');

const SearchBar = useMemo(
() => searchBarCustomization?.CustomSearchBar ?? AggregateQueryTopNavMenu,
[searchBarCustomization?.CustomSearchBar, AggregateQueryTopNavMenu]
);

return (
<SearchBar
appName="discover"
Expand All @@ -231,7 +236,7 @@ export const DiscoverTopNav = ({
) : undefined
}
dataViewPickerComponentProps={
searchBarCustomization?.CustomDataViewPicker ? undefined : dataViewPickerProps
shouldHideDefaultDataviewPicker ? undefined : dataViewPickerProps
}
displayStyle="detached"
textBasedLanguageModeErrors={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export interface SearchBarCustomization {
CustomDataViewPicker?: ComponentType;
PrependFilterBar?: ComponentType;
CustomSearchBar?: ComponentType<TopNavMenuProps<AggregateQuery>>;
hideDataViewPicker?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ export const allowedExperimentalValues = Object.freeze({
* Enables experimental Entity Analytics HTTP endpoints
*/
riskScoringRoutesEnabled: false,
/*
*
* Enables Discover embedded within timeline
*
* */
discoverInTimeline: false,

/**
* disables ES|QL rules
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@

export const useDiscoverInTimelineActions = () => {
return {
resetDiscoverAppState: jest.fn(),
resetDiscoverAppState: jest.fn().mockResolvedValue(true),
restoreDiscoverAppStateFromSavedSearch: jest.fn(),
updateSavedSearch: jest.fn(),
getAppStateFromSavedSearch: jest.fn(),
defaultDiscoverAppState: {
getDefaultDiscoverAppState: () => ({
query: {
query: '',
language: 'kuery',
language: 'esql',
},
sort: [['@timestamp', 'desc']],
columns: [],
index: 'security-solution-default',
interval: 'auto',
filters: [],
hideChart: true,
hideChart: false,
grid: {},
},
}),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ import { createStore } from '../../store';
import { TimelineId } from '../../../../common/types';
import type { ComponentType, FC, PropsWithChildren } from 'react';
import React from 'react';
import type { DataView } from '@kbn/data-views-plugin/common';
import TestRenderer from 'react-test-renderer';

const mockDiscoverStateContainerRef = {
const { act } = TestRenderer;

let mockDiscoverStateContainerRef = {
current: discoverPluginMock.getDiscoverStateMock({}),
};

Expand Down Expand Up @@ -64,6 +68,9 @@ const getTestProviderWithCustomState = (state: State = mockState) => {
};

const renderTestHook = (customWrapper: ComponentType = getTestProviderWithCustomState()) => {
mockDiscoverStateContainerRef = {
current: discoverPluginMock.getDiscoverStateMock({}),
};
return renderHook(() => useDiscoverInTimelineActions(mockDiscoverStateContainerRef), {
wrapper: customWrapper,
});
Expand Down Expand Up @@ -120,6 +127,13 @@ export const savedSearchMock = {

const startServicesMock = createStartServicesMock();

startServicesMock.dataViews.get = jest.fn(
async () =>
({
getIndexPattern: jest.fn(),
} as unknown as DataView)
);

describe('useDiscoverInTimelineActions', () => {
beforeEach(() => {
(useKibana as jest.Mock).mockImplementation(() => ({
Expand Down Expand Up @@ -188,15 +202,15 @@ describe('useDiscoverInTimelineActions', () => {
describe('resetDiscoverAppState', () => {
it('should reset Discover AppState to a default state', async () => {
const { result, waitFor } = renderTestHook();
result.current.resetDiscoverAppState();
await result.current.resetDiscoverAppState();
await waitFor(() => {
const appState = mockDiscoverStateContainerRef.current.appState.getState();
expect(appState).toMatchObject(result.current.defaultDiscoverAppState);
expect(appState).toMatchObject(result.current.getDefaultDiscoverAppState());
});
});
it('should reset Discover time to a default state', async () => {
const { result, waitFor } = renderTestHook();
result.current.resetDiscoverAppState();
await result.current.resetDiscoverAppState();
await waitFor(() => {
const globalState = mockDiscoverStateContainerRef.current.globalState.get();
expect(globalState).toMatchObject({ time: { from: 'now-15m', to: 'now' } });
Expand All @@ -206,7 +220,9 @@ describe('useDiscoverInTimelineActions', () => {
describe('updateSavedSearch', () => {
it('should add defaults to the savedSearch before updating saved search', async () => {
const { result } = renderTestHook();
await result.current.updateSavedSearch(savedSearchMock, TimelineId.active);
await act(async () => {
await result.current.updateSavedSearch(savedSearchMock, TimelineId.active);
});

expect(startServicesMock.savedSearch.save).toHaveBeenNthCalledWith(
1,
Expand Down Expand Up @@ -242,7 +258,9 @@ describe('useDiscoverInTimelineActions', () => {

const LocalTestProvider = getTestProviderWithCustomState(localMockState);
const { result } = renderTestHook(LocalTestProvider);
await result.current.updateSavedSearch(savedSearchMock, TimelineId.active);
await act(async () => {
await result.current.updateSavedSearch(savedSearchMock, TimelineId.active);
});

expect(startServicesMock.savedSearch.save).toHaveBeenNthCalledWith(
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export const useDiscoverInTimelineActions = (
const { addError } = useAppToasts();

const {
services: { customDataService: discoverDataService, savedSearch: savedSearchService },
services: {
customDataService: discoverDataService,
savedSearch: savedSearchService,
dataViews: dataViewService,
},
} = useKibana();

const dispatch = useDispatch();
Expand Down Expand Up @@ -69,18 +73,23 @@ export const useDiscoverInTimelineActions = (
},
});

const defaultDiscoverAppState: DiscoverAppState = useMemo(() => {
const getDefaultDiscoverAppState: () => Promise<DiscoverAppState> = useCallback(async () => {
const localDataViewId = dataViewId ?? 'security-solution-default';

const dataView = await dataViewService.get(localDataViewId);

return {
query: discoverDataService.query.queryString.getDefaultQuery(),
query: {
esql: dataView ? `from ${dataView.getIndexPattern()} | limit 10` : '',
},
sort: [['@timestamp', 'desc']],
columns: [],
index: dataViewId ?? 'security-solution-default',
interval: 'auto',
filters: [],
hideChart: true,
grid: {},
};
}, [discoverDataService, dataViewId]);
}, [dataViewService, dataViewId]);

/*
* generates Appstate from a given saved Search object
Expand Down Expand Up @@ -123,13 +132,14 @@ export const useDiscoverInTimelineActions = (
* resets discover state to a default value
*
* */
const resetDiscoverAppState = useCallback(() => {
const resetDiscoverAppState = useCallback(async () => {
const defaultDiscoverAppState = await getDefaultDiscoverAppState();
discoverStateContainer.current?.appState.set(defaultDiscoverAppState);
discoverStateContainer.current?.globalState.set({
...discoverStateContainer.current?.globalState.get(),
time: defaultDiscoverTimeRange,
});
}, [defaultDiscoverAppState, discoverStateContainer]);
}, [getDefaultDiscoverAppState, discoverStateContainer]);

const persistSavedSearch = useCallback(
async (savedSearch: SavedSearch, savedSearchOption: SaveSavedSearchOptions) => {
Expand Down Expand Up @@ -220,14 +230,14 @@ export const useDiscoverInTimelineActions = (
restoreDiscoverAppStateFromSavedSearch,
updateSavedSearch,
getAppStateFromSavedSearch,
defaultDiscoverAppState,
getDefaultDiscoverAppState,
}),
[
resetDiscoverAppState,
restoreDiscoverAppStateFromSavedSearch,
updateSavedSearch,
getAppStateFromSavedSearch,
defaultDiscoverAppState,
getDefaultDiscoverAppState,
]
);

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/security_solution/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export const contractStartServicesMock: ContractStartServices = {
getComponent$: jest.fn(),
upselling,
dataQualityPanelConfig: undefined,
timelineConfig: undefined,
};

const setupMock = (): PluginSetup => ({
resolver: jest.fn(),
setAppLinksSwitcher: jest.fn(),
setDataQualityPanelConfig: jest.fn(),
setTimelineConfig: jest.fn(),
});

const startMock = (): PluginStart => ({
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/security_solution/public/overview/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
export interface DataQualityPanelConfig {
isILMAvailable: boolean;
}

export interface TimelineConfig {
esqlEnabled: boolean;
}
7 changes: 6 additions & 1 deletion x-pack/plugins/security_solution/public/plugin_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BehaviorSubject } from 'rxjs';
import type { RouteProps } from 'react-router-dom';
import { UpsellingService } from '@kbn/security-solution-upselling/service';
import type { ContractStartServices, PluginSetup, PluginStart } from './types';
import type { DataQualityPanelConfig } from './overview/types';
import type { DataQualityPanelConfig, TimelineConfig } from './overview/types';
import type { AppLinksSwitcher } from './common/links';
import { navLinks$ } from './common/links/nav_links';
import { breadcrumbsNav$ } from './common/breadcrumbs';
Expand All @@ -22,6 +22,7 @@ export class PluginContract {
public extraRoutes$: BehaviorSubject<RouteProps[]>;
public appLinksSwitcher: AppLinksSwitcher;
public dataQualityPanelConfig?: DataQualityPanelConfig;
public timelineConfig?: TimelineConfig;

constructor() {
this.extraRoutes$ = new BehaviorSubject<RouteProps[]>([]);
Expand All @@ -38,6 +39,7 @@ export class PluginContract {
getComponent$: this.componentsService.getComponent$.bind(this.componentsService),
upselling: this.upsellingService,
dataQualityPanelConfig: this.dataQualityPanelConfig,
timelineConfig: this.timelineConfig,
};
}

Expand All @@ -50,6 +52,9 @@ export class PluginContract {
setDataQualityPanelConfig: (dataQualityPanelConfig) => {
this.dataQualityPanelConfig = dataQualityPanelConfig;
},
setTimelineConfig: (timelineConfig) => {
this.timelineConfig = timelineConfig;
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const useSearchBarCustomizations = () => {
customizations.set({
id: 'search_bar',
CustomSearchBar: CustomStatefulTopNavKqlQueryBar,
hideDataViewPicker: true,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useSearchBarCustomizations } from './use_search_bar_customizations';

export const useSetDiscoverCustomizationCallbacks = (): CustomizationCallback[] => {
const searchBarCustomizationCallback = useSearchBarCustomizations();

const histogramCustomizationCallback = useHistogramCustomization();

return [searchBarCustomizationCallback, histogramCustomizationCallback];
Expand Down
Loading
Loading