kibana/x-pack/plugins/rollup/server/plugin.ts
Matthew Kime a69870b950
[data / data views] Disable rollup functionality when rollup plugin is disabled (#162674)
## Summary

Rollup functionality will be disabled on serverless instances. The
`rollup` plugin will be disabled. While it won't be possible to create
rollups on serverless, it will be possible to import data view saved
objects which may be configured for use with rollups. We will make a
'best effort' to improve functionality as to help users transition away
from rollups.

- In classic environments, the `rollup` plugin will enable `dataViews`
and `data` plugin rollup functionality.
- The data plugin will run an async search instead of a rollup search.
- The data views plugin will fetch normal fields, omitting a query for
rollup fields - which would fail anyway.

Closes https://github.com/elastic/kibana/issues/152708

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-08-08 11:25:13 -05:00

113 lines
3.4 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { CoreSetup, Plugin, Logger, PluginInitializerContext } from '@kbn/core/server';
import { i18n } from '@kbn/i18n';
import { schema } from '@kbn/config-schema';
import { getCapabilitiesForRollupIndices } from '@kbn/data-plugin/server';
import { PLUGIN, CONFIG_ROLLUPS } from '../common';
import { Dependencies } from './types';
import { registerApiRoutes } from './routes';
import { License } from './services';
import { registerRollupUsageCollector } from './collectors';
import { rollupDataEnricher } from './rollup_data_enricher';
import { IndexPatternsFetcher } from './shared_imports';
import { handleEsError } from './shared_imports';
import { formatEsError } from './lib/format_es_error';
export class RollupPlugin implements Plugin<void, void, any, any> {
private readonly logger: Logger;
private readonly license: License;
constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
this.license = new License();
}
public setup(
{ http, uiSettings, getStartServices }: CoreSetup,
{ features, licensing, indexManagement, usageCollection, dataViews, data }: Dependencies
) {
this.license.setup(
{
pluginId: PLUGIN.ID,
minimumLicenseType: PLUGIN.minimumLicenseType,
defaultErrorMessage: i18n.translate('xpack.rollupJobs.licenseCheckErrorMessage', {
defaultMessage: 'License check failed',
}),
},
{
licensing,
logger: this.logger,
}
);
features.registerElasticsearchFeature({
id: 'rollup_jobs',
management: {
data: ['rollup_jobs'],
},
catalogue: ['rollup_jobs'],
privileges: [
{
requiredClusterPrivileges: ['manage_rollup'],
ui: [],
},
],
});
registerApiRoutes({
router: http.createRouter(),
license: this.license,
lib: {
handleEsError,
formatEsError,
getCapabilitiesForRollupIndices,
},
sharedImports: {
IndexPatternsFetcher,
},
});
uiSettings.register({
[CONFIG_ROLLUPS]: {
name: i18n.translate('xpack.rollupJobs.rollupDataViewsTitle', {
defaultMessage: 'Enable rollup data views',
}),
value: true,
description: i18n.translate('xpack.rollupJobs.rollupDataViewsDescription', {
defaultMessage: `Enable the creation of data views that capture rollup indices,
which in turn enable visualizations based on rollup data.`,
}),
category: ['rollups'],
schema: schema.boolean(),
requiresPageReload: true,
},
});
if (usageCollection) {
try {
const getIndexForType = (type: string) =>
getStartServices().then(([coreStart]) => coreStart.savedObjects.getIndexForType(type));
registerRollupUsageCollector(usageCollection, getIndexForType);
} catch (e) {
this.logger.warn(`Registering Rollup collector failed: ${e}`);
}
}
if (indexManagement && indexManagement.indexDataEnricher) {
indexManagement.indexDataEnricher.add(rollupDataEnricher);
}
dataViews.enableRollups();
data.search.enableRollups();
}
start() {}
stop() {}
}