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

[SecuritySolution] Render histograms with Lens #147261

Merged
merged 108 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
62bd659
render histogram with lens
angorayc Dec 8, 2022
6376733
replace alert histograms with lens
angorayc Dec 16, 2022
7b39762
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Dec 16, 2022
b68afd1
replace alerts histograms with Lens
angorayc Dec 20, 2022
5f5291d
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Dec 20, 2022
84dce3f
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Dec 20, 2022
a07eefe
extra actions
angorayc Dec 20, 2022
0b18236
Merge branch 'histogram-with-lens' of github.com:angorayc/kibana into…
angorayc Dec 20, 2022
73424d7
add no data prompt
angorayc Dec 21, 2022
5fc4ece
fix types
angorayc Dec 21, 2022
761998f
fix unit tests
angorayc Dec 22, 2022
445cb99
clean up
angorayc Dec 22, 2022
26da70b
update events chart
angorayc Dec 22, 2022
da58b26
rename props
angorayc Dec 22, 2022
153f139
add unit tests
angorayc Dec 22, 2022
55f0cf2
update snapshots
angorayc Dec 22, 2022
1b50b16
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Dec 22, 2022
7dbc50d
add unit tests
angorayc Dec 23, 2022
c31b77d
fix unit tests
angorayc Dec 28, 2022
785712e
replace alerts donut charts
angorayc Dec 29, 2022
c753bd8
add total alerts count
angorayc Dec 30, 2022
dfb9e8f
render rule preview with lens
angorayc Jan 3, 2023
789c0c8
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Jan 3, 2023
73e17de
pass extra filters to Lens
angorayc Jan 3, 2023
1c5febb
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Jan 3, 2023
1c18042
styling
angorayc Jan 5, 2023
29da009
fix types
angorayc Jan 5, 2023
a91bf4f
update snapshot
angorayc Jan 5, 2023
aead88e
Merge branch 'histogram-with-lens' of github.com:angorayc/kibana into…
angorayc Jan 5, 2023
4d4a5cf
update snapshot
angorayc Jan 5, 2023
075ef5f
styling
angorayc Jan 5, 2023
d619b30
unit tests
angorayc Jan 7, 2023
d896cb0
remove eslint comment
angorayc Jan 7, 2023
82b4ddb
refetch
angorayc Jan 7, 2023
d2023fa
fetch session id only when vis inabled
angorayc Jan 7, 2023
0891f07
unit test
angorayc Jan 7, 2023
119dbe7
fix types
angorayc Jan 8, 2023
772fb17
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Jan 8, 2023
010f93b
render histogram with lens
angorayc Dec 8, 2022
f5cb4e0
Merge branch 'histogram-with-lens' of github.com:angorayc/kibana into…
angorayc Jan 10, 2023
076d60d
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Jan 10, 2023
e0bdf32
replace donut on alerts page
angorayc Jan 10, 2023
a1464c2
Merge branch 'histogram-with-lens' of github.com:angorayc/kibana into…
angorayc Jan 10, 2023
fc3b886
replace alerts by severity table with lens
angorayc Jan 10, 2023
6a01c57
Merge branch 'histogram-with-lens' of github.com:angorayc/kibana into…
angorayc Jan 10, 2023
a2c4cbc
replace donut charts for risk scores
angorayc Jan 11, 2023
c303846
fix index nout found warning
angorayc Jan 12, 2023
d57eac4
Merge branch 'main' of github.com:elastic/kibana into riskscore-donut
angorayc Jan 12, 2023
0284f43
sync with main
angorayc Jan 12, 2023
0ac2d88
fix eslint
angorayc Jan 12, 2023
56714cc
add unit tests
angorayc Jan 13, 2023
b949db5
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Jan 13, 2023
11507be
update configs
angorayc Jan 13, 2023
bd2b23c
Merge branch 'riskscore-donut' of github.com:angorayc/kibana into ris…
angorayc Jan 13, 2023
e0ff503
Merge branch 'main' into riskscore-donut
angorayc Jan 15, 2023
11dd2b0
an option to not apply global queries and filters
angorayc Jan 16, 2023
1bacbd2
Merge branch 'riskscore-donut' of github.com:angorayc/kibana into ris…
angorayc Jan 16, 2023
04b0bbc
update snapshot
angorayc Jan 16, 2023
027c8af
Merge branch 'riskscore-donut' of github.com:angorayc/kibana into his…
angorayc Jan 16, 2023
a5712f7
sync up with main
angorayc Jan 16, 2023
0019fea
fix unit tests
angorayc Jan 16, 2023
29545fd
unit tests
angorayc Jan 17, 2023
cc768f2
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Jan 17, 2023
b6013bb
Merge branch 'main' into histogram-with-lens
angorayc Jan 17, 2023
a3a9f7a
Merge branch 'histogram-with-lens' of github.com:angorayc/kibana into…
angorayc Jan 17, 2023
811719e
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Jan 23, 2023
4b6677c
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Jan 23, 2023
374f652
review
angorayc Jan 24, 2023
8d39e19
Merge branch 'main' into histogram-with-lens
angorayc Jan 24, 2023
981499e
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Jan 25, 2023
08858ce
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 25, 2023
c45a535
fix types
angorayc Jan 25, 2023
af0ffa6
Merge branch 'histogram-with-lens' of github.com:angorayc/kibana into…
angorayc Jan 25, 2023
b54143b
review
angorayc Jan 25, 2023
19726bc
move legend to the left side
angorayc Jan 26, 2023
b65787c
disable chart actions for rule previews
angorayc Jan 26, 2023
609bf6c
revert alert treemap and chart
angorayc Jan 26, 2023
0b03c88
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Jan 26, 2023
23878fa
revert change
angorayc Jan 26, 2023
47ae44b
revert changes
angorayc Jan 26, 2023
d75d3e7
revert changes
angorayc Jan 26, 2023
73c559c
revert changes
angorayc Jan 26, 2023
1bedc1c
Merge branch 'main' into histogram-with-lens
angorayc Jan 26, 2023
d81d136
page crashes when deleting group by field
angorayc Jan 27, 2023
9ae3379
check estypes for stackByFields
angorayc Jan 30, 2023
d075afb
Merge branch 'main' of github.com:elastic/kibana into histogram-with-…
angorayc Jan 30, 2023
7f215e4
use extra large space for alerts trend legend
angorayc Jan 30, 2023
62e7195
Merge branch 'main' into histogram-with-lens
angorayc Jan 30, 2023
8404d7b
refetch
angorayc Jan 31, 2023
ef18579
unit test
angorayc Jan 31, 2023
8edc08e
Merge branch 'main' into histogram-with-lens
angorayc Feb 1, 2023
71e0bde
Merge branch 'main' into histogram-with-lens
angorayc Feb 1, 2023
f5d9e5a
review
angorayc Feb 1, 2023
78d214a
Merge branch 'histogram-with-lens' of github.com:angorayc/kibana into…
angorayc Feb 1, 2023
1449be9
update event histogram's configs
angorayc Feb 1, 2023
151a317
typo
angorayc Feb 1, 2023
f6fecc3
lint
angorayc Feb 1, 2023
0b30b7a
Merge branch 'main' into histogram-with-lens
angorayc Feb 1, 2023
e949a18
handle timerange update when indices nout found
angorayc Feb 1, 2023
d7780eb
Merge branch 'histogram-with-lens' of github.com:angorayc/kibana into…
angorayc Feb 1, 2023
ea59f99
clear sessions before leaving security
angorayc Feb 1, 2023
913d470
code review
angorayc Feb 1, 2023
84f4c4b
put back missing props
angorayc Feb 1, 2023
88a102a
Merge branch 'main' into histogram-with-lens
angorayc Feb 1, 2023
62faf0f
Merge branch 'main' into histogram-with-lens
angorayc Feb 2, 2023
107c6e4
Merge branch 'main' into histogram-with-lens
angorayc Feb 2, 2023
11f18e8
block nested types
angorayc Feb 2, 2023
df333d3
fix types
angorayc Feb 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jest.mock('react-router-dom', () => {
useLocation: jest.fn().mockReturnValue({ pathname: '/test' }),
};
});
jest.mock('../../common/components/visualization_actions');

