[Monitoring] Change license service to use recommended API (#93620)
* Change license service to use recommended API * Remove unused type * Update this code too * Generate docs * New docs
This commit is contained in:
parent
644e08b94f
commit
46253d6ae2
|
@ -5498,17 +5498,11 @@
|
|||
"type": "Function",
|
||||
"children": [
|
||||
{
|
||||
"type": "CompoundType",
|
||||
"type": "Any",
|
||||
"label": "error",
|
||||
"isRequired": false,
|
||||
"isRequired": true,
|
||||
"signature": [
|
||||
{
|
||||
"pluginId": "ml",
|
||||
"scope": "common",
|
||||
"docId": "kibMlPluginApi",
|
||||
"section": "def-common.ErrorType",
|
||||
"text": "ErrorType"
|
||||
}
|
||||
"any"
|
||||
],
|
||||
"description": [],
|
||||
"source": {
|
||||
|
@ -5518,9 +5512,7 @@
|
|||
}
|
||||
],
|
||||
"signature": [
|
||||
"(error: ",
|
||||
"ErrorType",
|
||||
") => string"
|
||||
"(error: any) => string"
|
||||
],
|
||||
"description": [],
|
||||
"label": "extractErrorMessage",
|
||||
|
|
|
@ -46,6 +46,34 @@
|
|||
"signature": [
|
||||
"() => void"
|
||||
]
|
||||
},
|
||||
{
|
||||
"tags": [],
|
||||
"id": "def-server.IBulkUploader.start",
|
||||
"type": "Function",
|
||||
"label": "start",
|
||||
"description": [],
|
||||
"source": {
|
||||
"path": "x-pack/plugins/monitoring/server/types.ts",
|
||||
"lineNumber": 95
|
||||
},
|
||||
"signature": [
|
||||
"() => void"
|
||||
]
|
||||
},
|
||||
{
|
||||
"tags": [],
|
||||
"id": "def-server.IBulkUploader.handleNotEnabled",
|
||||
"type": "Function",
|
||||
"label": "handleNotEnabled",
|
||||
"description": [],
|
||||
"source": {
|
||||
"path": "x-pack/plugins/monitoring/server/types.ts",
|
||||
"lineNumber": 96
|
||||
},
|
||||
"signature": [
|
||||
"() => void"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
|
@ -106,7 +134,7 @@
|
|||
"description": [],
|
||||
"source": {
|
||||
"path": "x-pack/plugins/monitoring/server/types.ts",
|
||||
"lineNumber": 98
|
||||
"lineNumber": 100
|
||||
},
|
||||
"signature": [
|
||||
"() => any"
|
||||
|
@ -115,7 +143,7 @@
|
|||
],
|
||||
"source": {
|
||||
"path": "x-pack/plugins/monitoring/server/types.ts",
|
||||
"lineNumber": 97
|
||||
"lineNumber": 99
|
||||
},
|
||||
"lifecycle": "setup",
|
||||
"initialIsOpen": true
|
||||
|
|
|
@ -146,8 +146,8 @@ export function createFilterForTime(options) {
|
|||
* @param {Object} req Request object from the API route
|
||||
* @param {String} cluster The cluster being checked
|
||||
*/
|
||||
export function alertsClusterSearch(req, alertsIndex, cluster, checkLicense, options = {}) {
|
||||
const verification = verifyMonitoringLicense(req.server);
|
||||
export async function alertsClusterSearch(req, alertsIndex, cluster, checkLicense, options = {}) {
|
||||
const verification = await verifyMonitoringLicense(req.server);
|
||||
|
||||
if (!verification.enabled) {
|
||||
return Promise.resolve({ message: verification.message });
|
||||
|
|
|
@ -9,8 +9,8 @@ import { get, find } from 'lodash';
|
|||
import { verifyMonitoringLicense } from './verify_monitoring_license';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
export function alertsClustersAggregation(req, alertsIndex, clusters, checkLicense) {
|
||||
const verification = verifyMonitoringLicense(req.server);
|
||||
export async function alertsClustersAggregation(req, alertsIndex, clusters, checkLicense) {
|
||||
const verification = await verifyMonitoringLicense(req.server);
|
||||
|
||||
if (!verification.enabled) {
|
||||
// return metadata detailing that alerts is disabled because of the monitoring cluster license
|
||||
|
|
|
@ -16,17 +16,18 @@ import { i18n } from '@kbn/i18n';
|
|||
* @param {Object} server Server object containing config and plugins
|
||||
* @return {Boolean} {@code true} to indicate that cluster alerts can be used.
|
||||
*/
|
||||
export function verifyMonitoringLicense(server) {
|
||||
export async function verifyMonitoringLicense(server) {
|
||||
const config = server.config();
|
||||
|
||||
// if cluster alerts are enabled, then ensure that we can use it according to the license
|
||||
if (config.get('monitoring.cluster_alerts.enabled')) {
|
||||
const xpackInfo = get(server.plugins.monitoring, 'info');
|
||||
if (xpackInfo) {
|
||||
const watcherFeature = xpackInfo.getWatcherFeature();
|
||||
const licenseService = await xpackInfo.getLicenseService();
|
||||
const watcherFeature = licenseService.getWatcherFeature();
|
||||
return {
|
||||
enabled: watcherFeature.isEnabled,
|
||||
message: xpackInfo.getMessage(),
|
||||
message: licenseService.getMessage(),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -127,8 +127,8 @@ export async function getClustersFromRequest(
|
|||
clusters.map((cluster) => cluster.cluster_uuid)
|
||||
);
|
||||
|
||||
const verification = await verifyMonitoringLicense(req.server);
|
||||
for (const cluster of clusters) {
|
||||
const verification = verifyMonitoringLicense(req.server);
|
||||
if (!verification.enabled) {
|
||||
// return metadata detailing that alerts is disabled because of the monitoring cluster license
|
||||
cluster.alerts = {
|
||||
|
|
|
@ -20,7 +20,8 @@ export async function verifyMonitoringAuth(req) {
|
|||
const xpackInfo = get(req.server.plugins.monitoring, 'info');
|
||||
|
||||
if (xpackInfo) {
|
||||
const security = xpackInfo.getSecurityFeature();
|
||||
const licenseService = await xpackInfo.getLicenseService();
|
||||
const security = licenseService.getSecurityFeature();
|
||||
|
||||
// we only need to verify permissions if we're using X-Pack Security
|
||||
if (security.isAvailable && security.isEnabled) {
|
||||
|
|
|
@ -234,7 +234,8 @@ function isBeatFromAPM(bucket) {
|
|||
}
|
||||
|
||||
async function hasNecessaryPermissions(req) {
|
||||
const securityFeature = req.server.plugins.monitoring.info.getSecurityFeature();
|
||||
const licenseService = await req.server.plugins.monitoring.info.getLicenseService();
|
||||
const securityFeature = licenseService.getSecurityFeature();
|
||||
if (!securityFeature.isAvailable || !securityFeature.isEnabled) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -47,12 +47,14 @@ const mockReq = (
|
|||
plugins: {
|
||||
monitoring: {
|
||||
info: {
|
||||
getSecurityFeature: () => {
|
||||
return {
|
||||
isAvailable: securityEnabled,
|
||||
isEnabled: securityEnabled,
|
||||
};
|
||||
},
|
||||
getLicenseService: () => ({
|
||||
getSecurityFeature: () => {
|
||||
return {
|
||||
isAvailable: securityEnabled,
|
||||
isEnabled: securityEnabled,
|
||||
};
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
elasticsearch: {
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
import { Subscription } from 'rxjs';
|
||||
import { ILegacyCustomClusterClient } from 'kibana/server';
|
||||
import { ILicense, LicenseFeature } from '../../licensing/common/types';
|
||||
import { LicensingPluginSetup } from '../../licensing/server';
|
||||
import { LicensingPluginStart } from '../../licensing/server';
|
||||
import { MonitoringConfig } from './config';
|
||||
import { Logger } from '../../../../src/core/server';
|
||||
import { MonitoringLicenseService } from './types';
|
||||
|
||||
interface SetupDeps {
|
||||
licensing: LicensingPluginSetup;
|
||||
licensing: LicensingPluginStart;
|
||||
monitoringClient: ILegacyCustomClusterClient;
|
||||
config: MonitoringConfig;
|
||||
log: Logger;
|
||||
|
|
|
@ -105,15 +105,6 @@ export class MonitoringPlugin
|
|||
core.elasticsearch.legacy.createClient
|
||||
));
|
||||
|
||||
// Start our license service which will ensure
|
||||
// the appropriate licenses are present
|
||||
this.licenseService = new LicenseService().setup({
|
||||
licensing: plugins.licensing,
|
||||
monitoringClient: cluster,
|
||||
config,
|
||||
log: this.log,
|
||||
});
|
||||
|
||||
Globals.init(core, plugins.cloud, cluster, config, this.getLogger);
|
||||
const serverInfo = core.http.getServerInfo();
|
||||
const alerts = AlertsFactory.getAll();
|
||||
|
@ -165,34 +156,6 @@ export class MonitoringPlugin
|
|||
},
|
||||
}));
|
||||
|
||||
// If collection is enabled, start it
|
||||
const kibanaCollectionEnabled = config.kibana.collection.enabled;
|
||||
if (kibanaCollectionEnabled) {
|
||||
// Do not use `this.licenseService` as that looks at the monitoring cluster
|
||||
// whereas we want to check the production cluster here
|
||||
if (plugins.licensing) {
|
||||
plugins.licensing.license$.subscribe((license: any) => {
|
||||
// use updated xpack license info to start/stop bulk upload
|
||||
const mainMonitoring = license.getFeature('monitoring');
|
||||
const monitoringBulkEnabled =
|
||||
mainMonitoring && mainMonitoring.isAvailable && mainMonitoring.isEnabled;
|
||||
if (monitoringBulkEnabled) {
|
||||
bulkUploader.start();
|
||||
} else {
|
||||
bulkUploader.handleNotEnabled();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
kibanaMonitoringLog.warn(
|
||||
'Internal collection for Kibana monitoring is disabled due to missing license information.'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
kibanaMonitoringLog.info(
|
||||
'Internal collection for Kibana monitoring is disabled per configuration.'
|
||||
);
|
||||
}
|
||||
|
||||
// If the UI is enabled, then we want to register it so it shows up
|
||||
// and start any other UI-related setup tasks
|
||||
if (config.ui.enabled) {
|
||||
|
@ -201,7 +164,6 @@ export class MonitoringPlugin
|
|||
config,
|
||||
legacyConfig,
|
||||
core.getStartServices as () => Promise<[CoreStart, PluginsStart, {}]>,
|
||||
this.licenseService,
|
||||
this.cluster,
|
||||
plugins
|
||||
);
|
||||
|
@ -224,7 +186,46 @@ export class MonitoringPlugin
|
|||
};
|
||||
}
|
||||
|
||||
start() {}
|
||||
async start(core: CoreStart, { licensing }: PluginsStart) {
|
||||
const config = createConfig(this.initializerContext.config.get<TypeOf<typeof configSchema>>());
|
||||
// Start our license service which will ensure
|
||||
// the appropriate licenses are present
|
||||
this.licenseService = new LicenseService().setup({
|
||||
licensing,
|
||||
monitoringClient: this.cluster,
|
||||
config,
|
||||
log: this.log,
|
||||
});
|
||||
|
||||
// If collection is enabled, start it
|
||||
const kibanaMonitoringLog = this.getLogger(KIBANA_MONITORING_LOGGING_TAG);
|
||||
const kibanaCollectionEnabled = config.kibana.collection.enabled;
|
||||
if (kibanaCollectionEnabled) {
|
||||
// Do not use `this.licenseService` as that looks at the monitoring cluster
|
||||
// whereas we want to check the production cluster here
|
||||
if (this.bulkUploader && licensing) {
|
||||
licensing.license$.subscribe((license: any) => {
|
||||
// use updated xpack license info to start/stop bulk upload
|
||||
const mainMonitoring = license.getFeature('monitoring');
|
||||
const monitoringBulkEnabled =
|
||||
mainMonitoring && mainMonitoring.isAvailable && mainMonitoring.isEnabled;
|
||||
if (monitoringBulkEnabled) {
|
||||
this.bulkUploader?.start();
|
||||
} else {
|
||||
this.bulkUploader?.handleNotEnabled();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
kibanaMonitoringLog.warn(
|
||||
'Internal collection for Kibana monitoring is disabled due to missing license information.'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
kibanaMonitoringLog.info(
|
||||
'Internal collection for Kibana monitoring is disabled per configuration.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
stop() {
|
||||
if (this.cluster) {
|
||||
|
@ -276,7 +277,6 @@ export class MonitoringPlugin
|
|||
config: MonitoringConfig,
|
||||
legacyConfig: any,
|
||||
getCoreServices: () => Promise<[CoreStart, PluginsStart, {}]>,
|
||||
licenseService: MonitoringLicenseService,
|
||||
cluster: ILegacyCustomClusterClient,
|
||||
setupPlugins: PluginsSetup
|
||||
): MonitoringCore {
|
||||
|
@ -343,7 +343,9 @@ export class MonitoringPlugin
|
|||
},
|
||||
plugins: {
|
||||
monitoring: {
|
||||
info: licenseService,
|
||||
info: {
|
||||
getLicenseService: () => this.licenseService,
|
||||
},
|
||||
},
|
||||
elasticsearch: {
|
||||
getCluster: (name: string) => ({
|
||||
|
|
|
@ -25,7 +25,7 @@ import {
|
|||
PluginSetupContract as AlertingPluginSetupContract,
|
||||
} from '../../alerting/server';
|
||||
import { InfraPluginSetup } from '../../infra/server';
|
||||
import { LicensingPluginSetup } from '../../licensing/server';
|
||||
import { LicensingPluginStart } from '../../licensing/server';
|
||||
import { PluginSetupContract as FeaturesPluginSetupContract } from '../../features/server';
|
||||
import { EncryptedSavedObjectsPluginSetup } from '../../encrypted_saved_objects/server';
|
||||
import { CloudSetup } from '../../cloud/server';
|
||||
|
@ -47,7 +47,6 @@ export interface MonitoringElasticsearchConfig {
|
|||
export interface PluginsSetup {
|
||||
encryptedSavedObjects?: EncryptedSavedObjectsPluginSetup;
|
||||
usageCollection?: UsageCollectionSetup;
|
||||
licensing: LicensingPluginSetup;
|
||||
features: FeaturesPluginSetupContract;
|
||||
alerting?: AlertingPluginSetupContract;
|
||||
infra: InfraPluginSetup;
|
||||
|
@ -62,6 +61,7 @@ export interface RequestHandlerContextMonitoringPlugin extends RequestHandlerCon
|
|||
export interface PluginsStart {
|
||||
alerting: AlertingPluginStartContract;
|
||||
actions: ActionsPluginsStartContact;
|
||||
licensing: LicensingPluginStart;
|
||||
}
|
||||
|
||||
export interface MonitoringCoreConfig {
|
||||
|
@ -92,6 +92,8 @@ export interface LegacyShimDependencies {
|
|||
export interface IBulkUploader {
|
||||
getKibanaStats: () => any;
|
||||
stop: () => void;
|
||||
start: () => void;
|
||||
handleNotEnabled: () => void;
|
||||
}
|
||||
|
||||
export interface MonitoringPluginSetup {
|
||||
|
@ -127,7 +129,9 @@ export interface LegacyServer {
|
|||
};
|
||||
plugins: {
|
||||
monitoring: {
|
||||
info: MonitoringLicenseService;
|
||||
info: {
|
||||
getLicenseService: () => MonitoringLicenseService;
|
||||
};
|
||||
};
|
||||
elasticsearch: {
|
||||
getCluster: (
|
||||
|
|
Loading…
Reference in a new issue