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

[Cloud Security] Added graph visualization in alert's flyout #196034

Merged
merged 45 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
977874c
Created Graph component
kfirpeled Oct 13, 2024
8456abf
Ensure target has an id
kfirpeled Oct 13, 2024
2203f65
Added graph preview to alerts flyout
kfirpeled Oct 13, 2024
431e59f
Hides react flow attribution
kfirpeled Oct 13, 2024
c97c18c
Added cloud security storybook to kibana's storybook website
kfirpeled Oct 13, 2024
f856800
Experimental feature disabled by default
kfirpeled Oct 13, 2024
edebaf6
fixed unknown target's label
kfirpeled Oct 13, 2024
ff920d6
code cleanup
kfirpeled Oct 13, 2024
832ddf4
Disable controls, dragging and zoom when in preview
kfirpeled Oct 13, 2024
bc189ee
Removed panel's
kfirpeled Oct 13, 2024
94c22d4
Enhanced experience
kfirpeled Oct 13, 2024
47dc47a
Merge branch 'main' into cspm/cdr-alerts-flyout2
kfirpeled Oct 15, 2024
8876474
Refactor cloud-security-posture storybook folder structure
kfirpeled Oct 15, 2024
6545761
Refactored graph data types
kfirpeled Oct 15, 2024
652652e
Renamed stories
kfirpeled Oct 15, 2024
8d0d79a
Added FTR test that check it is being rendered
kfirpeled Oct 15, 2024
81bc3d2
Refactoring
kfirpeled Oct 15, 2024
e8f03b0
Fixed API type, removing redundant properties. Fixed dragging that st…
kfirpeled Oct 15, 2024
11f1565
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Oct 15, 2024
e06bbdf
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Oct 15, 2024
e8597da
Added graph UT
kfirpeled Oct 15, 2024
eeddc65
Updated readme
kfirpeled Oct 15, 2024
e1cfbe8
skipped failing test
kfirpeled Oct 15, 2024
e70e48e
Fixed behaviour when changing focus using tab
kfirpeled Oct 15, 2024
63329eb
Build fixes
kfirpeled Oct 15, 2024
1151e7b
Jest fix
kfirpeled Oct 15, 2024
d54c371
Merge branch 'main' into cspm/cdr-alerts-flyout2
kfirpeled Oct 15, 2024
85c75ba
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Oct 15, 2024
78b1f99
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Oct 15, 2024
33c7ce6
Revert changes tsconfig.json
kfirpeled Oct 15, 2024
16de019
Fixed graph interactivity
kfirpeled Oct 16, 2024
7952ce7
Code review fixes
kfirpeled Oct 16, 2024
48f3d88
fixed UT
kfirpeled Oct 16, 2024
e2db7c9
import fix
kfirpeled Oct 16, 2024
9a7d02e
Lazy loading graph component
kfirpeled Oct 16, 2024
7eb5c49
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Oct 16, 2024
7ce77b2
Merge branch 'main' into cspm/cdr-alerts-flyout2
kfirpeled Oct 17, 2024
04c2c8b
Refactoring, auto fitview on resize when not interactive.
kfirpeled Oct 17, 2024
9b3dc3c
webpack refactoring - usage of babel preset
kfirpeled Oct 18, 2024
e4e07c6
Removed packaging of storybook config
kfirpeled Oct 18, 2024
049b4c0
Merge branch 'main' into cspm/cdr-alerts-flyout2
kfirpeled Oct 21, 2024
0c0594d
Enhancing graph behavior in preview - max zoom is set to 1.3
kfirpeled Oct 22, 2024
9aa0863
Memorizing graph's data
kfirpeled Oct 25, 2024
2a0b590
Merge branch 'main' into cspm/cdr-alerts-flyout2
kfirpeled Oct 25, 2024
db07ec1
refactored shapes
kfirpeled Oct 25, 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
17 changes: 9 additions & 8 deletions .buildkite/scripts/steps/storybooks/build_and_upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,45 @@ const STORYBOOKS = [
'canvas',
'cases',
'cell_actions',
'coloring',
'chart_icons',
'cloud_security_posture_packages',
'coloring',
'content_management_examples',
'custom_integrations',
'dashboard_enhanced',
'dashboard',
'data',
'logs_explorer',
'embeddable',
'esql_editor',
'expression_error',
'expression_image',
'expression_metric',
'expression_repeat_image',
'expression_reveal_image',
'expression_shape',
'expression_tagcloud',
'management',
'fleet',
'grouping',
'home',
'infra',
'kibana_react',
'language_documentation_popover',
'lists',
'observability',
'logs_explorer',
'management',
'observability_ai_assistant',
'observability_inventory',
'observability_shared',
'observability',
'presentation',
'security_solution',
'random_sampling',
'security_solution_packages',
'security_solution',
'serverless',
'shared_ux',
'triggers_actions_ui',
'ui_actions_enhanced',
'language_documentation_popover',
'unified_search',
'random_sampling',
'esql_editor',
];

