-
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.
Add SloGlobalDiagnosis check to SLO List and SLO Create pages (#157488)
Co-authored-by: Kevin Delemme <[email protected]> Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
30a3730
commit e753256
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