[Breaking] Remove /api/settings & the xpack_legacy plugin. (#114730)

This commit is contained in:
Luke Elmers 2021-10-13 14:20:56 -06:00 committed by GitHub
parent 491fcd5c36
commit e1e1830f15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 1 additions and 388 deletions

1
.github/CODEOWNERS vendored
View file

@ -254,7 +254,6 @@
/src/plugins/kibana_overview/ @elastic/kibana-core
/x-pack/plugins/global_search_bar/ @elastic/kibana-core
#CC# /src/core/server/csp/ @elastic/kibana-core
#CC# /src/plugins/xpack_legacy/ @elastic/kibana-core
#CC# /src/plugins/saved_objects/ @elastic/kibana-core
#CC# /x-pack/plugins/cloud/ @elastic/kibana-core
#CC# /x-pack/plugins/features/ @elastic/kibana-core

View file

@ -153,7 +153,6 @@ warning: This document is auto-generated and is meant to be viewed inside our ex
| <DocLink id="kibVisualizationsPluginApi" text="visualizations"/> | [Vis Editors](https://github.com/orgs/elastic/teams/kibana-vis-editors) | Contains the shared architecture among all the legacy visualizations, e.g. the visualization type registry or the visualization embeddable. | 304 | 13 | 286 | 16 |
| <DocLink id="kibVisualizePluginApi" text="visualize"/> | [Vis Editors](https://github.com/orgs/elastic/teams/kibana-vis-editors) | Contains the visualize application which includes the listing page and the app frame, which will load the visualization's editor. | 24 | 0 | 23 | 1 |
| watcher | [Stack Management](https://github.com/orgs/elastic/teams/kibana-stack-management) | - | 0 | 0 | 0 | 0 |
| xpackLegacy | [Kibana Core](https://github.com/orgs/elastic/teams/kibana-core) | - | 0 | 0 | 0 | 0 |
## Package Directory

View file

@ -617,10 +617,6 @@ in their infrastructure.
|This plugins adopts some conventions in addition to or in place of conventions in Kibana (at the time of the plugin's creation):
|{kib-repo}blob/{branch}/x-pack/plugins/xpack_legacy/README.md[xpackLegacy]
|Contains HTTP endpoints and UiSettings that are slated for removal.
|===
include::{kibana-root}/src/plugins/dashboard/README.asciidoc[leveloffset=+1]

View file

@ -1,3 +0,0 @@
# Xpack Leagcy
Contains HTTP endpoints and UiSettings that are slated for removal.

View file

@ -1,15 +0,0 @@
/*
* 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.
*/
module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/x-pack/plugins/xpack_legacy'],
coverageDirectory: '<rootDir>/target/kibana-coverage/jest/x-pack/plugins/xpack_legacy',
coverageReporters: ['text', 'html'],
collectCoverageFrom: ['<rootDir>/x-pack/plugins/xpack_legacy/server/**/*.{ts,tsx}'],
};

View file

@ -1,12 +0,0 @@
{
"id": "xpackLegacy",
"owner": {
"name": "Kibana Core",
"githubTeam": "kibana-core"
},
"version": "8.0.0",
"kibanaVersion": "kibana",
"server": true,
"ui": false,
"requiredPlugins": ["usageCollection"]
}

View file

@ -1,12 +0,0 @@
/*
* 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 { PluginInitializerContext } from '../../../../src/core/server';
import { XpackLegacyPlugin } from './plugin';
export const plugin = (initializerContext: PluginInitializerContext) =>
new XpackLegacyPlugin(initializerContext);

View file

@ -1,45 +0,0 @@
/*
* 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 {
CoreStart,
CoreSetup,
Plugin,
PluginInitializerContext,
} from '../../../../src/core/server';
import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
import { registerSettingsRoute } from './routes/settings';
interface SetupPluginDeps {
usageCollection: UsageCollectionSetup;
}
export class XpackLegacyPlugin implements Plugin {
constructor(private readonly initContext: PluginInitializerContext) {}
public setup(core: CoreSetup, { usageCollection }: SetupPluginDeps) {
const router = core.http.createRouter();
const globalConfig = this.initContext.config.legacy.get();
const serverInfo = core.http.getServerInfo();
registerSettingsRoute({
router,
usageCollection,
overallStatus$: core.status.overall$,
config: {
kibanaIndex: globalConfig.kibana.index,
kibanaVersion: this.initContext.env.packageInfo.version,
uuid: this.initContext.env.instanceUuid,
server: serverInfo,
},
});
}
public start(core: CoreStart) {}
public stop() {}
}

View file

@ -1,115 +0,0 @@
/*
* 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 { BehaviorSubject } from 'rxjs';
import { UnwrapPromise } from '@kbn/utility-types';
import supertest from 'supertest';
import { ServiceStatus, ServiceStatusLevels } from '../../../../../src/core/server';
import {
contextServiceMock,
elasticsearchServiceMock,
savedObjectsServiceMock,
executionContextServiceMock,
} from '../../../../../src/core/server/mocks';
import { createHttpServer } from '../../../../../src/core/server/test_utils';
import { registerSettingsRoute } from './settings';
type HttpService = ReturnType<typeof createHttpServer>;
type HttpSetup = UnwrapPromise<ReturnType<HttpService['setup']>>;
export function mockGetClusterInfo(clusterInfo: any) {
const esClient = elasticsearchServiceMock.createScopedClusterClient().asCurrentUser;
// @ts-ignore we only care about the response body
esClient.info.mockResolvedValue({ body: { ...clusterInfo } });
return esClient;
}
describe('/api/settings', () => {
let server: HttpService;
let httpSetup: HttpSetup;
let overallStatus$: BehaviorSubject<ServiceStatus>;
beforeEach(async () => {
server = createHttpServer();
await server.preboot({ context: contextServiceMock.createPrebootContract() });
httpSetup = await server.setup({
context: contextServiceMock.createSetupContract({
core: {
elasticsearch: {
client: {
asCurrentUser: mockGetClusterInfo({ cluster_uuid: 'yyy-yyyyy' }),
},
},
savedObjects: {
client: savedObjectsServiceMock.create(),
},
},
}),
executionContext: executionContextServiceMock.createInternalSetupContract(),
});
overallStatus$ = new BehaviorSubject<ServiceStatus>({
level: ServiceStatusLevels.available,
summary: 'everything is working',
});
const usageCollection = {
getCollectorByType: jest.fn().mockReturnValue({
fetch: jest
.fn()
.mockReturnValue({ xpack: { default_admin_email: 'kibana-machine@elastic.co' } }),
}),
} as any;
const router = httpSetup.createRouter('');
registerSettingsRoute({
router,
overallStatus$,
usageCollection,
config: {
kibanaIndex: '.kibana-test',
kibanaVersion: '8.8.8-SNAPSHOT',
server: {
name: 'mykibana',
hostname: 'mykibana.com',
port: 1234,
},
uuid: 'xxx-xxxxx',
},
});
await server.start();
});
afterEach(async () => {
await server.stop();
});
it('successfully returns data', async () => {
const response = await supertest(httpSetup.server.listener).get('/api/settings').expect(200);
expect(response.body).toMatchObject({
cluster_uuid: 'yyy-yyyyy',
settings: {
xpack: {
default_admin_email: 'kibana-machine@elastic.co',
},
kibana: {
uuid: 'xxx-xxxxx',
name: 'mykibana',
index: '.kibana-test',
host: 'mykibana.com',
locale: 'en',
transport_address: `mykibana.com:1234`,
version: '8.8.8',
snapshot: true,
status: 'green',
},
},
});
});
});

View file

@ -1,96 +0,0 @@
/*
* 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 { i18n } from '@kbn/i18n';
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { IRouter, ServiceStatus, ServiceStatusLevels } from '../../../../../src/core/server';
import { UsageCollectionSetup } from '../../../../../src/plugins/usage_collection/server';
import { KIBANA_SETTINGS_TYPE } from '../../../monitoring/common/constants';
import { KibanaSettingsCollector } from '../../../monitoring/server';
const SNAPSHOT_REGEX = /-snapshot/i;
export function registerSettingsRoute({
router,
usageCollection,
overallStatus$,
config,
}: {
router: IRouter;
usageCollection: UsageCollectionSetup;
overallStatus$: Observable<ServiceStatus>;
config: {
kibanaIndex: string;
kibanaVersion: string;
uuid: string;
server: {
name: string;
hostname: string;
port: number;
};
};
}) {
router.get(
{
path: '/api/settings',
validate: false,
},
async (context, req, res) => {
const collectorFetchContext = {
esClient: context.core.elasticsearch.client.asCurrentUser,
soClient: context.core.savedObjects.client,
};
const settingsCollector = usageCollection.getCollectorByType(KIBANA_SETTINGS_TYPE) as
| KibanaSettingsCollector
| undefined;
if (!settingsCollector) {
throw new Error('The settings collector is not registered');
}
const settings =
(await settingsCollector.fetch(collectorFetchContext)) ??
settingsCollector.getEmailValueStructure(null);
const { body } = await collectorFetchContext.esClient.info({ filter_path: 'cluster_uuid' });
const uuid: string = body.cluster_uuid;
const overallStatus = await overallStatus$.pipe(first()).toPromise();
const kibana = {
uuid: config.uuid,
name: config.server.name,
index: config.kibanaIndex,
host: config.server.hostname,
port: config.server.port,
locale: i18n.getLocale(),
transport_address: `${config.server.hostname}:${config.server.port}`,
version: config.kibanaVersion.replace(SNAPSHOT_REGEX, ''),
snapshot: SNAPSHOT_REGEX.test(config.kibanaVersion),
status: ServiceStatusToLegacyState[overallStatus.level.toString()],
};
return res.ok({
body: {
cluster_uuid: uuid,
settings: {
...settings,
kibana,
},
},
});
}
);
}
const ServiceStatusToLegacyState: Record<string, string> = {
[ServiceStatusLevels.critical.toString()]: 'red',
[ServiceStatusLevels.unavailable.toString()]: 'red',
[ServiceStatusLevels.degraded.toString()]: 'yellow',
[ServiceStatusLevels.available.toString()]: 'green',
};

View file

@ -1,17 +0,0 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./target/types",
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true
},
"include": [
"server/**/*",
],
"references": [
{ "path": "../../../src/core/tsconfig.json" },
{ "path": "../../../src/plugins/usage_collection/tsconfig.json" },
{ "path": "../monitoring/tsconfig.json" },
]
}

View file

@ -16,7 +16,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./security'));
loadTestFile(require.resolve('./spaces'));
loadTestFile(require.resolve('./monitoring'));
loadTestFile(require.resolve('./xpack_legacy'));
loadTestFile(require.resolve('./features'));
loadTestFile(require.resolve('./telemetry'));
loadTestFile(require.resolve('./logstash'));

View file

@ -1,12 +0,0 @@
/*
* 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.
*/
export default function ({ loadTestFile }) {
describe('xpack_legacy', () => {
loadTestFile(require.resolve('./settings'));
});
}

View file

@ -1,12 +0,0 @@
/*
* 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.
*/
export default function ({ loadTestFile }) {
describe('Settings', () => {
loadTestFile(require.resolve('./settings'));
});
}

View file

@ -1,40 +0,0 @@
/*
* 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 expect from '@kbn/expect';
export default function ({ getService }) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
describe('/api/settings', () => {
describe('with trial license clusters', () => {
const archive = 'x-pack/test/functional/es_archives/monitoring/multicluster';
before('load clusters archive', () => {
return esArchiver.load(archive);
});
after('unload clusters archive', () => {
return esArchiver.unload(archive);
});
it('should load multiple clusters', async () => {
const { body } = await supertest.get('/api/settings').set('kbn-xsrf', 'xxx').expect(200);
expect(body.cluster_uuid.length > 1).to.eql(true);
expect(body.settings.kibana.uuid.length > 0).to.eql(true);
expect(body.settings.kibana.name.length > 0).to.eql(true);
expect(body.settings.kibana.index.length > 0).to.eql(true);
expect(body.settings.kibana.host.length > 0).to.eql(true);
expect(body.settings.kibana.transport_address.length > 0).to.eql(true);
expect(body.settings.kibana.version.length > 0).to.eql(true);
expect(body.settings.kibana.status.length > 0).to.eql(true);
expect(body.settings.xpack.default_admin_email).to.eql(null);
});
});
});
}

View file

@ -102,7 +102,6 @@
{ "path": "../plugins/remote_clusters/tsconfig.json" },
{ "path": "../plugins/cross_cluster_replication/tsconfig.json" },
{ "path": "../plugins/index_lifecycle_management/tsconfig.json"},
{ "path": "../plugins/uptime/tsconfig.json" },
{ "path": "../plugins/xpack_legacy/tsconfig.json" }
{ "path": "../plugins/uptime/tsconfig.json" }
]
}