-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[RAM] Alert Table from triggers_actions_ui plugin #131883
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
Merged
Merged
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
ef36295
wip I
XavierM e7f2db1
Merge branch 'main' of github.com:elastic/kibana into alert_hook
XavierM 1a2c01b
Merge branch 'main' of github.com:elastic/kibana into alert_hook
XavierM 101f207
Merge branch 'main' of github.com:elastic/kibana into alert_hook
XavierM 97f0724
add alert table state in case
XavierM 34743f4
Merge branch 'main' of github.com:elastic/kibana into alert_hook
XavierM 8ad955b
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 0f631fd
add new API to get FeatureID form registrationContext and update UI t…
XavierM 64c9934
Merge branch 'main' of github.com:elastic/kibana into alert_hook
XavierM 751c424
Merge branch 'alert_hook' of github.com:XavierM/kibana into alert_hook
XavierM e4a9428
rm dead code
XavierM 722ec2b
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 18ae8e6
Merge remote-tracking branch 'upstream/main' into alert_hook
d857e79
remove unnecessary memo
fb97e17
adds tests for case view helpers
e3200d0
Move http call to API and add tests for getFeatureIds
d9d0362
fix type + unit test
XavierM 1159965
Merge branch 'main' of github.com:elastic/kibana into alert_hook
XavierM a5d8dfc
add unit tests + cleanup
XavierM 6844821
Merge branch 'main' of github.com:elastic/kibana into alert_hook
XavierM 0eb04cc
add new api integration test for _feature_ids
XavierM dcc63d2
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 7b21712
Fix small type creating typescript slowness
1371478
remove console log
30cc5c7
use import type for validfeatureId
08ae759
force any to improve typescript performance
e6c8a92
Update APM (#132270)
renovate[bot] 016aaf4
[ResponseOps][Docs] Updating ServiceNow docs with OAuth setup instruc…
ymao1 29b56a6
Show polling options when 'Data streams' option is selected in the Co…
0eecdb1
[Osquery] Make Osquery All with All base privillege (#130523)
tomsonpl 9c2f618
[XY] Add normalizeTable function to correct works with esdocs (#131917)
VladLasitsa a06e781
[Osquery] Add default osquery_saved_query objects (#129461)
tomsonpl 59ffe0d
[Unified Search] Show error message for invalid date filter value (#1…
nlatipov b5dc585
Update navigation landing pages to use appLinks config (#132027)
machadoum 1160ae5
[Cloud Posture] add resource findings page flyout (#132243)
orouz 0f66dcf
[Discover] Add a tour for Document Explorer (#131125)
jughosta 1724ab7
[XY] Add `minTimeBarInterval` arg (#128726)
VladLasitsa 430264d
Merge remote-tracking branch 'upstream/main' into alert_hook
dc41578
do not use barrel imports
94fd76a
do not use barrel import
9545f0e
do not use barrel import
b4e82ca
do not use barrel imports
08b760c
do not use barrel import
c7dc373
import types
cbf0be3
Add tests
cnasikas 229e75b
Merge branch 'alert_hook' of github.com:XavierM/kibana into alert_hook
cnasikas 66abc65
Fix cases bundle size
62bb244
Add more tests
cnasikas 20f58cb
Merge branch 'alert_hook' of github.com:XavierM/kibana into alert_hook
cnasikas f40928b
[Fleet] Add new API to get current upgrades (#132276)
nchaulet fc6cd8c
Add support of Data View switching for Agg-Based visualizations (#132…
alexwizp 6bf622a
[Security Solution] Responsive styling fixes (#131951)
stephmilovic 6202f2f
[Discover] Add Analytics No Data Page (#131965)
1bf83a3
Remove barrel export from public index file
09f7ca1
remove barrel export
f8b4913
Merge remote-tracking branch 'upstream/main' into alert_hook
afb43aa
Re-export missing exports
f44390c
Turn off feature flag
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
x-pack/plugins/cases/public/components/case_view/components/case_view_alerts.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * 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 { waitFor } from '@testing-library/dom'; | ||
| import { alertCommentWithIndices, basicCase } from '../../../containers/mock'; | ||
| import { AppMockRenderer, createAppMockRenderer } from '../../../common/mock'; | ||
| import { Case } from '../../../../common'; | ||
| import { CaseViewAlerts } from './case_view_alerts'; | ||
| import * as api from '../../../containers/api'; | ||
|
|
||
| jest.mock('../../../containers/api'); | ||
|
|
||
| const caseData: Case = { | ||
| ...basicCase, | ||
| comments: [...basicCase.comments, alertCommentWithIndices], | ||
| }; | ||
|
|
||
| describe('Case View Page activity tab', () => { | ||
| const getAlertsStateTableMock = jest.fn(); | ||
| let appMockRender: AppMockRenderer; | ||
|
|
||
| beforeEach(() => { | ||
| appMockRender = createAppMockRenderer(); | ||
| appMockRender.coreStart.triggersActionsUi.getAlertsStateTable = | ||
| getAlertsStateTableMock.mockReturnValue(<div data-test-subj="alerts-table" />); | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should render the alerts table', async () => { | ||
| const result = appMockRender.render(<CaseViewAlerts caseData={caseData} />); | ||
| await waitFor(async () => { | ||
| expect(result.getByTestId('alerts-table')).toBeTruthy(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should call the alerts table with correct props', async () => { | ||
| appMockRender.render(<CaseViewAlerts caseData={caseData} />); | ||
| await waitFor(async () => { | ||
| expect(getAlertsStateTableMock).toHaveBeenCalledWith({ | ||
| alertsTableConfigurationRegistry: expect.anything(), | ||
| configurationId: 'securitySolution', | ||
| featureIds: ['siem', 'observability'], | ||
| id: 'case-details-alerts-securitySolution', | ||
| query: { | ||
| ids: { | ||
| values: ['alert-id-1'], | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it('should call the getFeatureIds with the correct registration context', async () => { | ||
| const getFeatureIdsMock = jest.spyOn(api, 'getFeatureIds'); | ||
| appMockRender.render(<CaseViewAlerts caseData={caseData} />); | ||
| await waitFor(async () => { | ||
| expect(getFeatureIdsMock).toHaveBeenCalledWith( | ||
| { registrationContext: ['matchme'] }, | ||
| expect.anything() | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/cases/public/components/case_view/components/case_view_alerts.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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, { useMemo } from 'react'; | ||
|
|
||
| import { Case } from '../../../../common'; | ||
| import { useKibana } from '../../../common/lib/kibana'; | ||
| import { getManualAlertIds, getRegistrationContextFromAlerts } from './helpers'; | ||
| import { useGetFeatureIds } from '../../../containers/use_get_feature_ids'; | ||
|
|
||
| interface CaseViewAlertsProps { | ||
| caseData: Case; | ||
| } | ||
| export const CaseViewAlerts = ({ caseData }: CaseViewAlertsProps) => { | ||
| const { triggersActionsUi } = useKibana().services; | ||
|
|
||
| const alertIdsQuery = useMemo( | ||
| () => ({ | ||
| ids: { | ||
| values: getManualAlertIds(caseData.comments), | ||
| }, | ||
| }), | ||
| [caseData.comments] | ||
| ); | ||
| const alertRegistrationContexts = useMemo( | ||
| () => getRegistrationContextFromAlerts(caseData.comments), | ||
| [caseData.comments] | ||
| ); | ||
|
|
||
| const alertFeatureIds = useGetFeatureIds(alertRegistrationContexts); | ||
|
|
||
| const alertStateProps = { | ||
| alertsTableConfigurationRegistry: triggersActionsUi.alertsTableConfigurationRegistry, | ||
| configurationId: caseData.owner, | ||
| id: `case-details-alerts-${caseData.owner}`, | ||
| featureIds: alertFeatureIds, | ||
| query: alertIdsQuery, | ||
| }; | ||
|
|
||
| return <>{triggersActionsUi.getAlertsStateTable(alertStateProps)}</>; | ||
|
academo marked this conversation as resolved.
|
||
| }; | ||
| CaseViewAlerts.displayName = 'CaseViewAlerts'; | ||
94 changes: 94 additions & 0 deletions
94
x-pack/plugins/cases/public/components/case_view/components/helpers.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * 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 { alertComment } from '../../../containers/mock'; | ||
| import { getManualAlertIds, getRegistrationContextFromAlerts } from './helpers'; | ||
|
|
||
| const comment = { | ||
| ...alertComment, | ||
| alertId: 'alert-id-1', | ||
| index: '.alerts-matchme.alerts', | ||
| }; | ||
| const comment2 = { | ||
| ...alertComment, | ||
| alertId: 'alert-id-2', | ||
| index: '.alerts-another.alerts', | ||
| }; | ||
|
|
||
| const comment3 = { | ||
| ...alertComment, | ||
| alertId: ['nested1', 'nested2', 'nested3'], | ||
| }; | ||
|
|
||
| const commentSiemSignal = { | ||
| ...alertComment, | ||
| alertId: 'alert-id-siem', | ||
| index: '.siem-signals-default-000008', | ||
| }; | ||
|
|
||
| const commentIsBad = { | ||
| ...alertComment, | ||
| alertId: 'alert-id-bad', | ||
| index: 'bad-siem-signals-default-000008', | ||
| }; | ||
|
|
||
| const multipleIndices = { | ||
| ...alertComment, | ||
| alertId: ['test-id-1', 'test-id-2', 'test-id-3', 'test-id-4', 'test-id-5', 'test-id-6'], | ||
| index: [ | ||
| '.internal.alerts-security.alerts-default-000001', | ||
| '.internal.alerts-observability.logs.alerts-default-000001', | ||
| '.internal.alerts-observability.uptime.alerts-default-000001', | ||
| '.internal.alerts-observability.metrics.alerts-default-000001', | ||
| '.internal.alerts-observability.apm.alerts-space2-000001', | ||
| '.internal.alerts-observability.logs.alerts-space1-000001', | ||
| ], | ||
| }; | ||
|
|
||
| describe('Case view helpers', () => { | ||
| describe('getRegistrationContextFromAlerts', () => { | ||
| it('returns the correct registration context', () => { | ||
| const result = getRegistrationContextFromAlerts([comment, comment2, multipleIndices]); | ||
| expect(result).toEqual([ | ||
| 'matchme', | ||
| 'another', | ||
| 'security', | ||
| 'observability.logs', | ||
| 'observability.uptime', | ||
| 'observability.metrics', | ||
| 'observability.apm', | ||
| ]); | ||
| }); | ||
|
|
||
| it('dedupes contexts', () => { | ||
| const result = getRegistrationContextFromAlerts([comment, comment]); | ||
| expect(result).toEqual(['matchme']); | ||
| }); | ||
|
|
||
| it('returns the correct registration when find a .siem-signals* index', () => { | ||
| const result = getRegistrationContextFromAlerts([commentSiemSignal, comment2]); | ||
| expect(result).toEqual(['security', 'another']); | ||
| }); | ||
|
|
||
| it('returns empty when the index is not formatted as expected', () => { | ||
| const result = getRegistrationContextFromAlerts([commentIsBad]); | ||
| expect(result).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getManualAlertIds', () => { | ||
| it('returns the alert ids', () => { | ||
| const result = getManualAlertIds([comment, comment2]); | ||
| expect(result).toEqual(['alert-id-1', 'alert-id-2']); | ||
| }); | ||
|
|
||
| it('returns the alerts id from multiple alerts in a comment', () => { | ||
| const result = getManualAlertIds([comment, comment2, comment3]); | ||
| expect(result).toEqual(['alert-id-1', 'alert-id-2', 'nested1', 'nested2', 'nested3']); | ||
| }); | ||
| }); | ||
| }); |
51 changes: 51 additions & 0 deletions
51
x-pack/plugins/cases/public/components/case_view/components/helpers.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * 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 { CommentType } from '../../../../common/api'; | ||
| import type { Comment } from '../../../containers/types'; | ||
|
|
||
| export const getManualAlertIds = (comments: Comment[]): string[] => { | ||
| const dedupeAlerts = comments.reduce((alertIds, comment: Comment) => { | ||
| if (comment.type === CommentType.alert) { | ||
| const ids = Array.isArray(comment.alertId) ? comment.alertId : [comment.alertId]; | ||
| ids.forEach((id) => alertIds.add(id)); | ||
| return alertIds; | ||
| } | ||
| return alertIds; | ||
| }, new Set<string>()); | ||
| return Array.from(dedupeAlerts); | ||
| }; | ||
|
|
||
| export const getRegistrationContextFromAlerts = (comments: Comment[]): string[] => { | ||
| const dedupeRegistrationContext = comments.reduce((registrationContexts, comment: Comment) => { | ||
| if (comment.type === CommentType.alert) { | ||
| const indices = Array.isArray(comment.index) ? comment.index : [comment.index]; | ||
| indices.forEach((index) => { | ||
| // That's legacy code, we created some index alias so everything should work as expected | ||
| if (index.startsWith('.siem-signals')) { | ||
| registrationContexts.add('security'); | ||
| } else { | ||
| const registrationContext = getRegistrationContextFromIndex(index); | ||
| if (registrationContext) { | ||
| registrationContexts.add(registrationContext); | ||
| } | ||
| } | ||
| }); | ||
| return registrationContexts; | ||
| } | ||
| return registrationContexts; | ||
| }, new Set<string>()); | ||
| return Array.from(dedupeRegistrationContext); | ||
| }; | ||
|
|
||
| export const getRegistrationContextFromIndex = (indexName: string): string | null => { | ||
| const found = indexName.match(/\.alerts-(.*?).alerts/); | ||
| if (found && found.length > 1) { | ||
| return `${found[1]}`; | ||
| } | ||
| return null; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.