-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
# Backport This will backport the following commits from `main` to `8.x`: - [feat(rca): display investigations stats (#193069)](#193069) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Kevin Delemme","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-16T21:22:03Z","message":"feat(rca): display investigations stats (#193069)","sha":"bb1898ec8f56fd77cfe0858cce243d714e788194","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","ci:project-deploy-observability","Team:obs-ux-management","v8.16.0"],"title":"feat(rca): display investigations stats","number":193069,"url":"https://github.com/elastic/kibana/pull/193069","mergeCommit":{"message":"feat(rca): display investigations stats (#193069)","sha":"bb1898ec8f56fd77cfe0858cce243d714e788194"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193069","number":193069,"mergeCommit":{"message":"feat(rca): display investigations stats (#193069)","sha":"bb1898ec8f56fd77cfe0858cce243d714e788194"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Kevin Delemme <[email protected]>
- Loading branch information
1 parent
7823f1c
commit d00d65b
Showing
12 changed files
with
286 additions
and
8 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
packages/kbn-investigation-shared/src/rest_specs/get_all_investigation_stats.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,25 @@ | ||
/* | ||
* 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 { z } from '@kbn/zod'; | ||
import { statusSchema } from '../schema'; | ||
|
||
const getAllInvestigationStatsParamsSchema = z.object({ | ||
query: z.object({}), | ||
}); | ||
|
||
const getAllInvestigationStatsResponseSchema = z.object({ | ||
count: z.record(statusSchema, z.number()), | ||
total: z.number(), | ||
}); | ||
|
||
type GetAllInvestigationStatsResponse = z.output<typeof getAllInvestigationStatsResponseSchema>; | ||
|
||
export { getAllInvestigationStatsParamsSchema, getAllInvestigationStatsResponseSchema }; | ||
export type { GetAllInvestigationStatsResponse }; |
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
73 changes: 73 additions & 0 deletions
73
.../observability_solution/investigate_app/public/hooks/use_fetch_all_investigation_stats.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,73 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
import type { GetAllInvestigationStatsResponse, Status } from '@kbn/investigation-shared'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { investigationKeys } from './query_key_factory'; | ||
import { useKibana } from './use_kibana'; | ||
|
||
export interface Response { | ||
isInitialLoading: boolean; | ||
isLoading: boolean; | ||
isRefetching: boolean; | ||
isSuccess: boolean; | ||
isError: boolean; | ||
data: { count: Record<Status, number>; total: number } | undefined; | ||
} | ||
|
||
export function useFetchAllInvestigationStats(): Response { | ||
const { | ||
core: { | ||
http, | ||
notifications: { toasts }, | ||
}, | ||
} = useKibana(); | ||
|
||
const { isInitialLoading, isLoading, isError, isSuccess, isRefetching, data } = useQuery({ | ||
queryKey: investigationKeys.stats(), | ||
queryFn: async ({ signal }) => { | ||
const response = await http.get<GetAllInvestigationStatsResponse>( | ||
`/api/observability/investigations/_stats`, | ||
{ | ||
version: '2023-10-31', | ||
signal, | ||
} | ||
); | ||
|
||
return { | ||
count: { | ||
triage: response.count.triage ?? 0, | ||
active: response.count.active ?? 0, | ||
mitigated: response.count.mitigated ?? 0, | ||
resolved: response.count.resolved ?? 0, | ||
cancelled: response.count.cancelled ?? 0, | ||
}, | ||
total: response.total ?? 0, | ||
}; | ||
}, | ||
retry: false, | ||
cacheTime: 600 * 1000, // 10 minutes | ||
staleTime: 0, | ||
onError: (error: Error) => { | ||
toasts.addError(error, { | ||
title: i18n.translate('xpack.investigateApp.useFetchAllInvestigationStats.errorTitle', { | ||
defaultMessage: 'Something went wrong while fetching the investigation stats', | ||
}), | ||
}); | ||
}, | ||
}); | ||
|
||
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
83 changes: 83 additions & 0 deletions
83
...servability_solution/investigate_app/public/pages/list/components/investigation_stats.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,83 @@ | ||
/* | ||
* 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 numeral from '@elastic/numeral'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiStat } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import { useFetchAllInvestigationStats } from '../../../hooks/use_fetch_all_investigation_stats'; | ||
import { useKibana } from '../../../hooks/use_kibana'; | ||
|
||
export function InvestigationStats() { | ||
const { | ||
core: { uiSettings }, | ||
} = useKibana(); | ||
const { data, isLoading: isStatsLoading } = useFetchAllInvestigationStats(); | ||
const numberFormat = uiSettings.get('format:number:defaultPattern'); | ||
|
||
return ( | ||
<EuiPanel hasBorder={true}> | ||
<EuiFlexGroup> | ||
<EuiFlexItem> | ||
<EuiStat | ||
title={numeral(data?.count.triage).format(numberFormat)} | ||
description={i18n.translate( | ||
'xpack.investigateApp.investigationList.stats.triageLabel', | ||
{ defaultMessage: 'Triage' } | ||
)} | ||
titleSize="s" | ||
isLoading={isStatsLoading} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiStat | ||
title={numeral(data?.count.active).format(numberFormat)} | ||
description={i18n.translate( | ||
'xpack.investigateApp.investigationList.stats.activeLabel', | ||
{ defaultMessage: 'Active' } | ||
)} | ||
titleSize="s" | ||
isLoading={isStatsLoading} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiStat | ||
title={numeral(data?.count.cancelled).format(numberFormat)} | ||
description={i18n.translate( | ||
'xpack.investigateApp.investigationList.stats.cancelledLabel', | ||
{ defaultMessage: 'Cancelled' } | ||
)} | ||
titleSize="s" | ||
isLoading={isStatsLoading} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiStat | ||
title={numeral(data?.count.mitigated).format(numberFormat)} | ||
description={i18n.translate( | ||
'xpack.investigateApp.investigationList.stats.mitigatedLabel', | ||
{ defaultMessage: 'Mitigated' } | ||
)} | ||
titleSize="s" | ||
isLoading={isStatsLoading} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiStat | ||
title={numeral(data?.count.resolved).format(numberFormat)} | ||
description={i18n.translate( | ||
'xpack.investigateApp.investigationList.stats.resolvedLabel', | ||
{ defaultMessage: 'Resolved' } | ||
)} | ||
titleSize="s" | ||
isLoading={isStatsLoading} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
} |
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
19 changes: 19 additions & 0 deletions
19
...ins/observability_solution/investigate_app/server/services/get_all_investigation_stats.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,19 @@ | ||
/* | ||
* 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 { | ||
GetAllInvestigationStatsResponse, | ||
getAllInvestigationStatsResponseSchema, | ||
} from '@kbn/investigation-shared'; | ||
import { InvestigationRepository } from './investigation_repository'; | ||
|
||
export async function getAllInvestigationStats( | ||
repository: InvestigationRepository | ||
): Promise<GetAllInvestigationStatsResponse> { | ||
const stats = await repository.getStats(); | ||
return getAllInvestigationStatsResponseSchema.parse(stats); | ||
} |
Oops, something went wrong.