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.
feat(rca): add screen context into investigation details (elastic#194753
- Loading branch information
Showing
5 changed files
with
89 additions
and
1 deletion.
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
79 changes: 79 additions & 0 deletions
79
.../observability_solution/investigate_app/public/pages/details/hooks/use_screen_context.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,79 @@ | ||
/* | ||
* 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 { alertOriginSchema } from '@kbn/investigation-shared'; | ||
import { ALERT_REASON, ALERT_START, ALERT_STATUS } from '@kbn/rule-data-utils'; | ||
import type { EcsFieldsResponse } from '@kbn/rule-registry-plugin/common'; | ||
import dedent from 'dedent'; | ||
import { useEffect } from 'react'; | ||
import { useKibana } from '../../../hooks/use_kibana'; | ||
import { useInvestigation } from '../contexts/investigation_context'; | ||
import { useFetchAlert } from './use_fetch_alert'; | ||
|
||
export function useScreenContext() { | ||
const { | ||
dependencies: { | ||
start: { observabilityAIAssistant }, | ||
}, | ||
} = useKibana(); | ||
|
||
const { investigation } = useInvestigation(); | ||
const alertOriginInvestigation = alertOriginSchema.safeParse(investigation?.origin); | ||
const alertId = alertOriginInvestigation.success ? alertOriginInvestigation.data.id : undefined; | ||
const { data: alertDetails, isLoading: isAlertDetailsLoading } = useFetchAlert({ id: alertId }); | ||
|
||
useEffect(() => { | ||
if (!investigation || isAlertDetailsLoading) { | ||
return; | ||
} | ||
|
||
observabilityAIAssistant.service.setScreenContext({ | ||
screenDescription: dedent(` | ||
The user is looking at the details of an investigation in order to understand the root cause of an issue. | ||
The investigation details include the title, status, tags, and its time range. | ||
${alertDetails ? getAlertDetailScreenContext(alertDetails) : ''} | ||
Title: ${investigation.title} | ||
Tags: ${investigation.tags.join(', ')} | ||
Status: ${investigation.status} | ||
Start time: ${new Date(investigation.params.timeRange.from).toISOString()} | ||
End time: ${new Date(investigation.params.timeRange.to).toISOString()} | ||
`), | ||
data: [ | ||
{ | ||
name: 'investigation', | ||
description: 'The investigation details, including metadata, notes and items.', | ||
value: investigation, | ||
}, | ||
...(alertDetails | ||
? [ | ||
{ | ||
name: 'alert', | ||
description: 'The alert details that triggered the investigation.', | ||
value: alertDetails, | ||
}, | ||
] | ||
: []), | ||
], | ||
}); | ||
}, [observabilityAIAssistant, investigation, alertDetails, isAlertDetailsLoading]); | ||
} | ||
|
||
function getAlertDetailScreenContext(alertDetail: EcsFieldsResponse) { | ||
const alertState = alertDetail[ALERT_STATUS]; | ||
const alertStarted = alertDetail[ALERT_START]; | ||
|
||
return dedent(`The investigation originates from an ${alertState} alert which started at ${alertStarted}. | ||
${ | ||
alertDetail[ALERT_REASON] | ||
? `The reason given for the alert is ${alertDetail[ALERT_REASON]}.` | ||
: '' | ||
} | ||
`); | ||
} |
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