-
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.
[8.8] Add SloGlobalDiagnosis check to SLO List and SLO Create pages (#…
…157488) (#157514) # Backport This will backport the following commits from `main` to `8.8`: - [Add SloGlobalDiagnosis check to SLO List and SLO Create pages (#157488)](#157488) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Coen Warmer","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-05-12T15:45:16Z","message":"Add SloGlobalDiagnosis check to SLO List and SLO Create pages (#157488)\n\nCo-authored-by: Kevin Delemme <[email protected]>\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"e75325653c88553454270bf412ddbed700fc022b","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:prev-minor","v8.8.0","v8.9.0"],"number":157488,"url":"https://github.com/elastic/kibana/pull/157488","mergeCommit":{"message":"Add SloGlobalDiagnosis check to SLO List and SLO Create pages (#157488)\n\nCo-authored-by: Kevin Delemme <[email protected]>\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"e75325653c88553454270bf412ddbed700fc022b"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/157488","number":157488,"mergeCommit":{"message":"Add SloGlobalDiagnosis check to SLO List and SLO Create pages (#157488)\n\nCo-authored-by: Kevin Delemme <[email protected]>\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"e75325653c88553454270bf412ddbed700fc022b"}}]}] BACKPORT--> Co-authored-by: Coen Warmer <[email protected]>
- Loading branch information
1 parent
e5132c7
commit 277be81
Showing
7 changed files
with
196 additions
and
37 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/observability/public/hooks/slo/helpers/convert_error_for_use_in_toast.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,15 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export function convertErrorForUseInToast(error: Error) { | ||
const newError = { | ||
...error, | ||
message: Object(error).body.message, | ||
}; | ||
|
||
return newError; | ||
} |
86 changes: 86 additions & 0 deletions
86
x-pack/plugins/observability/public/hooks/slo/use_fetch_global_diagnosis.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,86 @@ | ||
/* | ||
* 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 { | ||
QueryObserverResult, | ||
RefetchOptions, | ||
RefetchQueryFilters, | ||
useQuery, | ||
} from '@tanstack/react-query'; | ||
import { i18n } from '@kbn/i18n'; | ||
import type { PublicLicenseJSON } from '@kbn/licensing-plugin/public'; | ||
import type { SecurityGetUserPrivilegesResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import { useKibana } from '../../utils/kibana_react'; | ||
import { convertErrorForUseInToast } from './helpers/convert_error_for_use_in_toast'; | ||
|
||
interface SloGlobalDiagnosisResponse { | ||
licenseAndFeatures: PublicLicenseJSON; | ||
userPrivileges: SecurityGetUserPrivilegesResponse; | ||
sloResources: { | ||
[x: string]: 'OK' | 'NOT_OK'; | ||
}; | ||
} | ||
|
||
export interface UseFetchSloGlobalDiagnoseResponse { | ||
isInitialLoading: boolean; | ||
isLoading: boolean; | ||
isRefetching: boolean; | ||
isSuccess: boolean; | ||
isError: boolean; | ||
globalSloDiagnosis: SloGlobalDiagnosisResponse | undefined; | ||
refetch: <TPageData>( | ||
options?: (RefetchOptions & RefetchQueryFilters<TPageData>) | undefined | ||
) => Promise<QueryObserverResult<SloGlobalDiagnosisResponse | undefined, unknown>>; | ||
} | ||
|
||
export function useFetchSloGlobalDiagnosis(): UseFetchSloGlobalDiagnoseResponse { | ||
const { | ||
http, | ||
notifications: { toasts }, | ||
} = useKibana().services; | ||
|
||
const { isInitialLoading, isLoading, isError, isSuccess, isRefetching, data, refetch } = useQuery( | ||
{ | ||
queryKey: ['fetchSloGlobalDiagnosis'], | ||
queryFn: async ({ signal }) => { | ||
try { | ||
const response = await http.get<SloGlobalDiagnosisResponse>( | ||
'/internal/observability/slos/_diagnosis', | ||
{ | ||
query: {}, | ||
signal, | ||
} | ||
); | ||
|
||
return response; | ||
} catch (error) { | ||
throw convertErrorForUseInToast(error); | ||
} | ||
}, | ||
keepPreviousData: true, | ||
refetchOnWindowFocus: false, | ||
retry: false, | ||
onError: (error: Error) => { | ||
toasts.addError(error, { | ||
title: i18n.translate('xpack.observability.slo.globalDiagnosis.errorNotification', { | ||
defaultMessage: 'You do not have the right permissions to use this feature.', | ||
}), | ||
}); | ||
}, | ||
} | ||
); | ||
|
||
return { | ||
globalSloDiagnosis: data, | ||
isLoading, | ||
isInitialLoading, | ||
isRefetching, | ||
isSuccess, | ||
isError, | ||
refetch, | ||
}; | ||
} |
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
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