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] Unified Timeline - Fix Flaky tests #184747

Merged
merged 28 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
720efb5
tests: fix flaky tests
logeekal Jun 4, 2024
10c66ce
fix: tab type
logeekal Jun 4, 2024
f617707
remove flaky comments
logeekal Jun 4, 2024
04b5f4e
fix: timeline leading actions
logeekal Jun 5, 2024
9856913
fix: tests
logeekal Jun 5, 2024
801fc86
fix: remove unnecesary statements
logeekal Jun 5, 2024
80212c9
fix: types
logeekal Jun 5, 2024
a716414
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 5, 2024
7af55bb
fix: tests
logeekal Jun 6, 2024
c7ade85
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 6, 2024
a35c73e
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 6, 2024
5e0ee45
fix: cypress tests + unskipping
logeekal Jun 7, 2024
f4645fe
chore: 💅
logeekal Jun 7, 2024
8fa089b
fix: tests beforeEach + cypress
logeekal Jun 10, 2024
da9c1f9
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 10, 2024
7cb73af
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 10, 2024
db85502
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 10, 2024
d228d19
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 10, 2024
3dc48e3
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 11, 2024
eba7e5a
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 11, 2024
b7a098e
fix: more tests
logeekal Jun 11, 2024
720db4b
temporary: change for flaky test runner
logeekal Jun 12, 2024
f0641a0
fix: flaky test fix
logeekal Jun 13, 2024
c01bfbf
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 13, 2024
bdeffad
fix: revert flaky test runner command
logeekal Jun 13, 2024
3df6826
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 17, 2024
c3ecfe0
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 17, 2024
f93b1ba
Merge branch 'main' into test/fix_flaky_tests
logeekal Jun 17, 2024
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 @@ -19,7 +19,9 @@ import React, { memo, useEffect } from 'react';
*
* */
export const getCustomCellPopoverRenderer = () => {
return memo(function RenderCustomCellPopover(props: EuiDataGridCellPopoverElementProps) {
const RenderCustomCellPopoverMemoized = memo(function RenderCustomCellPopoverMemoized(
logeekal marked this conversation as resolved.
Show resolved Hide resolved
props: EuiDataGridCellPopoverElementProps
) {
const { setCellPopoverProps, DefaultCellPopover } = props;

useEffect(() => {
Expand All @@ -30,4 +32,10 @@ export const getCustomCellPopoverRenderer = () => {

return <DefaultCellPopover {...props} />;
});

// Components passed to EUI DataGrid cannot be memoized components
// otherwise EUI throws an error `typeof Component !== 'function'`
return (props: EuiDataGridCellPopoverElementProps) => (
<RenderCustomCellPopoverMemoized {...props} />
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { memo, useEffect, useContext } from 'react';
import React, { useEffect, useContext } from 'react';
import { i18n } from '@kbn/i18n';
import type { DataView, DataViewField } from '@kbn/data-views-plugin/public';
import {
Expand Down Expand Up @@ -47,10 +47,7 @@ export const getRenderCellValueFn = ({
externalCustomRenderers?: CustomCellRenderer;
isPlainRecord?: boolean;
}) => {
/**
* memo is imperative here otherwise the cell will re-render on every hover on every cell
*/
return memo(function UnifiedDataTableRenderCellValue({
return function UnifiedDataTableRenderCellValue({
Copy link
Contributor Author

@logeekal logeekal Jun 5, 2024

Choose a reason for hiding this comment

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

Note

Had to remove memo here because EUI fails the unit tests when a memoized components is passed to the Data Grid with error that typeof renderCellValue !== 'function'

Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, is the named function here just to help with debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes exactly. Otherwise, it appears as Anonymous in React Dev tools. Not other reason.

rowIndex,
columnId,
isDetails,
Expand Down Expand Up @@ -149,7 +146,7 @@ export const getRenderCellValueFn = ({
}}
/>
);
});
};
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { EuiButtonIcon, EuiToolTip } from '@elastic/eui';
import styled from 'styled-components';

import { TimelineTabs, TableId } from '@kbn/securitysolution-data-table';
import { selectTimelineById } from '../../../timelines/store/selectors';
import {
eventHasNotes,
getEventType,
getPinOnClick,
} from '../../../timelines/components/timeline/body/helpers';
import { getScopedActions, isTimelineScope } from '../../../helpers';
import { useIsInvestigateInResolverActionEnabled } from '../../../detections/components/alerts_table/timeline_actions/investigate_in_resolver';
import { timelineActions, timelineSelectors } from '../../../timelines/store';
import { timelineActions } from '../../../timelines/store';
import type { ActionProps, OnPinEvent } from '../../../../common/types';
import { TimelineId } from '../../../../common/types';
import { AddEventNoteAction } from './add_note_icon_item';
Expand Down Expand Up @@ -66,11 +67,10 @@ const ActionsComponent: React.FC<ActionProps> = ({
'unifiedComponentsInTimelineEnabled'
);
const emptyNotes: string[] = [];
const getTimeline = useMemo(() => timelineSelectors.getTimelineByIdSelector(), []);
const timelineType = useShallowEqualSelector(
(state) =>
(isTimelineScope(timelineId) ? getTimeline(state, timelineId) : timelineDefaults).timelineType
const { timelineType } = useShallowEqualSelector((state) =>
isTimelineScope(timelineId) ? selectTimelineById(state, timelineId) : timelineDefaults
);

const { startTransaction } = useStartTransaction();

const isEnterprisePlus = useLicense().isEnterprise();
Expand Down Expand Up @@ -213,8 +213,8 @@ const ActionsComponent: React.FC<ActionProps> = ({
onEventDetailsPanelOpened();
}, [activeStep, incrementStep, isTourAnchor, isTourShown, onEventDetailsPanelOpened]);
const showExpandEvent = useMemo(
() => !unifiedComponentsInTimelineEnabled || isEventViewer || timelineId !== TimelineId.active,
[isEventViewer, timelineId, unifiedComponentsInTimelineEnabled]
() => !unifiedComponentsInTimelineEnabled || isEventViewer,
[isEventViewer, unifiedComponentsInTimelineEnabled]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import { TimelineTabs, TimelineId } from '../../../../common/types';
import { isFullScreen } from '../../../timelines/components/timeline/body/column_headers';
import { isActiveTimeline } from '../../../helpers';
import { getColumnHeader } from '../../../timelines/components/timeline/body/column_headers/helpers';
import { timelineActions, timelineSelectors } from '../../../timelines/store';
import { useDeepEqualSelector } from '../../hooks/use_selector';
import { timelineActions } from '../../../timelines/store';
import { useGlobalFullScreen, useTimelineFullScreen } from '../../containers/use_full_screen';
import { useKibana } from '../../lib/kibana';
import { DEFAULT_ACTION_BUTTON_WIDTH } from '.';
Expand All @@ -27,6 +26,8 @@ import { EXIT_FULL_SCREEN } from '../exit_full_screen/translations';
import { EventsSelect } from '../../../timelines/components/timeline/body/column_headers/events_select';
import * as i18n from './translations';
import { useIsExperimentalFeatureEnabled } from '../../hooks/use_experimental_features';
import { useDeepEqualSelector } from '../../hooks/use_selector';
import { selectTimelineById } from '../../../timelines/store/selectors';

const SortingColumnsContainer = styled.div`
button {
Expand Down Expand Up @@ -90,14 +91,14 @@ const HeaderActionsComponent: React.FC<HeaderActionProps> = memo(
const { timelineFullScreen, setTimelineFullScreen } = useTimelineFullScreen();
const dispatch = useDispatch();

const getManageTimeline = useMemo(() => timelineSelectors.getTimelineByIdSelector(), []);
const { defaultColumns } = useDeepEqualSelector((state) =>
getManageTimeline(state, timelineId)
);
const unifiedComponentsInTimelineEnabled = useIsExperimentalFeatureEnabled(
'unifiedComponentsInTimelineEnabled'
);

const { defaultColumns } = useDeepEqualSelector((state) =>
selectTimelineById(state, timelineId)
);

const toggleFullScreen = useCallback(() => {
if (timelineId === TimelineId.active) {
setTimelineFullScreen(!timelineFullScreen);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ const AlertContextMenuComponent: React.FC<AlertContextMenuProps> = ({
refetchQuery([timelineQuery]);
} else {
refetchQuery(globalQuery);
if (refetch) refetch();
}

if (refetch) refetch();
janmonschke marked this conversation as resolved.
Show resolved Hide resolved
}, [scopeId, globalQuery, timelineQuery, refetch]);

const ruleIndex =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@ describe('EventColumnView', () => {
});

test('it renders correct tooltip for NotesButton - timeline template', () => {
(useShallowEqualSelector as jest.Mock).mockReturnValue(TimelineType.template);
(useShallowEqualSelector as jest.Mock).mockReturnValue({
timelineType: TimelineType.template,
});

const wrapper = mount(<EventColumnView {...props} />, { wrappingComponent: TestProviders });

expect(wrapper.find('[data-test-subj="add-note"]').prop('toolTip')).toEqual(
NOTES_DISABLE_TOOLTIP
);
(useShallowEqualSelector as jest.Mock).mockReturnValue(TimelineType.default);
(useShallowEqualSelector as jest.Mock).mockReturnValue({ timelineType: TimelineType.default });
});

test('it does NOT render a pin button when isEventViewer is true', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const defaultProps: UnifiedTimelineBodyProps = {
activePage: 0,
querySize: 0,
},
eventIdToNoteIds: {} as Record<string, string[]>,
pinnedEventIds: {} as Record<string, boolean>,
};

const renderTestComponents = (props?: UnifiedTimelineBodyProps) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ export const EqlTabContentComponent: React.FC<Props> = ({
} = useSourcererDataView(SourcererScopeName.timeline);
const { augmentedColumnHeaders, timelineQueryFieldsFromColumns } = useTimelineColumns(columns);

const leadingControlColumns = useTimelineControlColumn(columns, TIMELINE_NO_SORTING);

const unifiedComponentsInTimelineEnabled = useIsExperimentalFeatureEnabled(
'unifiedComponentsInTimelineEnabled'
);
Expand Down Expand Up @@ -137,6 +135,14 @@ export const EqlTabContentComponent: React.FC<Props> = ({
timerangeKind,
});

const leadingControlColumns = useTimelineControlColumn({
columns,
sort: TIMELINE_NO_SORTING,
timelineId,
activeTab: TimelineTabs.eql,
refetch,
});

const isQueryLoading = useMemo(
() =>
dataLoadingState === DataLoadingState.loading ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ export const PinnedTabContentComponent: React.FC<Props> = ({
timerangeKind: undefined,
});

const leadingControlColumns = useTimelineControlColumn(columns, sort);
const leadingControlColumns = useTimelineControlColumn({
columns,
sort,
timelineId,
activeTab: TimelineTabs.pinned,
refetch,
});

const isQueryLoading = useMemo(
() => [DataLoadingState.loading, DataLoadingState.loadingMore].includes(queryLoadingState),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ export const QueryTabContentComponent: React.FC<Props> = ({
timerangeKind,
});

const leadingControlColumns = useTimelineControlColumn(columns, sort);
const leadingControlColumns = useTimelineControlColumn({
columns,
sort,
timelineId,
activeTab: TimelineTabs.query,
refetch,
});

useEffect(() => {
dispatch(
Expand Down
Loading