const GITHUB_CONTEXT = 'Build and Publish Storybooks';
Expand Down
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1911,10 +1911,10 @@ x-pack/plugins/osquery @elastic/security-defend-workflows
/x-pack/plugins/security_solution/public/detections/components/osquery @elastic/security-defend-workflows

# Cloud Defend
/x-pack/plugins/cloud_defend/ @elastic/kibana-cloud-security-posture
/x-pack/plugins/security_solution/public/cloud_defend @elastic/kibana-cloud-security-posture

# Cloud Security Posture
x-pack/packages/kbn-cloud-security-posture @elastic/kibana-cloud-security-posture
/x-pack/test_serverless/functional/test_suites/security/config.cloud_security_posture.* @elastic/kibana-cloud-security-posture
/x-pack/plugins/security_solution/public/cloud_security_posture @elastic/kibana-cloud-security-posture
/x-pack/test/api_integration/apis/cloud_security_posture/ @elastic/kibana-cloud-security-posture
Expand Down
21 changes: 21 additions & 0 deletions packages/kbn-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,27 @@ export function getWebpackConfig(
},
},
},
{
test: /\.js$/,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

required when using @kbn/cloud-security-posture-graph which depends on dagrejs and xyflow packages

include: /node_modules[\\\/]@dagrejs/,
use: {
loader: 'babel-loader',
options: {
envName: worker.dist ? 'production' : 'development',
presets: ['@babel/preset-env'], // Doesn't work with BABEL_PRESET
plugins: ['@babel/plugin-proposal-class-properties'],
},
},
},
{
test: /node_modules[\/\\]@?xyflow[\/\\].*.js$/,
loaders: 'babel-loader',
options: {
envName: worker.dist ? 'production' : 'development',
presets: [BABEL_PRESET],
plugins: ['@babel/plugin-transform-logical-assignment-operators'],
},
},
{
test: /\.(html|md|txt|tmpl)$/,
use: {
Expand Down
19 changes: 19 additions & 0 deletions packages/kbn-storybook/src/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ export default ({ config: storybookConfig }: { config: Configuration }) => {
},
},
},
{
test: /\.js$/,
include: /node_modules[\\\/]@dagrejs/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'], // Doesn't work with @kbn/babel-preset/webpack_preset
plugins: ['@babel/plugin-proposal-class-properties'],
},
},
},
{
test: /node_modules[\/\\]@?xyflow[\/\\].*.js$/,
loaders: 'babel-loader',
options: {
presets: [require.resolve('@kbn/babel-preset/webpack_preset')],
plugins: ['@babel/plugin-transform-logical-assignment-operators'],
},
},
],
},
plugins: [new IgnoreNotFoundExportPlugin()],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

