import { Observable } from 'rxjs' ; import { first } from 'rxjs/operators' ; import { LegacyAPICaller , SharedGlobalConfig } from 'opensearch-dashboards/server' ; import { Usage } from './register' ; interface SearchTelemetrySavedObject { 'search-telemetry' : Usage ; } export function fetchProvider ( config$ ) { return async ( callCluster ) : Promise < Usage > => { const config = await config$ . pipe ( first ( ) ) . toPromise ( ) ; const response = await callCluster < SearchTelemetrySavedObject > ( 'search' , { index : config . opensearchDashboards . index , body : { query : { term : { type : { value : 'search-telemetry' } } } , } , ignore : [ 404 ] , } ) ; return response . hits . hits . length ? response . hits . hits [ 0 ] . _source [ 'search-telemetry' ] : { successCount : 0 , errorCount : 0 , averageDuration : null , } ; } ; }