forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RCA] Start investigation from alert details page (elastic#190307)
Resolves elastic#190320 and elastic#190396 - Start investigation from Custom threshold alert details page - Go to ongoing investigation instead of creating new one if one already exists - Initial investigation status is set as `ongoing` - Investigation origin is set as `alert` "Start investigation" is hidden for other alert types and when investigate plugin is disabled. ### Testing - Add the following in `kibana.dev.yml` ``` xpack.investigate.enabled: true xpack.investigateApp.enabled: true ``` - Create Custom threshold rule - Open Custom threshold alert details page - Click on "Start investigation" - Verify that a new saved object is created for the investigation https://github.com/user-attachments/assets/6dfe8a5f-287b-4cc5-92ae-e4c315c7420b --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Kevin Delemme <[email protected]>
- Loading branch information
1 parent
abc8495
commit 95736fb
Showing
26 changed files
with
477 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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 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 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
File renamed without changes.
This file contains 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
17 changes: 17 additions & 0 deletions
17
x-pack/plugins/observability_solution/investigate/common/schema/origin.ts
This file contains 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,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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import * as t from 'io-ts'; | ||
|
||
const blankOriginSchema = t.type({ type: t.literal('blank') }); | ||
const alertOriginSchema = t.type({ type: t.literal('alert'), id: t.string }); | ||
|
||
type AlertOrigin = t.OutputOf<typeof alertOriginSchema>; | ||
type BlankOrigin = t.OutputOf<typeof blankOriginSchema>; | ||
|
||
export { alertOriginSchema, blankOriginSchema }; | ||
|
||
export type { AlertOrigin, BlankOrigin }; |
This file contains 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 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/observability_solution/investigate_app/public/hooks/use_get_alert_details.tsx
This file contains 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 { useQuery } from '@tanstack/react-query'; | ||
import { BASE_RAC_ALERTS_API_PATH, EcsFieldsResponse } from '@kbn/rule-registry-plugin/common'; | ||
import { useKibana } from './use_kibana'; | ||
|
||
export interface AlertParams { | ||
id: string; | ||
} | ||
|
||
export interface UseFetchAlertResponse { | ||
isInitialLoading: boolean; | ||
isLoading: boolean; | ||
isRefetching: boolean; | ||
isSuccess: boolean; | ||
isError: boolean; | ||
data: EcsFieldsResponse | undefined | null; | ||
} | ||
|
||
export function useFetchAlert({ id }: AlertParams): UseFetchAlertResponse { | ||
const { | ||
core: { | ||
http, | ||
notifications: { toasts }, | ||
}, | ||
} = useKibana(); | ||
|
||
const { isInitialLoading, isLoading, isError, isSuccess, isRefetching, data } = useQuery({ | ||
queryKey: ['fetchAlert', id], | ||
queryFn: async ({ signal }) => { | ||
return await http.get<EcsFieldsResponse>(BASE_RAC_ALERTS_API_PATH, { | ||
query: { | ||
id, | ||
}, | ||
signal, | ||
}); | ||
}, | ||
cacheTime: 0, | ||
refetchOnWindowFocus: false, | ||
retry: (failureCount, error) => { | ||
if (String(error) === 'Error: Forbidden') { | ||
return false; | ||
} | ||
|
||
return failureCount < 3; | ||
}, | ||
onError: (error: Error) => { | ||
toasts.addError(error, { | ||
title: 'Something went wrong while fetching alert', | ||
}); | ||
}, | ||
enabled: Boolean(id), | ||
}); | ||
|
||
return { | ||
data, | ||
isInitialLoading, | ||
isLoading, | ||
isRefetching, | ||
isSuccess, | ||
isError, | ||
}; | ||
} |
68 changes: 68 additions & 0 deletions
68
...ins/observability_solution/investigate_app/public/hooks/use_get_investigation_details.tsx
This file contains 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 { useQuery } from '@tanstack/react-query'; | ||
import { GetInvestigationResponse } from '@kbn/investigate-plugin/common/schema/get'; | ||
import { investigationKeys } from './query_key_factory'; | ||
import { useKibana } from './use_kibana'; | ||
|
||
export interface FetchInvestigationParams { | ||
id: string; | ||
} | ||
|
||
export interface UseFetchInvestigationResponse { | ||
isInitialLoading: boolean; | ||
isLoading: boolean; | ||
isRefetching: boolean; | ||
isSuccess: boolean; | ||
isError: boolean; | ||
data: GetInvestigationResponse | undefined; | ||
} | ||
|
||
export function useFetchInvestigation({ | ||
id, | ||
}: FetchInvestigationParams): UseFetchInvestigationResponse { | ||
const { | ||
core: { | ||
http, | ||
notifications: { toasts }, | ||
}, | ||
} = useKibana(); | ||
|
||
const { isInitialLoading, isLoading, isError, isSuccess, isRefetching, data } = useQuery({ | ||
queryKey: investigationKeys.fetch({ id }), | ||
queryFn: async ({ signal }) => { | ||
return await http.get<GetInvestigationResponse>(`/api/observability/investigations/${id}`, { | ||
version: '2023-10-31', | ||
signal, | ||
}); | ||
}, | ||
cacheTime: 0, | ||
refetchOnWindowFocus: false, | ||
retry: (failureCount, error) => { | ||
if (String(error) === 'Error: Forbidden') { | ||
return false; | ||
} | ||
|
||
return failureCount < 3; | ||
}, | ||
onError: (error: Error) => { | ||
toasts.addError(error, { | ||
title: 'Something went wrong while fetching Investigation', | ||
}); | ||
}, | ||
}); | ||
|
||
return { | ||
data, | ||
isInitialLoading, | ||
isLoading, | ||
isRefetching, | ||
isSuccess, | ||
isError, | ||
}; | ||
} |
This file contains 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 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 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 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.