{
"id": "@kbn/cloud-security-posture-common",
"owner": "@elastic/kibana-cloud-security-posture",
"type": "shared-common"
}
"id": "@kbn/cloud-security-posture-common",
"owner": "@elastic/kibana-cloud-security-posture",
"type": "shared-common"
}
14 changes: 7 additions & 7 deletions x-pack/packages/kbn-cloud-security-posture/common/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@kbn/cloud-security-posture-common",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0",
"description": "Shared components for cloud security posture, both client and server side",
"sideEffects": false
}
"name": "@kbn/cloud-security-posture-common",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0",
"description": "Shared components for cloud security posture, both client and server side",
"sideEffects": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export const groupNodeDataSchema = schema.allOf([
export const labelNodeDataSchema = schema.allOf([
nodeBaseDataSchema,
schema.object({
source: schema.string(),
target: schema.string(),
shape: schema.literal('label'),
parentId: schema.maybe(schema.string()),
color: colorSchema,
Expand All @@ -82,8 +80,6 @@ export const labelNodeDataSchema = schema.allOf([
export const edgeDataSchema = schema.object({
id: schema.string(),
source: schema.string(),
sourceShape: nodeShapeSchema,
target: schema.string(),
targetShape: nodeShapeSchema,
color: colorSchema,
});
99 changes: 96 additions & 3 deletions x-pack/packages/kbn-cloud-security-posture/graph/README.md
Copy link
Contributor

Choose a reason for hiding this comment

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

appreciate you adding the docs and examples!

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,104 @@ security solution plugin.

## How to use this

Standalone examples will follow. In the meantime check out storybook to view the graph's progress.
### Step 1: Import the Component

## The most important public api members
First, import the `Graph` component into your desired file.

- GraphComponent itself (comming soon..)
```tsx
import { Graph } from '@kbn/cloud-security-posture-graph';
```

### Step 2: Prepare the Data

Create the nodes and edges data models. These should follow the `NodeViewModel` and `EdgeViewModel` interfaces.

```tsx
const nodes: NodeViewModel[] = [
{
id: 'node1',
label: 'Node 1',
color: 'primary',
shape: 'ellipse',
icon: 'user',
},
{
id: 'node2',
label: 'Node 2',
color: 'primary',
shape: 'hexagon',
icon: 'questionInCircle',
},
];

const edges: EdgeViewModel[] = [
{
id: 'edge1',
source: 'node1',
target: 'node2',
color: 'primary',
},
];
```

### Step 3: Render the Component

Use the `Graph` component in your JSX/TSX, passing the nodes, edges, and interactivity flag as props.

```tsx
<Graph nodes={nodes} edges={edges} interactive={true} />
```

### Example Usage

Here is a complete example of how to use the `Graph` component in a React component.
Copy link
Contributor

Choose a reason for hiding this comment

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

💯


```tsx
import React from 'react';
import { Graph } from '@kbn/cloud-security-posture-graph';
import type { NodeViewModel, EdgeViewModel } from '@kbn/cloud-security-posture-graph';

const App: React.FC = () => {
const nodes: NodeViewModel[] = [
{
id: 'node1',
label: 'Node 1',
color: 'primary',
shape: 'ellipse',
icon: 'user',
},
{
id: 'node2',
label: 'Node 2',
color: 'primary',
shape: 'hexagon',
icon: 'questionInCircle',
},
];

const edges: EdgeViewModel[] = [
{
id: 'edge1',
source: 'node1',
target: 'node2',
color: 'primary',
},
];

return (
<div>
<h1>Graph Visualization</h1>
<Graph nodes={nodes} edges={edges} interactive={true} />
</div>
);
};

export default App;
```

### Storybook Example

You can also see how the `Graph` component is used in the Storybook file `graph_layout.stories.tsx`.

### Extras

Expand Down
2 changes: 2 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './src/components';
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ module.exports = {
preset: '@kbn/test',
roots: ['<rootDir>/x-pack/packages/kbn-cloud-security-posture/graph'],
rootDir: '../../../..',
setupFiles: ['jest-canvas-mock'],
setupFilesAfterEnv: ['<rootDir>/x-pack/packages/kbn-cloud-security-posture/graph/setup_tests.ts'],
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "shared-browser",
"id": "@kbn/cloud-security-posture-graph",
"owner": "@elastic/kibana-cloud-security-posture"
"owner": "@elastic/kibana-cloud-security-posture",
"type": "shared-browser"
}
13 changes: 13 additions & 0 deletions x-pack/packages/kbn-cloud-security-posture/graph/setup_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/

// eslint-disable-next-line @kbn/imports/no_boundary_crossing
import { mockReactFlow } from './src/components/mock/react_flow';
// eslint-disable-next-line import/no-extraneous-dependencies
import '@testing-library/jest-dom';

mockReactFlow();
Loading