Skip to content

Commit

Permalink
[7.x] [Monitoring] Migrate server to NP (elastic#56675) (elastic#60796)
Browse files Browse the repository at this point in the history
* Backport 3a39602

* Remove unused code
  • Loading branch information
chrisronline authored Mar 21, 2020
1 parent f1965eb commit 8d9f39b
Show file tree
Hide file tree
Showing 388 changed files with 2,281 additions and 2,356 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';
import { ESLicense } from './telemetry_collection/get_local_license';

export type EncryptedStatsGetterConfig = { unencrypted: false } & {
Expand Down Expand Up @@ -70,7 +71,7 @@ export type LicenseGetter = (
interface CollectionConfig<T extends BasicStatsPayload> {
title: string;
priority: number;
esCluster: string;
esCluster: string | Cluster;
statsGetter: StatsGetter<T>;
clusterDetailsGetter: ClusterDetailsGetter;
licenseGetter: LicenseGetter;
Expand All @@ -79,7 +80,7 @@ interface Collection {
statsGetter: StatsGetter;
licenseGetter: LicenseGetter;
clusterDetailsGetter: ClusterDetailsGetter;
esCluster: string;
esCluster: string | Cluster;
title: string;
}

Expand Down Expand Up @@ -135,9 +136,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
2 changes: 1 addition & 1 deletion src/legacy/server/status/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export const KIBANA_STATS_TYPE = 'kibana_stats'; // kibana stats per 5s intervals
export const KIBANA_STATS_TYPE = 'oss_kibana_stats'; // kibana stats per 5s intervals
2 changes: 1 addition & 1 deletion x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"xpack.main": "legacy/plugins/xpack_main",
"xpack.maps": ["plugins/maps", "legacy/plugins/maps"],
"xpack.ml": ["plugins/ml", "legacy/plugins/ml"],
"xpack.monitoring": "legacy/plugins/monitoring",
"xpack.monitoring": ["plugins/monitoring", "legacy/plugins/monitoring"],
"xpack.remoteClusters": "plugins/remote_clusters",
"xpack.reporting": ["plugins/reporting", "legacy/plugins/reporting"],
"xpack.rollupJobs": "legacy/plugins/rollup",
Expand Down
8 changes: 3 additions & 5 deletions x-pack/legacy/plugins/monitoring/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS } from '../../server/lib/constants';

/**
* User-configurable settings for xpack.monitoring via configuration schema
* @param {Object} Joi - HapiJS Joi module that allows for schema validation
Expand Down Expand Up @@ -132,9 +130,9 @@ export const config = Joi => {
email_address: Joi.string().email(),
}).default(),
}).default(),
xpack_api_polling_frequency_millis: Joi.number().default(
XPACK_INFO_API_DEFAULT_POLL_FREQUENCY_IN_MILLIS
),
licensing: Joi.object({
api_polling_frequency: Joi.number().default(30001),
}),
agent: Joi.object({
interval: Joi.string()
.regex(/[\d\.]+[yMwdhms]/)
Expand Down
59 changes: 59 additions & 0 deletions x-pack/legacy/plugins/monitoring/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { get } from 'lodash';
import { resolve } from 'path';
import { config } from './config';
import { getUiExports } from './ui_exports';
import { KIBANA_ALERTING_ENABLED } from './common/constants';
import { telemetryCollectionManager } from '../../../../src/legacy/core_plugins/telemetry/server';

/**
* Invokes plugin modules to instantiate the Monitoring plugin for Kibana
* @param kibana {Object} Kibana plugin instance
* @return {Object} Monitoring UI Kibana plugin object
*/
const deps = ['kibana', 'elasticsearch', 'xpack_main'];
if (KIBANA_ALERTING_ENABLED) {
deps.push(...['alerting', 'actions']);
}
export const monitoring = kibana => {
return new kibana.Plugin({
require: deps,
id: 'monitoring',
configPrefix: 'monitoring',
publicDir: resolve(__dirname, 'public'),
init(server) {
const serverConfig = server.config();
const npMonitoring = server.newPlatform.setup.plugins.monitoring;
if (npMonitoring) {
const kbnServerStatus = this.kbnServer.status;
npMonitoring.registerLegacyAPI({
telemetryCollectionManager,
getServerStatus: () => {
const status = kbnServerStatus.toJSON();
return get(status, 'overall.state');
},
});
}

server.injectUiAppVars('monitoring', () => {
return {
maxBucketSize: serverConfig.get('monitoring.ui.max_bucket_size'),
minIntervalSeconds: serverConfig.get('monitoring.ui.min_interval_seconds'),
kbnIndex: serverConfig.get('kibana.index'),
showLicenseExpiration: serverConfig.get('monitoring.ui.show_license_expiration'),
showCgroupMetricsElasticsearch: serverConfig.get(
'monitoring.ui.container.elasticsearch.enabled'
),
showCgroupMetricsLogstash: serverConfig.get('monitoring.ui.container.logstash.enabled'), // Note, not currently used, but see https://github.com/elastic/x-pack-kibana/issues/1559 part 2
};
});
},
config,
uiExports: getUiExports(),
});
};
142 changes: 0 additions & 142 deletions x-pack/legacy/plugins/monitoring/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ uiRoutes
const globalState = $injector.get('globalState');
const storage = $injector.get('localStorage');
const showLicenseExpiration = $injector.get('showLicenseExpiration');

this.data = $route.current.locals.clusters;

$scope.$watch(
Expand Down
87 changes: 0 additions & 87 deletions x-pack/legacy/plugins/monitoring/server/__tests__/check_license.js

This file was deleted.

This file was deleted.

Loading

0 comments on commit 8d9f39b

Please sign in to comment.