mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Currently, if the Cloud plugin is disabled the server will fail to start Fixes #31612 Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
This commit is contained in:
parent
c2eab6cb8a
commit
2e5f32dc11
4 changed files with 72 additions and 20 deletions
4
x-pack/plugins/cloud/index.d.ts
vendored
4
x-pack/plugins/cloud/index.d.ts
vendored
|
@ -5,5 +5,7 @@
|
|||
*/
|
||||
|
||||
export interface CloudPlugin {
|
||||
isCloudEnabled: boolean;
|
||||
config: {
|
||||
isCloudEnabled: boolean;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -16,29 +16,80 @@ import { registerClusterCheckupRoutes } from './cluster_checkup';
|
|||
const MigrationApis = require('../lib/es_migration_apis');
|
||||
MigrationApis.getUpgradeAssistantStatus = jest.fn();
|
||||
|
||||
function register(plugins = {}) {
|
||||
const server = new Server();
|
||||
server.plugins = {
|
||||
elasticsearch: {
|
||||
getCluster: () => ({ callWithRequest: jest.fn() } as any),
|
||||
} as any,
|
||||
...plugins,
|
||||
} as any;
|
||||
server.config = () => ({ get: () => '' } as any);
|
||||
|
||||
registerClusterCheckupRoutes(server);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Since these route callbacks are so thin, these serve simply as integration tests
|
||||
* to ensure they're wired up to the lib functions correctly. Business logic is tested
|
||||
* more thoroughly in the es_migration_apis test.
|
||||
*/
|
||||
describe('cluster checkup API', () => {
|
||||
const server = new Server();
|
||||
server.plugins = {
|
||||
elasticsearch: {
|
||||
getCluster: () => ({ callWithRequest: jest.fn() } as any),
|
||||
} as any,
|
||||
apm_oss: {
|
||||
indexPatterns: ['apm-*'],
|
||||
},
|
||||
cloud: {
|
||||
isCloudEnabled: false,
|
||||
},
|
||||
} as any;
|
||||
server.config = () => ({ get: () => '' } as any);
|
||||
const spy = jest.spyOn(MigrationApis, 'getUpgradeAssistantStatus');
|
||||
|
||||
registerClusterCheckupRoutes(server);
|
||||
afterEach(() => jest.clearAllMocks());
|
||||
|
||||
describe('with cloud enabled', () => {
|
||||
it('is provided to getUpgradeAssistantStatus', async () => {
|
||||
const server = register({
|
||||
cloud: {
|
||||
config: {
|
||||
isCloudEnabled: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
MigrationApis.getUpgradeAssistantStatus.mockResolvedValue({
|
||||
cluster: [],
|
||||
indices: [],
|
||||
nodes: [],
|
||||
});
|
||||
await server.inject({
|
||||
method: 'GET',
|
||||
url: '/api/upgrade_assistant/status',
|
||||
});
|
||||
|
||||
expect(spy.mock.calls[0][2]).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with APM enabled', () => {
|
||||
it('is provided to getUpgradeAssistantStatus', async () => {
|
||||
const server = register({
|
||||
apm_oss: {
|
||||
indexPatterns: ['apm-*'],
|
||||
},
|
||||
});
|
||||
|
||||
MigrationApis.getUpgradeAssistantStatus.mockResolvedValue({
|
||||
cluster: [],
|
||||
indices: [],
|
||||
nodes: [],
|
||||
});
|
||||
await server.inject({
|
||||
method: 'GET',
|
||||
url: '/api/upgrade_assistant/status',
|
||||
});
|
||||
|
||||
expect(spy.mock.calls[0][3]).toEqual(['apm-*']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /api/upgrade_assistant/reindex/{indexName}.json', () => {
|
||||
const server = register();
|
||||
|
||||
it('returns state', async () => {
|
||||
MigrationApis.getUpgradeAssistantStatus.mockResolvedValue({
|
||||
cluster: [],
|
||||
|
|
|
@ -6,14 +6,15 @@
|
|||
|
||||
import Boom from 'boom';
|
||||
import { Legacy } from 'kibana';
|
||||
import { get } from 'lodash';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { getUpgradeAssistantStatus } from '../lib/es_migration_apis';
|
||||
import { EsVersionPrecheck } from '../lib/es_version_precheck';
|
||||
|
||||
export function registerClusterCheckupRoutes(server: Legacy.Server) {
|
||||
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
|
||||
const { isCloudEnabled } = server.plugins.cloud;
|
||||
const isCloudEnabled = _.get(server.plugins, 'cloud.config.isCloudEnabled', false);
|
||||
const apmIndexPatterns = _.get(server, 'plugins.apm_oss.indexPatterns', []);
|
||||
|
||||
server.route({
|
||||
path: '/api/upgrade_assistant/status',
|
||||
|
@ -23,8 +24,6 @@ export function registerClusterCheckupRoutes(server: Legacy.Server) {
|
|||
},
|
||||
async handler(request) {
|
||||
try {
|
||||
const apmIndexPatterns = get(server, 'plugins.apm_oss.indexPatterns', []);
|
||||
|
||||
return await getUpgradeAssistantStatus(
|
||||
callWithRequest,
|
||||
request,
|
||||
|
|
2
x-pack/typings/hapi.d.ts
vendored
2
x-pack/typings/hapi.d.ts
vendored
|
@ -11,7 +11,7 @@ import { XPackMainPlugin } from 'x-pack/plugins/xpack_main/xpack_main';
|
|||
|
||||
declare module 'hapi' {
|
||||
interface PluginProperties {
|
||||
cloud: CloudPlugin;
|
||||
cloud?: CloudPlugin;
|
||||
xpack_main: XPackMainPlugin;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue