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] Add Host/User flyout in One Discover. #199279

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ac84386
incremental app wrapper working
logeekal Sep 23, 2024
3a46b0e
fix: user+host flyout
logeekal Nov 8, 2024
2580c51
remove unnecessary change
logeekal Nov 8, 2024
27ee1fc
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Nov 8, 2024
fb53790
discover shared lazy modules
logeekal Nov 11, 2024
8a385b6
fix: types
logeekal Nov 11, 2024
0a7eaed
fix: better lazy loading and feature access
logeekal Nov 11, 2024
a57d5bf
fix: types
logeekal Nov 12, 2024
6a8a7d9
createSecurityProfileProvider is not async
logeekal Nov 12, 2024
d9cd681
types: fix
logeekal Nov 12, 2024
f134206
fix: more types + some renames
logeekal Nov 12, 2024
9a23ccc
fix: tests
logeekal Nov 12, 2024
89b4dbb
pass security services correctly
logeekal Nov 12, 2024
b5392bf
Merge branch 'main' into feat/entity_flyout_discover_context_final
logeekal Nov 12, 2024
ab7a6ed
Merge branch 'main' into feat/entity_flyout_discover_context_final
logeekal Nov 12, 2024
cf289a4
fix: types
logeekal Nov 12, 2024
f7df1b0
PR feeback 1
logeekal Nov 13, 2024
f6fdc45
PR Feedback: discoverShared plugin
logeekal Nov 13, 2024
df8e005
fix: remove redux store init
logeekal Nov 13, 2024
5824506
add isInSecurityApp hook
logeekal Nov 13, 2024
c4bece2
fix: discover tsconfig
logeekal Nov 13, 2024
371c220
fix: correct security solution services in app wrapper
logeekal Nov 13, 2024
9198449
Merge branch 'main' into feat/entity_flyout_discover_context_final
logeekal Nov 13, 2024
4ef1600
Merge main → current branch
logeekal Nov 21, 2024
4aaa456
fix: CellActionsContext + isTimeline
logeekal Nov 21, 2024
7af2969
fix: PR feedback
logeekal Nov 21, 2024
cbbb094
fix: types
logeekal Nov 21, 2024
652ba54
Merge branch 'main' into feat/entity_flyout_discover_context_final
logeekal Nov 27, 2024
6ae2a61
fix: types
logeekal Nov 27, 2024
5c42105
Merge branch 'main' into feat/entity_flyout_discover_context_final
logeekal Nov 29, 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
7 changes: 2 additions & 5 deletions packages/kbn-unified-data-table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { ReactElement } from 'react';
import type { FunctionComponent } from 'react';
import type { EuiDataGridCellValueElementProps, EuiDataGridColumn } from '@elastic/eui';
import type { DataTableRecord } from '@kbn/discover-utils/src/types';
import type { DataView } from '@kbn/data-views-plugin/common';
Expand Down Expand Up @@ -46,10 +46,7 @@ export type DataGridCellValueElementProps = EuiDataGridCellValueElementProps & {
isCompressed?: boolean;
};

export type CustomCellRenderer = Record<
string,
(props: DataGridCellValueElementProps) => ReactElement
>;
export type CustomCellRenderer = Record<string, FunctionComponent<DataGridCellValueElementProps>>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@elastic/kibana-data-discovery

Changed this to FunctionComponent because previous type does not accept memoized components. FunctionComponent is more inclusive.

Please let me know if you would keep this a function instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really see an issue with this, although we do already memoize cell renderers here, so it's likely not necessary to memoize again:

: memo(UnifiedDataTableRenderCellValue);

If we make this change, it might even make sense to go all the way and just accept ComponentType, but not really a strong opinion.


export interface CustomGridColumnProps {
column: EuiDataGridColumn;
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/discover/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"unifiedDocViewer",
"unifiedSearch",
"unifiedHistogram",
"contentManagement"
"contentManagement",
"discoverShared"
],
"optionalPlugins": [
"dataVisualizer",
Expand Down Expand Up @@ -58,4 +59,4 @@
"common"
]
}
}
}
2 changes: 2 additions & 0 deletions src/plugins/discover/public/build_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface DiscoverServices {
ebtManager: DiscoverEBTManager;
fieldsMetadata?: FieldsMetadataPublicStart;
logsDataAccess?: LogsDataAccessPluginStart;
discoverFeaturesRegistry: DiscoverStartPlugins['discoverShared']['features']['registry'];
}

export const buildServices = memoize(
Expand Down Expand Up @@ -226,6 +227,7 @@ export const buildServices = memoize(
ebtManager,
fieldsMetadata: plugins.fieldsMetadata,
logsDataAccess: plugins.logsDataAccess,
discoverFeaturesRegistry: plugins.discoverShared.features.registry,
};
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { SecuritySolutionAppWrapperFeature } from '@kbn/discover-shared-plugin/public';

export const createAppWrapperAccessor = async (
appWrapperFeature?: SecuritySolutionAppWrapperFeature
) => {
if (!appWrapperFeature) return undefined;
return appWrapperFeature.getWrapper();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
import { SecuritySolutionCellRenderFeature } from '@kbn/discover-shared-plugin/public';
import { DataGridCellValueElementProps } from '@kbn/unified-data-table';
import { createCellRendererAccessor } from './get_cell_renderer_accessor';
import { render } from '@testing-library/react';

const cellRendererFeature: SecuritySolutionCellRenderFeature = {
id: 'security-solution-cell-render',
getRender: async () => (fieldName: string) => {
if (fieldName === 'host.name') {
return (props: DataGridCellValueElementProps) => {
return <div data-test-subj="cell-render-feature">{props.columnId}</div>;
};
}
},
};

const mockCellProps = {
columnId: 'host.name',
row: {
id: '1',
raw: {},
flattened: {},
},
} as DataGridCellValueElementProps;

describe('getCellRendererAccessort', () => {
it('should return a cell renderer', async () => {
const getCellRenderer = await createCellRendererAccessor(cellRendererFeature);
expect(getCellRenderer).toBeDefined();
const CellRenderer = getCellRenderer?.('host.name') as React.FC<DataGridCellValueElementProps>;
expect(CellRenderer).toBeDefined();
const { getByTestId } = render(<CellRenderer {...mockCellProps} />);
expect(getByTestId('cell-render-feature')).toBeVisible();
expect(getByTestId('cell-render-feature')).toHaveTextContent('host.name');
});

it('should return undefined if cellRendererFeature is not defined', async () => {
const getCellRenderer = await createCellRendererAccessor();
expect(getCellRenderer).toBeUndefined();
});

it('should return undefined if cellRendererGetter returns undefined', async () => {
const getCellRenderer = await createCellRendererAccessor(cellRendererFeature);
const cellRenderer = getCellRenderer?.('user.name');
expect(cellRenderer).toBeUndefined();
});
});
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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
import { SecuritySolutionCellRenderFeature } from '@kbn/discover-shared-plugin/public';
import { DataGridCellValueElementProps } from '@kbn/unified-data-table';

export const createCellRendererAccessor = async (
cellRendererFeature?: SecuritySolutionCellRenderFeature
) => {
if (!cellRendererFeature) return undefined;
const cellRendererGetter = await cellRendererFeature.getRender();
function getCellRenderer(fieldName: string) {
if (!cellRendererFeature) return undefined;
const CellRenderer = cellRendererGetter(fieldName);
if (!CellRenderer) return undefined;
return React.memo(function SecuritySolutionCellRenderer(props: DataGridCellValueElementProps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now I see where the memo is used. I think we could probably omit this since we memoize them anyway.

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

return getCellRenderer;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,80 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React, { FunctionComponent, useMemo } from 'react';
import { CustomCellRenderer, DataGridCellValueElementProps } from '@kbn/unified-data-table';
import { RootProfileProvider, SolutionType } from '../../../profiles';
import { ProfileProviderServices } from '../../profile_provider_services';
import { SecurityProfileProviderFactory } from '../types';
import { createCellRendererAccessor } from '../accessors/get_cell_renderer_accessor';
import { createAppWrapperAccessor } from '../accessors/get_app_wrapper_accessor';

interface SecurityRootProfileContext {
store?: unknown;
appWrapper?: (props: { children?: React.ReactNode }) => JSX.Element;
getCellRenderer?: (
fieldName: string
) => FunctionComponent<DataGridCellValueElementProps> | undefined;
}

export const createSecurityRootProfileProvider: SecurityProfileProviderFactory<
RootProfileProvider
> = (services: ProfileProviderServices) => ({
profileId: 'security-root-profile',
isExperimental: true,
profile: {
getCellRenderers: (prev) => (params) => ({
...prev(params),
}),
},
resolve: (params) => {
if (params.solutionNavId === SolutionType.Security) {
return { isMatch: true, context: { solutionType: SolutionType.Security } };
}
RootProfileProvider<SecurityRootProfileContext>
> = (services: ProfileProviderServices) => {
const { discoverFeaturesRegistry } = services;
const cellRendererFeature = discoverFeaturesRegistry.getById('security-solution-cell-render');
const appWrapperFeature = discoverFeaturesRegistry.getById('security-solution-app-wrapper');
const reduxStoreInitFeature = discoverFeaturesRegistry.getById(
'security-solution-redux-store-init'
);

return {
profileId: 'security-root-profile',
isExperimental: true,
profile: {
getRenderAppWrapper: (PrevWrapper, params) =>
React.memo(({ children }) => {
const AppWrapper = useMemo(() => params.context.appWrapper ?? PrevWrapper, []);
return <AppWrapper>{children}</AppWrapper>;
}),
getCellRenderers:
(prev, { context }) =>
(params) => {
const entries = prev(params);
const customCellRenderers = [
'host.name',
'user.name',
'source.ip',
'destination.ip',
].reduce<CustomCellRenderer>((acc, fieldName) => {
acc[fieldName] = context.getCellRenderer?.(fieldName) ?? entries[fieldName];
return acc;
}, {});
return {
...entries,
...customCellRenderers,
};
},
},
resolve: async (params) => {
if (params.solutionNavId !== SolutionType.Security) {
return {
isMatch: false,
};
}

const store = await reduxStoreInitFeature?.get();
const getAppWrapper = await createAppWrapperAccessor(appWrapperFeature);
const getCellRenderer = await createCellRendererAccessor(cellRendererFeature);

return { isMatch: false };
},
});
return {
isMatch: true,
context: {
solutionType: SolutionType.Security,
store,
appWrapper: getAppWrapper?.({ store }),
getCellRenderer,
},
};
},
};
};
4 changes: 2 additions & 2 deletions src/plugins/discover/public/context_awareness/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { EuiIconType } from '@elastic/eui/src/components/icon/icon';
import type { AggregateQuery, Filter, Query, TimeRange } from '@kbn/es-query';
import type { OmitIndexSignature } from 'type-fest';
import type { Trigger } from '@kbn/ui-actions-plugin/public';
import type { PropsWithChildren, ReactElement } from 'react';
import type { FunctionComponent, PropsWithChildren } from 'react';
import type { DocViewFilterFn } from '@kbn/unified-doc-viewer/types';
import type { DiscoverDataSource } from '../../common/data_sources';
import type { DiscoverAppState } from '../application/main/state_management/discover_app_state_container';
Expand Down Expand Up @@ -264,7 +264,7 @@ export interface Profile {
* @param props The app wrapper props
* @returns The custom app wrapper component
*/
getRenderAppWrapper: (props: PropsWithChildren<{}>) => ReactElement;
getRenderAppWrapper: FunctionComponent<PropsWithChildren<{}>>;

/**
* Gets default Discover app state that should be used when the profile is resolved
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/discover/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import type { AiopsPluginStart } from '@kbn/aiops-plugin/public';
import type { DataVisualizerPluginStart } from '@kbn/data-visualizer-plugin/public';
import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
import type { LogsDataAccessPluginStart } from '@kbn/logs-data-access-plugin/public';
import { DiscoverSharedPublicStart } from '@kbn/discover-shared-plugin/public';
import { DiscoverAppLocator } from '../common';
import { DiscoverCustomizationContext } from './customizations';
import { type DiscoverContainerProps } from './components/discover_container';
Expand Down Expand Up @@ -172,4 +173,5 @@ export interface DiscoverStartPlugins {
unifiedSearch: UnifiedSearchPublicPluginStart;
urlForwarding: UrlForwardingStart;
usageCollection?: UsageCollectionSetup;
discoverShared: DiscoverSharedPublicStart;
}
6 changes: 4 additions & 2 deletions src/plugins/discover/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@
"@kbn/presentation-containers",
"@kbn/observability-ai-assistant-plugin",
"@kbn/fields-metadata-plugin",
"@kbn/discover-contextual-components",
"@kbn/logs-data-access-plugin",
"@kbn/core-lifecycle-browser",
"@kbn/discover-contextual-components",
"@kbn/esql-ast"
"@kbn/esql-ast",
"@kbn/logs-data-access-plugin",
"@kbn/discover-shared-plugin",
],
"exclude": [
"target/**/*"
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/discover_shared/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ export type { DiscoverSharedPublicSetup, DiscoverSharedPublicStart } from './typ
export type {
ObservabilityLogsAIAssistantFeatureRenderDeps,
ObservabilityLogsAIAssistantFeature,
SecuritySolutionCellRenderFeature,
SecuritySolutionAppWrapperFeature,
SecuritySolutionReduxStoreInitFeature,
DiscoverFeature,
} from './services/discover_features';
DiscoverFeaturesServiceSetup,
DiscoverFeaturesServiceStart,
} from './services/discover_features/types';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { DataTableRecord } from '@kbn/discover-utils';
import type { DataTableRecord } from '@kbn/discover-utils';
import type { FunctionComponent, PropsWithChildren, ReactElement } from 'react';
import type { DataGridCellValueElementProps } from '@kbn/unified-data-table';
import { FeaturesRegistry } from '../../../common';

/**
Expand All @@ -30,8 +32,39 @@ export interface ObservabilityLogsAIAssistantFeature {
render: (deps: ObservabilityLogsAIAssistantFeatureRenderDeps) => JSX.Element;
}

/** ***************************** Security **********/
export interface SecuritySolutionCellRenderFeature {
id: 'security-solution-cell-render';
getRender: () => Promise<
(fieldName: string) => FunctionComponent<DataGridCellValueElementProps> | undefined
>;
}

interface SecuritySolutionAppWrapperFeatureArgs {
store: unknown;
}

export interface SecuritySolutionAppWrapperFeature {
id: 'security-solution-app-wrapper';
getWrapper: () => Promise<
(args: SecuritySolutionAppWrapperFeatureArgs) => (props: PropsWithChildren<{}>) => ReactElement
>;
}

export interface SecuritySolutionReduxStoreInitFeature {
id: 'security-solution-redux-store-init';
/* returns the security's redux store instance */
get: () => Promise<unknown>;
}

type SecuritySolutionFeature =
| SecuritySolutionCellRenderFeature
| SecuritySolutionAppWrapperFeature
| SecuritySolutionReduxStoreInitFeature;
/** ****************************************************************************************/

// This should be a union of all the available client features.
export type DiscoverFeature = ObservabilityLogsAIAssistantFeature;
export type DiscoverFeature = ObservabilityLogsAIAssistantFeature | SecuritySolutionFeature;

/**
* Service types
Expand Down
1 change: 1 addition & 0 deletions src/plugins/discover_shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"kbn_references": [
"@kbn/discover-utils",
"@kbn/core",
"@kbn/unified-data-table",
]
}
4 changes: 2 additions & 2 deletions x-pack/plugins/security_solution/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"dashboard",
"data",
"dataViews",
"discover",
"ecsDataQualityDashboard",
"elasticAssistant",
"embeddable",
Expand Down Expand Up @@ -59,7 +58,8 @@
"unifiedDocViewer",
"charts",
"entityManager",
"inference"
"inference",
"discoverShared"
],
"optionalPlugins": [
"encryptedSavedObjects",
Expand Down
Loading