const casesService = {
ui: { getCasesContext: () => mockCasesContext },
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/security_solution/public/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@ export const renderApp = ({
</SecurityApp>,
element
);
return () => unmountComponentAtNode(element);
return () => {
services.data.search.session.clear();
unmountComponentAtNode(element);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export interface DonutChartProps {
data: DonutChartData[] | null | undefined;
fillColor: FillColor;
height?: number;
isChartEmbeddablesEnabled?: boolean;
label: React.ReactElement | string;
legendItems?: LegendItem[] | null | undefined;
onElementClick?: ElementClickListener;
Expand All @@ -67,10 +66,10 @@ export interface DonutChartWrapperProps {
/* Make this position absolute in order to overlap the text onto the donut */
export const DonutTextWrapper = styled(EuiFlexGroup)<
EuiFlexGroupProps & {
$isChartEmbeddablesEnabled?: boolean;
$dataExists?: boolean;
$donutTextWrapperStyles?: FlattenSimpleInterpolation;
$isChartEmbeddablesEnabled?: boolean;
className?: string;
donutTextWrapperStyles?: FlattenSimpleInterpolation;
}
>`
top: ${({ $isChartEmbeddablesEnabled, $dataExists }) =>
Expand All @@ -80,8 +79,8 @@ export const DonutTextWrapper = styled(EuiFlexGroup)<
position: absolute;
z-index: 1;

${({ className, donutTextWrapperStyles }) =>
className && donutTextWrapperStyles ? `&.${className} {${donutTextWrapperStyles}}` : ''}
${({ className, $donutTextWrapperStyles }) =>
className && $donutTextWrapperStyles ? `&.${className} {${$donutTextWrapperStyles}}` : ''}
`;

export const StyledEuiFlexItem = styled(EuiFlexItem)`
Expand Down Expand Up @@ -117,11 +116,11 @@ const DonutChartWrapperComponent: React.FC<DonutChartWrapperProps> = ({
<StyledEuiFlexItem grow={isChartEmbeddablesEnabled}>
<DonutTextWrapper
$dataExists={dataExists}
$donutTextWrapperStyles={donutTextWrapperStyles}
$isChartEmbeddablesEnabled={isChartEmbeddablesEnabled}
alignItems="center"
className={donutTextWrapperClassName}
direction="column"
donutTextWrapperStyles={donutTextWrapperStyles}
gutterSize="none"
justifyContent="center"
>
Expand Down Expand Up @@ -151,7 +150,6 @@ export const DonutChart = ({
data,
fillColor,
height = 90,
isChartEmbeddablesEnabled,
label,
legendItems,
onElementClick,
Expand All @@ -165,7 +163,7 @@ export const DonutChart = ({
dataExists={data != null && data.length > 0}
label={label}
title={title}
isChartEmbeddablesEnabled={isChartEmbeddablesEnabled}
isChartEmbeddablesEnabled={false}
>
<>
{data == null || totalCount == null || totalCount === 0 ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jest.mock('../../lib/kibana', () => {
};
});

jest.mock('../visualization_actions');
jest.mock('../visualization_actions/lens_embeddable');

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: () => mockHistory,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import type { BarChartComponentProps } from '../charts/barchart';
import { BarChart } from '../charts/barchart';
import { MatrixLoader } from './matrix_loader';

const MatrixHistogramChartContentComponent = ({
isInitialLoading,
barChart,
configs,
stackByField,
scopeId,
}: BarChartComponentProps & { isInitialLoading: boolean }) => {
return isInitialLoading ? (
<MatrixLoader />
) : (
<BarChart barChart={barChart} configs={configs} stackByField={stackByField} scopeId={scopeId} />
);
};

export const MatrixHistogramChartContent = React.memo(MatrixHistogramChartContentComponent);

MatrixHistogramChartContentComponent.displayName = 'MatrixHistogramChartContentComponent';
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,7 @@ describe('Matrix Histogram Component', () => {
});

describe('Inspect button', () => {
test("it doesn't render Inspect button by default on Host page", () => {
mockLocation.mockReturnValue({ pathname: '/hosts' });

const testProps = {
...mockMatrixOverTimeHistogramProps,
lensAttributes: dnsTopDomainsLensAttributes,
};
wrapper = mount(<MatrixHistogram {...testProps} />, {
wrappingComponent: TestProviders,
});
expect(wrapper.find('[data-test-subj="inspect-icon-button"]').exists()).toBe(false);
});

test("it doesn't render Inspect button by default on Network page", () => {
mockLocation.mockReturnValue({ pathname: '/network' });

test("it doesn't render Inspect button by default", () => {
const testProps = {
...mockMatrixOverTimeHistogramProps,
lensAttributes: dnsTopDomainsLensAttributes,
Expand All @@ -201,41 +186,10 @@ describe('Matrix Histogram Component', () => {
});
expect(wrapper.find('[data-test-subj="inspect-icon-button"]').exists()).toBe(false);
});

test('it render Inspect button by default on other pages', () => {
mockLocation.mockReturnValue({ pathname: '/overview' });

const testProps = {
...mockMatrixOverTimeHistogramProps,
lensAttributes: dnsTopDomainsLensAttributes,
};
wrapper = mount(<MatrixHistogram {...testProps} />, {
wrappingComponent: TestProviders,
});
expect(wrapper.find('[data-test-subj="inspect-icon-button"]').exists()).toBe(true);
});
});

describe('VisualizationActions', () => {
test('it renders VisualizationActions on Host page if lensAttributes is provided', () => {
mockLocation.mockReturnValue({ pathname: '/hosts' });

const testProps = {
...mockMatrixOverTimeHistogramProps,
lensAttributes: dnsTopDomainsLensAttributes,
};
wrapper = mount(<MatrixHistogram {...testProps} />, {
wrappingComponent: TestProviders,
});
expect(wrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(true);
expect(wrapper.find('[data-test-subj="mock-viz-actions"]').prop('className')).toEqual(
'histogram-viz-actions'
);
});

test('it renders VisualizationActions on Network page if lensAttributes is provided', () => {
mockLocation.mockReturnValue({ pathname: '/network' });

test('it renders VisualizationActions if lensAttributes is provided', () => {
const testProps = {
...mockMatrixOverTimeHistogramProps,
lensAttributes: dnsTopDomainsLensAttributes,
Expand All @@ -248,20 +202,6 @@ describe('Matrix Histogram Component', () => {
'histogram-viz-actions'
);
});

test("it doesn't renders VisualizationActions except Host / Network pages", () => {
const testProps = {
...mockMatrixOverTimeHistogramProps,
lensAttributes: dnsTopDomainsLensAttributes,
};

mockLocation.mockReturnValue({ pathname: '/overview' });

wrapper = mount(<MatrixHistogram {...testProps} />, {
wrappingComponent: TestProviders,
});
expect(wrapper.find('[data-test-subj="mock-viz-actions"]').exists()).toBe(false);
});
});

describe('toggle query', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import styled from 'styled-components';

import { EuiFlexGroup, EuiFlexItem, EuiProgress, EuiSelect, EuiSpacer } from '@elastic/eui';
import { useDispatch } from 'react-redux';
import { useLocation } from 'react-router-dom';
import * as i18n from './translations';
import { BarChart } from '../charts/barchart';
import { HeaderSection } from '../header_section';
import { MatrixLoader } from './matrix_loader';
import { Panel } from '../panel';
import { getBarchartConfigs, getCustomChartData } from './utils';
import { useMatrixHistogramCombined } from '../../containers/matrix_histogram';
Expand All @@ -35,8 +32,10 @@ import { HoverVisibilityContainer } from '../hover_visibility_container';
import { VisualizationActions } from '../visualization_actions';
import type { GetLensAttributes, LensAttributes } from '../visualization_actions/types';
import { useQueryToggle } from '../../containers/query_toggle';
import { useIsExperimentalFeatureEnabled } from '../../hooks/use_experimental_features';
import { VISUALIZATION_ACTIONS_BUTTON_CLASS } from '../visualization_actions/utils';
import { isExplorePage } from '../../../helpers';
import { VisualizationEmbeddable } from '../visualization_actions/visualization_embeddable';
import { MatrixHistogramChartContent } from './chart_content';

export type MatrixHistogramComponentProps = MatrixHistogramProps &
Omit<MatrixHistogramQueryProps, 'stackByField'> & {
Expand Down Expand Up @@ -71,6 +70,8 @@ const HistogramPanel = styled(Panel)<{ height?: number }>`
${({ height }) => (height != null ? `min-height: ${height}px;` : '')}
`;

const CHART_HEIGHT = '150px';

export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> = ({
chartHeight,
defaultStackByOption,
Expand Down Expand Up @@ -107,7 +108,6 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
hideQueryToggle = false,
}) => {
const dispatch = useDispatch();
const { pathname } = useLocation();

const handleBrushEnd = useCallback(
({ x }) => {
Expand Down Expand Up @@ -169,6 +169,8 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
[setQuerySkip, setToggleStatus]
);

const isChartEmbeddablesEnabled = useIsExperimentalFeatureEnabled('chartEmbeddablesEnabled');

const matrixHistogramRequest = {
endDate,
errorMessage,
Expand All @@ -180,11 +182,10 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
stackByField: selectedStackByOption.value,
runtimeMappings,
isPtrIncluded,
skip: querySkip,
skip: querySkip || isChartEmbeddablesEnabled,
};
const [loading, { data, inspect, totalCount, refetch }] =
useMatrixHistogramCombined(matrixHistogramRequest);
const onExplorePage = isExplorePage(pathname);

const titleWithStackByField = useMemo(
() => (title != null && typeof title === 'function' ? title(selectedStackByOption) : title),
Expand All @@ -209,22 +210,28 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =

useEffect(() => {
if (!loading && !isInitialLoading) {
setQuery({ id, inspect, loading, refetch });
setQuery({
id,
inspect,
loading,
refetch,
});
}

if (isInitialLoading && !!barChartData && data) {
setIsInitialLoading(false);
}
}, [
setQuery,
barChartData,
data,
id,
inspect,
isChartEmbeddablesEnabled,
isInitialLoading,
loading,
refetch,
isInitialLoading,
barChartData,
data,
setIsInitialLoading,
setQuery,
]);

const timerange = useMemo(() => ({ from: startDate, to: endDate }), [startDate, endDate]);
Expand Down Expand Up @@ -261,11 +268,11 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
toggleQuery={hideQueryToggle ? undefined : toggleQuery}
subtitle={subtitleWithCounts}
inspectMultiple
showInspectButton={showInspectButton || !onExplorePage}
showInspectButton={showInspectButton && !isChartEmbeddablesEnabled}
isInspectDisabled={filterQuery === undefined}
>
<EuiFlexGroup alignItems="center" gutterSize="none">
{onExplorePage && (getLensAttributes || lensAttributes) && timerange && (
{(getLensAttributes || lensAttributes) && timerange && (
<EuiFlexItem grow={false}>
<VisualizationActions
className="histogram-viz-actions"
Expand Down Expand Up @@ -293,10 +300,20 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramComponentProps> =
</EuiFlexGroup>
</HeaderSection>
{toggleStatus ? (
isInitialLoading ? (
<MatrixLoader />
isChartEmbeddablesEnabled ? (
<VisualizationEmbeddable
data-test-subj="embeddable-matrix-histogram"
getLensAttributes={getLensAttributes}
height={CHART_HEIGHT}
id={`${id}-embeddable`}
inspectTitle={title as string}
lensAttributes={lensAttributes}
stackByField={selectedStackByOption.value}
timerange={timerange}
/>
) : (
<BarChart
<MatrixHistogramChartContent
isInitialLoading={isInitialLoading}
barChart={barChartData}
configs={barchartConfigs}
stackByField={selectedStackByOption.value}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const useRefetchByRestartingSession = jest.fn().mockReturnValue({
session: {
current: {
start: jest
.fn()
.mockReturnValueOnce('mockSearchSessionId')
.mockReturnValue('mockSearchSessionIdDefault'),
},
},
refetchByRestartingSession: jest.fn(),
});
Loading