Filter out security realm deprecations on Cloud (#30018) (#30039)

This commit is contained in:
Josh Dover 2019-02-05 06:39:42 -06:00 committed by GitHub
parent e08f0c2e8a
commit 9229401b0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 15 deletions

9
x-pack/plugins/cloud/index.d.ts vendored Normal file
View file

@ -0,0 +1,9 @@
/*
* 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.
*/
export interface CloudPlugin {
isCloudEnabled: boolean;
}

View file

@ -32,5 +32,12 @@ export const cloud = kibana => {
}).default(),
}).default();
},
init(server) {
const config = server.config().get(`xpack.cloud`);
server.expose('config', {
isCloudEnabled: !!config.id
});
}
});
};

View file

@ -25,8 +25,8 @@ describe('getUpgradeAssistantStatus', () => {
deprecationsResponse = _.cloneDeep(fakeDeprecations);
});
it('calls /_xpack/migration/deprecations', async () => {
await getUpgradeAssistantStatus(callWithRequest, {} as any);
it('calls /_migration/deprecations', async () => {
await getUpgradeAssistantStatus(callWithRequest, {} as any, false);
expect(callWithRequest).toHaveBeenCalledWith({}, 'transport.request', {
path: '/_xpack/migration/deprecations',
method: 'GET',
@ -34,10 +34,23 @@ describe('getUpgradeAssistantStatus', () => {
});
it('returns the correct shape of data', async () => {
const resp = await getUpgradeAssistantStatus(callWithRequest, {} as any);
const resp = await getUpgradeAssistantStatus(callWithRequest, {} as any, false);
expect(resp).toMatchSnapshot();
});
it('returns readyForUpgrade === false when critical issues found', async () => {
deprecationsResponse = {
cluster_settings: [{ level: 'critical', message: 'Do count me', url: 'https://...' }],
node_settings: [],
ml_settings: [],
index_settings: {},
};
await expect(
getUpgradeAssistantStatus(callWithRequest, {} as any, false)
).resolves.toHaveProperty('readyForUpgrade', false);
});
it('returns readyForUpgrade === true when no critical issues found', async () => {
deprecationsResponse = {
cluster_settings: [{ level: 'warning', message: 'Do not count me', url: 'https://...' }],
@ -46,9 +59,28 @@ describe('getUpgradeAssistantStatus', () => {
index_settings: {},
};
await expect(getUpgradeAssistantStatus(callWithRequest, {} as any)).resolves.toHaveProperty(
'readyForUpgrade',
true
);
await expect(
getUpgradeAssistantStatus(callWithRequest, {} as any, false)
).resolves.toHaveProperty('readyForUpgrade', true);
});
it('filters out security realm deprecation on Cloud', async () => {
deprecationsResponse = {
cluster_settings: [
{
level: 'critical',
message: 'Security realm settings structure changed',
url: 'https://...',
},
],
node_settings: [],
ml_settings: [],
index_settings: {},
};
const result = await getUpgradeAssistantStatus(callWithRequest, {} as any, true);
expect(result).toHaveProperty('readyForUpgrade', true);
expect(result).toHaveProperty('cluster', []);
});
});

View file

@ -26,16 +26,15 @@ export interface UpgradeAssistantStatus {
export async function getUpgradeAssistantStatus(
callWithRequest: CallClusterWithRequest,
req: Request
req: Request,
isCloudEnabled: boolean
): Promise<UpgradeAssistantStatus> {
const deprecations = await callWithRequest(req, 'transport.request', {
path: '/_xpack/migration/deprecations',
method: 'GET',
});
const cluster = deprecations.cluster_settings
.concat(deprecations.ml_settings)
.concat(deprecations.node_settings);
const cluster = getClusterDeprecations(deprecations, isCloudEnabled);
const indices = getCombinedIndexInfos(deprecations);
const criticalWarnings = cluster.concat(indices).filter(d => d.level === 'critical');
@ -47,9 +46,7 @@ export async function getUpgradeAssistantStatus(
};
}
// Combines the information from the migration assistance api and the deprecation api into a single array.
// Enhances with information about which index the deprecation applies to and adds buttons for accessing the
// reindex UI.
// Reformats the index deprecations to an array of deprecation warnings extended with an index field.
const getCombinedIndexInfos = (deprecations: DeprecationAPIResponse) =>
Object.keys(deprecations.index_settings).reduce(
(indexDeprecations, indexName) => {
@ -61,3 +58,16 @@ const getCombinedIndexInfos = (deprecations: DeprecationAPIResponse) =>
},
[] as EnrichedDeprecationInfo[]
);
const getClusterDeprecations = (deprecations: DeprecationAPIResponse, isCloudEnabled: boolean) => {
const combined = deprecations.cluster_settings
.concat(deprecations.ml_settings)
.concat(deprecations.node_settings);
if (isCloudEnabled) {
// In Cloud, this is changed at upgrade time. Filter it out to improve upgrade UX.
return combined.filter(d => d.message !== 'Security realm settings structure changed');
} else {
return combined;
}
};

View file

@ -23,6 +23,9 @@ describe('cluster checkup API', () => {
elasticsearch: {
getCluster: () => ({ callWithRequest: jest.fn() } as any),
} as any,
cloud: {
isCloudEnabled: false,
},
} as any;
server.config = () => ({ get: () => '' } as any);

View file

@ -11,13 +11,14 @@ import { getUpgradeAssistantStatus } from '../lib/es_migration_apis';
export function registerClusterCheckupRoutes(server: Legacy.Server) {
const { callWithRequest } = server.plugins.elasticsearch.getCluster('admin');
const { isCloudEnabled } = server.plugins.cloud;
server.route({
path: '/api/upgrade_assistant/status',
method: 'GET',
async handler(request) {
try {
return await getUpgradeAssistantStatus(callWithRequest, request);
return await getUpgradeAssistantStatus(callWithRequest, request, isCloudEnabled);
} catch (e) {
if (e.status === 403) {
return Boom.forbidden(e.message);

View file

@ -5,10 +5,13 @@
*/
import 'hapi';
import { CloudPlugin } from 'x-pack/plugins/cloud';
import { XPackMainPlugin } from 'x-pack/plugins/xpack_main/xpack_main';
declare module 'hapi' {
interface PluginProperties {
cloud: CloudPlugin;
xpack_main: XPackMainPlugin;
}
}