Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting] New Platform Migration #56485

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/plugins/kibana_utils/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

export * from './defer';
export * from './of';
export { createGetterSetter, Get, Set } from './create_getter_setter';
export { distinctUntilChangedWithInitialValue } from './distinct_until_changed_with_initial_value';
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { createGetterSetter, Get, Set } from './create_getter_setter';
import { createGetterSetter, Get, Set } from '../../common';
import { CoreStart } from '../../../../core/public';
import { KUSavedObjectClient, createSavedObjectsClient } from './saved_objects_client';

Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana_utils/public/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@
* under the License.
*/

export * from './create_getter_setter';
export * from './create_kibana_utils_core';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { CoreStart } from '../../../../core/public';
import { Get } from './create_getter_setter';
import { Get } from '../../common';

type CoreSavedObjectClient = CoreStart['savedObjects']['client'];

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/kibana_utils/public/core/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { createGetterSetter } from './create_getter_setter';
import { createGetterSetter } from '../../common';
import { CoreStart } from '../../../../core/public';

export const [getCoreStart, setCoreStart] = createGetterSetter<CoreStart>('CoreStart');
2 changes: 1 addition & 1 deletion src/plugins/kibana_utils/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

export { defer, Defer, of } from '../common';
export { defer, Defer, of, createGetterSetter, Get, Set } from '../common';
export * from './core';
export * from './errors';
export * from './field_mapping';
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/kibana_utils/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { Get, Set, createGetterSetter } from '../common';
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { createGetterSetter } from '../../../../../../src/plugins/kibana_utils/public/core';
import { createGetterSetter } from '../../../../../../src/plugins/kibana_utils/public';
import { ExpressionsStart } from './types';

export const [getExpressions, setExpressions] = createGetterSetter<ExpressionsStart>('Expressions');
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CancellationToken } from '../../../common/cancellation_token';
import { fieldFormats } from '../../../../../../../src/plugins/data/server';
import { LevelLogger } from '../../../server/lib/level_logger';
import { executeJobFactory } from './execute_job';
import { setFieldFormats } from '../../../server/services';

const delay = ms => new Promise(resolve => setTimeout(() => resolve(), ms));

