Skip to content

Commit

Permalink
Pass a legacy client to telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Feb 7, 2020
1 parent 75c76e1 commit f03b070
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 91 deletions.
12 changes: 7 additions & 5 deletions src/legacy/core_plugins/telemetry/server/collection_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { encryptTelemetry } from './collectors';
import { CallCluster } from '../../elasticsearch';
import { UsageCollectionSetup } from '../../../../plugins/usage_collection/server';
import { Cluster } from '../../elasticsearch';

export type EncryptedStatsGetterConfig = { unencrypted: false } & {
server: any;
Expand Down Expand Up @@ -55,14 +56,14 @@ export type StatsGetter = (
interface CollectionConfig {
title: string;
priority: number;
esCluster: string;
esCluster: string | Cluster;
statsGetter: StatsGetter;
clusterDetailsGetter: ClusterDetailsGetter;
}
interface Collection {
statsGetter: StatsGetter;
clusterDetailsGetter: ClusterDetailsGetter;
esCluster: string;
esCluster: string | Cluster;
title: string;
}

Expand Down Expand Up @@ -107,9 +108,10 @@ export class TelemetryCollectionManager {
): Promise<StatsCollectionConfig> => {
const { start, end } = config;
const server = config.unencrypted ? config.req.server : config.server;
const { callWithRequest, callWithInternalUser } = server.plugins.elasticsearch.getCluster(
collection.esCluster
);
const { callWithRequest, callWithInternalUser } =
typeof collection.esCluster === 'string'
? server.plugins.elasticsearch.getCluster(collection.esCluster)
: collection.esCluster;
const callCluster = config.unencrypted
? (...args: any[]) => callWithRequest(config.req, ...args)
: callWithInternalUser;
Expand Down
77 changes: 0 additions & 77 deletions x-pack/plugins/monitoring/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,80 +16,3 @@ export const config = {
};

export { getKibanaInfoForStats };

/**
* Invokes plugin modules to instantiate the Monitoring plugin for Kibana
* @param kibana {Object} Kibana plugin instance
* @return {Object} Monitoring UI Kibana plugin object
*/
// export const monitoring = kibana =>
// new kibana.Plugin({
// require: ['kibana', 'elasticsearch', 'xpack_main'],
// id: 'monitoring',
// configPrefix: 'monitoring',
// publicDir: resolve(__dirname, 'public'),
// init(server) {
// const configs = [
// 'monitoring.ui.enabled',
// 'monitoring.kibana.collection.enabled',
// 'monitoring.ui.max_bucket_size',
// 'monitoring.ui.min_interval_seconds',
// 'kibana.index',
// 'monitoring.ui.show_license_expiration',
// 'monitoring.ui.container.elasticsearch.enabled',
// 'monitoring.ui.container.logstash.enabled',
// 'monitoring.tests.cloud_detector.enabled',
// 'monitoring.kibana.collection.interval',
// 'monitoring.ui.elasticsearch.hosts',
// 'monitoring.ui.elasticsearch',
// 'monitoring.xpack_api_polling_frequency_millis',
// 'server.uuid',
// 'server.name',
// 'server.host',
// 'server.port',
// 'monitoring.cluster_alerts.email_notifications.enabled',
// 'monitoring.cluster_alerts.email_notifications.email_address',
// 'monitoring.ui.ccs.enabled',
// 'monitoring.ui.elasticsearch.logFetchCount',
// ];

// const serverConfig = server.config();
// const serverFacade = {
// config: () => ({
// get: key => {
// if (configs.includes(key)) {
// return serverConfig.get(key);
// }
// throw `Unknown key '${key}'`;
// },
// }),
// injectUiAppVars: server.injectUiAppVars,
// log: (...args) => server.log(...args),
// getOSInfo: server.getOSInfo,
// events: {
// on: (...args) => server.events.on(...args),
// },
// expose: (...args) => server.expose(...args),
// route: (...args) => server.route(...args),
// _hapi: server,
// _kbnServer: this.kbnServer,
// };
// const { usageCollection, licensing } = server.newPlatform.setup.plugins;
// const plugins = {
// xpack_main: server.plugins.xpack_main,
// elasticsearch: server.plugins.elasticsearch,
// infra: server.plugins.infra,
// usageCollection,
// licensing,
// };

// new Plugin().setup(serverFacade, plugins);
// },
// config,
// deprecations,
// uiExports: getUiExports(),
// postInit(server) {
// const serverConfig = server.config();
// initInfraSource(serverConfig, server.plugins.infra);
// },
// });
12 changes: 5 additions & 7 deletions x-pack/plugins/monitoring/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ export class Plugin {

constructor(initializerContext: PluginInitializerContext) {
this.initializerContext = initializerContext;
// this.configPromise = initializerContext.config
// .create<MonitoringConfig>()
// .pipe(first())
// .toPromise();
this.log = initializerContext.logger.get(LOGGING_TAG);
this.getLogger = (...scopes: string[]) => initializerContext.logger.get(LOGGING_TAG, ...scopes);
}
Expand Down Expand Up @@ -269,12 +265,14 @@ export class Plugin {
xpackMainPlugin: legacyApi.xpackMain,
// expose: core.expose,
});

// Initialize telemetry
if (this.cluster) {
registerMonitoringCollection(this.cluster, legacyApi.telemetryCollectionManager);
}
}
// });

// Initialize telemetry
registerMonitoringCollection(legacyApi.telemetryCollectionManager);

// Register collector objects for stats to show up in the APIs
registerCollectors(this.plugins.usageCollection, {
elasticsearchPlugin: legacyApi.elasticsearch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ICustomClusterClient } from 'kibana/server';
import { Cluster } from 'src/legacy/core_plugins/elasticsearch';
// @ts-ignore
import { getAllStats } from './get_all_stats';
import { getClusterUuids } from './get_cluster_uuids';

export function registerMonitoringCollection(telemetryCollectionManager: any) {
export function registerMonitoringCollection(
cluster: ICustomClusterClient,
telemetryCollectionManager: any
) {
// Create a legacy wrapper since telemetry is still in the legacy plugins
const legacyCluster: Cluster = {
callWithRequest: async (req: any, endpoint: string, params: any) =>
cluster.asScoped(req).callAsCurrentUser(endpoint, params),
callWithInternalUser: () => {
throw new Error(
'callWithInternalUser is not supported in this context. Please use `callWithRequest`'
);
},
};
telemetryCollectionManager.setCollection({
esCluster: 'monitoring',
esCluster: legacyCluster,
title: 'monitoring',
priority: 2,
statsGetter: getAllStats,
Expand Down

0 comments on commit f03b070

Please sign in to comment.