import { IndexPatternsFetcher , FieldDescriptor , } from '../../../../../../src/plugins/data/server' ; import { APMRouteHandlerResources } from '../../routes/typings' ; import { withApmSpan } from '../../utils/with_apm_span' ; import { getApmIndices } from '../settings/apm_indices/get_apm_indices' ; import { getApmDataViewTitle } from './get_apm_data_view_title' ; export interface DataViewTitleAndFields { title : string ; timeFieldName : string ; fields : FieldDescriptor [ ] ; } export const getDynamicDataView = ( { config , context , logger , } ) => { return withApmSpan ( 'get_dynamic_data_view' , async ( ) => { const apmIndicies = await getApmIndices ( { savedObjectsClient : context . core . savedObjects . client , config , } ) ; const dataViewTitle = getApmDataViewTitle ( apmIndicies ) ; const DataViewsFetcher = new IndexPatternsFetcher ( context . core . elasticsearch . client . asCurrentUser ) ; try { const fields = await DataViewsFetcher . getFieldsForWildcard ( { pattern : dataViewTitle , } ) ; const dataView = { fields , timeFieldName : '@timestamp' , title : dataViewTitle , } ; return dataView ; } catch ( e ) { const notExists = e . output ?. statusCode === 404 ; if ( notExists ) { logger . error ( `Could not get dynamic data view because indices "${ dataViewTitle }" don't exist` ) ; return ; } throw e ; } } ) ; } ;