Expand Down Expand Up @@ -67,8 +68,7 @@ describe('CSV Execute Job', function() {
uiSettingsGetStub.withArgs('csv:separator').returns(',');
uiSettingsGetStub.withArgs('csv:quoteValues').returns(true);

mockServer = {
expose: function() {},
setFieldFormats({
fieldFormatServiceFactory: function() {
const uiConfigMock = {};
uiConfigMock['format:defaultTypeMap'] = {
Expand All @@ -81,6 +81,10 @@ describe('CSV Execute Job', function() {

return fieldFormatsRegistry;
},
});

mockServer = {
expose: function() {},
plugins: {
elasticsearch: {
getCluster: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ESQueueWorkerExecuteFn, ExecuteJobFactory, Logger, ServerFacade } from
import { JobDocPayloadDiscoverCsv } from '../types';
import { fieldFormatMapFactory } from './lib/field_format_map';
import { createGenerateCsv } from './lib/generate_csv';
import { getFieldFormats } from '../../../server/services';

export const executeJobFactory: ExecuteJobFactory<ESQueueWorkerExecuteFn<
JobDocPayloadDiscoverCsv
Expand Down Expand Up @@ -87,7 +88,7 @@ export const executeJobFactory: ExecuteJobFactory<ESQueueWorkerExecuteFn<

const [formatsMap, uiSettings] = await Promise.all([
(async () => {
const fieldFormats = await server.fieldFormatServiceFactory(uiConfig);
const fieldFormats = await getFieldFormats().fieldFormatServiceFactory(uiConfig);
return fieldFormatMapFactory(indexPatternSavedObject, fieldFormats);
})(),
(async () => {
Expand Down
44 changes: 2 additions & 42 deletions x-pack/legacy/plugins/reporting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@

import { i18n } from '@kbn/i18n';
import { Legacy } from 'kibana';
import { IUiSettingsClient } from 'kibana/server';
import { resolve } from 'path';
import { PluginStart as DataPluginStart } from '../../../../src/plugins/data/server';
import { PluginSetupContract as SecurityPluginSetup } from '../../../plugins/security/server';
import { PLUGIN_ID, UI_SETTINGS_CUSTOM_PDF_LOGO } from './common/constants';
import { config as reportingConfig } from './config';
import {
LegacySetup,
ReportingPlugin,
reportingPluginFactory,
ReportingSetupDeps,
} from './server/plugin';
import { legacyInit } from './server/legacy';
import { ReportingConfigOptions, ReportingPluginSpecOptions } from './types.d';

const kbToBase64Length = (kb: number) => {
return Math.floor((kb * 1024 * 8) / 6);
};

interface ReportingDeps {
data: DataPluginStart;
}

export const reporting = (kibana: any) => {
return new kibana.Plugin({
id: PLUGIN_ID,
Expand Down Expand Up @@ -73,35 +61,7 @@ export const reporting = (kibana: any) => {
},

async init(server: Legacy.Server) {
const coreSetup = server.newPlatform.setup.core;
const pluginsSetup: ReportingSetupDeps = {
security: server.newPlatform.setup.plugins.security as SecurityPluginSetup,
usageCollection: server.newPlatform.setup.plugins.usageCollection,
};

const fieldFormatServiceFactory = async (uiSettings: IUiSettingsClient) => {
const [, plugins] = await coreSetup.getStartServices();
const { fieldFormats } = (plugins as ReportingDeps).data;

return fieldFormats.fieldFormatServiceFactory(uiSettings);
};

const __LEGACY: LegacySetup = {
config: server.config,
info: server.info,
route: server.route.bind(server),
plugins: {
elasticsearch: server.plugins.elasticsearch,
xpack_main: server.plugins.xpack_main,
},
savedObjects: server.savedObjects,
fieldFormatServiceFactory,
uiSettingsServiceFactory: server.uiSettingsServiceFactory,
};

const initializerContext = server.newPlatform.coreContext;
const plugin: ReportingPlugin = reportingPluginFactory(initializerContext, __LEGACY, this);
await plugin.setup(coreSetup, pluginsSetup);
return legacyInit(server, this);
},

deprecations({ unused }: any) {
Expand Down
12 changes: 12 additions & 0 deletions x-pack/legacy/plugins/reporting/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 { PluginInitializerContext } from 'src/core/server';
import { ReportingPlugin as Plugin } from './plugin';

export const plugin = (context: PluginInitializerContext) => {
return new Plugin(context);
};
49 changes: 49 additions & 0 deletions x-pack/legacy/plugins/reporting/server/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 { Legacy } from 'kibana';
import { PluginInitializerContext } from 'src/core/server';
import { plugin } from './index';
import { LegacySetup, ReportingSetupDeps, ReportingStartDeps } from './plugin';
import { PluginSetupContract as SecurityPluginSetup } from '../../../../plugins/security/server';
import { PluginStart as DataPluginStart } from '../../../../../src/plugins/data/server';
import { ReportingPluginSpecOptions } from '../types';

const buildLegacyDependencies = (
server: Legacy.Server,
reportingPlugin: ReportingPluginSpecOptions
): LegacySetup => ({
config: server.config,
info: server.info,
route: server.route.bind(server),
plugins: {
elasticsearch: server.plugins.elasticsearch,
xpack_main: server.plugins.xpack_main,
reporting: reportingPlugin,
},
savedObjects: server.savedObjects,
uiSettingsServiceFactory: server.uiSettingsServiceFactory,
});

export const legacyInit = async (
server: Legacy.Server,
reportingPlugin: ReportingPluginSpecOptions
) => {
const coreSetup = server.newPlatform.setup.core;
const pluginInstance = plugin(server.newPlatform.coreContext as PluginInitializerContext);

await pluginInstance.setup(coreSetup, {
security: server.newPlatform.setup.plugins.security as SecurityPluginSetup,
usageCollection: server.newPlatform.setup.plugins.usageCollection,
__LEGACY: buildLegacyDependencies(server, reportingPlugin),
} as ReportingSetupDeps);

// Schedule to call the "start" hook only after start dependencies are ready
coreSetup.getStartServices().then(([core, plugins]) =>
pluginInstance.start(core, {
data: (plugins as any).data as DataPluginStart,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be: plugins as ReportingStartDeps

} as ReportingStartDeps)
);
};
Loading