import { first } from 'rxjs/operators' ; import { CoreSetup , Plugin , PluginInitializerContext } from 'opensearch-dashboards/server' ; import { registerDqlTelemetryRoute } from './route' ; import { UsageCollectionSetup } from '../../../usage_collection/server' ; import { makeDQLUsageCollector } from './usage_collector' ; import { dqlTelemetry } from '../saved_objects' ; export class DqlTelemetryService implements Plugin < void > { constructor ( private initializerContext ) { } public setup ( { http , getStartServices , savedObjects } , { usageCollection } ) { savedObjects . registerType ( dqlTelemetry ) ; registerDqlTelemetryRoute ( http . createRouter ( ) , getStartServices , this . initializerContext . logger . get ( 'data' , 'dql-telemetry' ) ) ; if ( usageCollection ) { this . initializerContext . config . legacy . globalConfig$ . pipe ( first ( ) ) . toPromise ( ) . then ( ( config ) => makeDQLUsageCollector ( usageCollection , config . opensearchDashboards . index ) ) . catch ( ( e ) => { this . initializerContext . logger . get ( 'dql-telemetry' ) . warn ( `Registering DQL telemetry collector failed: ${ e }` ) ; } ) ; } } public start ( ) { } }