import { first } from 'rxjs/operators' ; import { PluginInitializerContext , Logger , CoreSetup , CoreStart , ISavedObjectsRepository , Plugin , } from 'opensearch-dashboards/server' ; import { ConfigType } from './config' ; import { CollectorSet } from './collector' ; import { setupRoutes } from './routes' ; export type UsageCollectionSetup = CollectorSet ; export class UsageCollectionPlugin implements Plugin < CollectorSet > { private readonly logger : Logger ; private savedObjects ? : ISavedObjectsRepository ; constructor ( private readonly initializerContext ) { this . logger = this . initializerContext . logger . get ( ) ; } public async setup ( core ) { const config = await this . initializerContext . config . create < ConfigType > ( ) . pipe ( first ( ) ) . toPromise ( ) ; const collectorSet = new CollectorSet ( { logger : this . logger . get ( 'collector-set' ) , maximumWaitTimeForAllCollectorsInS : config . maximumWaitTimeForAllCollectorsInS , } ) ; const globalConfig = await this . initializerContext . config . legacy . globalConfig$ . pipe ( first ( ) ) . toPromise ( ) ; const router = core . http . createRouter ( ) ; setupRoutes ( { router , getSavedObjects : ( ) => this . savedObjects , collectorSet , config : { allowAnonymous : core . status . isStatusPageAnonymous ( ) , opensearchDashboardsIndex : globalConfig . opensearchDashboards . index , opensearchDashboardsVersion : this . initializerContext . env . packageInfo . version , server : core . http . getServerInfo ( ) , uuid : this . initializerContext . env . instanceUuid , } , metrics : core . metrics , overallStatus$ : core . status . overall$ , } ) ; return collectorSet ; } public start ( { savedObjects } ) { this . logger . debug ( 'Starting plugin' ) ; this . savedObjects = savedObjects . createInternalRepository ( ) ; } public stop ( ) { this . logger . debug ( 'Stopping plugin' ) ; } }