Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SLO] Adding Data Views to index pattern selector (#158033)
## Summary This PR adds support for picking Data Views to the index selector for the Custom KQL indicator. However, this doesn't actually attach the Data View to the SLO definition, this is only a convenient way to re-use the index pattern defined in the Data View. Keep in mind that if a user updates a Data View, they will need to update the SLO as well since the SLO service uses transforms behind the scenes; transforms do not support Kibana Data Views and there isn't a way to detect when the Data View is updated to re-create the transform. This PR also filters out hidden indices OR indices whose names are prefixed with a dot. <img width="953" alt="image" src="https://github.com/elastic/kibana/assets/41702/ef477f63-f89d-4733-aa19-95138d735967">
- Loading branch information
1 parent
839da37
commit a9b13c0
Showing
2 changed files
with
117 additions
and
36 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/observability/public/hooks/use_fetch_data_views.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,46 @@ | ||
/* | ||
* 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 { DataView } from '@kbn/data-views-plugin/public'; | ||
import { useKibana } from '../utils/kibana_react'; | ||
|
||
export interface UseFetchDataViewsResponse { | ||
isLoading: boolean; | ||
isSuccess: boolean; | ||
isError: boolean; | ||
dataViews: DataView[] | undefined; | ||
refetch: <TPageData>( | ||
options?: (RefetchOptions & RefetchQueryFilters<TPageData>) | undefined | ||
) => Promise<QueryObserverResult<Index[], unknown>>; | ||
} | ||
export interface Index { | ||
name: string; | ||
} | ||
|
||
export function useFetchDataViews(): UseFetchDataViewsResponse { | ||
const { dataViews } = useKibana().services; | ||
|
||
const { isLoading, isError, isSuccess, data, refetch } = useQuery({ | ||
queryKey: ['fetchDataViews'], | ||
queryFn: async () => { | ||
try { | ||
const response = await dataViews.find(''); | ||
return response; | ||
} catch (error) { | ||
throw new Error(`Something went wrong. Error: ${error}`); | ||
} | ||
}, | ||
}); | ||
|
||
return { isLoading, isError, isSuccess, dataViews: data, 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