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

[WIP] [Upgrade Assistant] Deprecations plugin #90957

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
19 changes: 19 additions & 0 deletions src/plugins/deprecations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# deprecations

A Kibana plugin

---

## Development

See the [kibana contributing guide](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md) for instructions setting up your development environment.

## Scripts

<dl>
<dt><code>yarn kbn bootstrap</code></dt>
<dd>Execute this to install node_modules and setup the dependencies in your plugin and in Kibana</dd>

<dt><code>yarn plugin-helpers build</code></dt>
<dd>Execute this to create a distributable version of this plugin that can be installed in Kibana</dd>
</dl>
10 changes: 10 additions & 0 deletions src/plugins/deprecations/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export const PLUGIN_ID = 'deprecations';
export const PLUGIN_NAME = 'deprecations';
13 changes: 13 additions & 0 deletions src/plugins/deprecations/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/src/plugins/deprecations'],
};
9 changes: 9 additions & 0 deletions src/plugins/deprecations/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "deprecations",
"version": "1.0.0",
"kibanaVersion": "kibana",
"server": true,
"ui": false,
"requiredPlugins": [],
"optionalPlugins": []
}
29 changes: 29 additions & 0 deletions src/plugins/deprecations/server/deprecations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { DeprecationInfo, DeprecationContext } from './types';

export class Deprecations {
private readonly deprecations: { [key: string]: DeprecationContext } = {};

public registerDeprecations = (deprecation: DeprecationContext) => {
if (this.deprecations[deprecation.pluginId]) {
throw new Error(`Plugin "${deprecation.pluginId}" is duplicated.`);
}

this.deprecations[deprecation.pluginId] = deprecation;
};

public getDeprecationInfoByPluginId = (pluginId: string) => {
return this.deprecations[pluginId];
};

public getDeprecationInfo = () => {
return this.deprecations;
};
}
15 changes: 15 additions & 0 deletions src/plugins/deprecations/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { PluginInitializerContext } from 'src/core/server';
import { DeprecationsPlugin } from './plugin';

export { DeprecationDependencies, DeprecationInfo, DeprecationContext } from './types';

export const plugin = (initializerContext: PluginInitializerContext) =>
new DeprecationsPlugin(initializerContext);
7 changes: 7 additions & 0 deletions src/plugins/deprecations/server/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
43 changes: 43 additions & 0 deletions src/plugins/deprecations/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { PluginInitializerContext, CoreSetup, CoreStart, Plugin, Logger } from 'src/core/server';

import { DeprecationsPluginSetup, DeprecationsPluginStart } from './types';
import { setupRoutes } from './routes';
import { Deprecations } from './deprecations';

export class DeprecationsPlugin
implements Plugin<DeprecationsPluginSetup, DeprecationsPluginStart> {
private readonly logger: Logger;

constructor(initializerContext: PluginInitializerContext) {
this.logger = initializerContext.logger.get();
}

public setup(core: CoreSetup) {
this.logger.debug('deprecations: Setup');

const deprecations = new Deprecations();
const router = core.http.createRouter();

// Register server side APIs
setupRoutes({ router, deprecations });

return deprecations;
}

public start(core: CoreStart) {
this.logger.debug('deprecations: Started');
return {};
}

public stop() {
this.logger.debug('Stopping plugin');
}
}
55 changes: 55 additions & 0 deletions src/plugins/deprecations/server/routes/deprecations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { IRouter } from 'src/core/server';
import { DeprecationDependencies, DeprecationInfo, DeprecationContext } from '../types';

export function registerDeprecationRoutes(router: IRouter, deprecations: any) {
router.get(
{
path: '/api/deprecations',
validate: false,
},
async (context, request, response) => {
const deprecationInfo: DeprecationContext = deprecations.getDeprecationInfo();

const dependencies: DeprecationDependencies = {
esClient: context.core.elasticsearch.client,
savedObjectsClient: context.core.savedObjects.client,
};

const pluginDeprecationsList = await Promise.all(
Object.entries(deprecationInfo).map(async ([pluginId, deprecationInfoContext]) => {
const pluginDeprecations: DeprecationInfo[] = await deprecationInfoContext.getDeprecations(
dependencies
);
const pluginDeprecationsWithId = pluginDeprecations.map((pluginDeprecation) => ({
...pluginDeprecation,
pluginId,
}));
return pluginDeprecationsWithId;
})
).catch((error) => {
// TODO handle error
// eslint-disable-next-line no-console
console.log('error', error);
});

const flattenedPluginDeprecationsList =
pluginDeprecationsList && pluginDeprecationsList.length
? pluginDeprecationsList.flat()
: [];

return response.ok({
body: {
deprecations: flattenedPluginDeprecationsList,
},
});
}
);
}
16 changes: 16 additions & 0 deletions src/plugins/deprecations/server/routes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { IRouter } from 'src/core/server';
import { registerDeprecationRoutes } from './deprecations';

export { DeprecationDependencies } from './deprecations';

export function setupRoutes({ router, deprecations }: { router: IRouter; deprecations: any }) {
registerDeprecationRoutes(router, deprecations);
}
39 changes: 39 additions & 0 deletions src/plugins/deprecations/server/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { IScopedClusterClient, SavedObjectsClientContract } from 'src/core/server';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DeprecationsPluginSetup {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DeprecationsPluginStart {}

export interface DeprecationDependencies {
esClient: IScopedClusterClient;
savedObjectsClient: SavedObjectsClientContract;
}
export interface DeprecationInfo {
message: string;
level: 'warning' | 'critical';
documentationUrl?: string;
correctionActions: {
api?: {
path: string;
method: 'POST' | 'PUT';
body?: {
[key: string]: any;
};
};
manualSteps?: string[];
};
}
export interface DeprecationContext {
pluginId: string;
getDeprecations: Promise<DeprecationInfo>;
}
21 changes: 21 additions & 0 deletions src/plugins/deprecations/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true
},
"include": [
"public/**/*",
"server/**/*",
"common/*",
"../../../typings/**/*"
],
"references": [
{
"path": "../../core/tsconfig.json"
},
]
}
3 changes: 2 additions & 1 deletion src/plugins/timelion/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"navigation",
"visTypeTimelion",
"savedObjects",
"kibanaLegacy"
"kibanaLegacy",
"deprecations"
]
}
44 changes: 44 additions & 0 deletions src/plugins/timelion/server/deprecations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { DeprecationDependencies } from 'src/plugins/deprecations/server';

export const getDeprecations = async ({ savedObjectsClient }: DeprecationDependencies) => {
const deprecations = [];

const getTimelionSheets = () =>
savedObjectsClient
.find({
type: 'timelion-sheet',
perPage: 1,
})
.then(({ total }: { total: number }) => total);

const timelionWorksheets = await getTimelionSheets();

if (timelionWorksheets > 0) {
deprecations.push({
message: `You have ${timelionWorksheets} Timelion worksheets. The Timelion app will be removed in 8.0. To continue using your Timelion worksheets, migrate them to a dashboard.`,
documentationUrl:
'https://www.elastic.co/guide/en/kibana/master/dashboard.html#timelion-deprecation',
level: 'warning',
correctiveActions: {
manualSteps: [
'Navigate to the Kibana Dashboard and click "Create dashboard".',
'Select Timelion from the "New Visualization" window.',
'Open a new tab, open the Timelion app, select the chart you want to copy, then copy the chart expression.',
'Go to Timelion, paste the chart expression in the Timelion expression field, then click Update.',
'In the toolbar, click Save.',
'On the Save visualization window, enter the visualization Title, then click Save and return.',
],
},
});
}

return deprecations;
};
Loading