Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { DomainDeprecationDetails } from '@kbn/core/server';

import { getKibanaUpgradeStatus } from './kibana_status';

const mockKibanaDeprecations: DomainDeprecationDetails[] = [
const mockKibanaDeprecations = (): DomainDeprecationDetails[] => [
{
title: 'mock-deprecation-title',
correctiveActions: {
Expand All @@ -31,15 +31,15 @@ const mockKibanaDeprecations: DomainDeprecationDetails[] = [
describe('getKibanaUpgradeStatus', () => {
const deprecationsClient = deprecationsServiceMock.createClient();

deprecationsClient.getAllDeprecations.mockResolvedValue(mockKibanaDeprecations);
deprecationsClient.getAllDeprecations.mockResolvedValue(mockKibanaDeprecations());

it('returns the correct shape of data', async () => {
const resp = await getKibanaUpgradeStatus(deprecationsClient);
expect(resp).toMatchSnapshot();
});

it('returns totalCriticalDeprecations > 0 when critical issues found', async () => {
deprecationsClient.getAllDeprecations.mockResolvedValue(mockKibanaDeprecations);
deprecationsClient.getAllDeprecations.mockResolvedValue(mockKibanaDeprecations());

await expect(getKibanaUpgradeStatus(deprecationsClient)).resolves.toHaveProperty(
'totalCriticalDeprecations',
Expand All @@ -55,4 +55,98 @@ describe('getKibanaUpgradeStatus', () => {
0
);
});

it('returns totalCriticalDeprecations > 0, but ignores API deprecations', async () => {
deprecationsClient.getAllDeprecations.mockResolvedValue([
...mockKibanaDeprecations(),
...mockKibanaDeprecations(),
{
title: 'mock-deprecation-title',
correctiveActions: {
manualSteps: [],
},
apiId: 'foo',
deprecationType: 'api',
documentationUrl: 'testDocUrl',
level: 'warning',
message: 'testMessage',
domainId: 'security',
},
{
title: 'mock-deprecation-title',
correctiveActions: {
manualSteps: [],
},
apiId: 'foo',
deprecationType: 'api',
documentationUrl: 'testDocUrl',
level: 'critical',
message: 'testMessage',
domainId: 'security',
},
{
title: 'mock-deprecation-title',
correctiveActions: {
manualSteps: [],
},
apiId: 'foo',
deprecationType: 'api',
documentationUrl: 'testDocUrl',
level: 'critical',
message: 'testMessage',
domainId: 'security',
},
]);

await expect(getKibanaUpgradeStatus(deprecationsClient)).resolves.toHaveProperty(
'totalCriticalDeprecations',
2
);
});

it('returns totalCriticalDeprecations === 0 when only critical API deprecations', async () => {
deprecationsClient.getAllDeprecations.mockResolvedValue([
{
title: 'mock-deprecation-title',
correctiveActions: {
manualSteps: [],
},
apiId: 'foo',
deprecationType: 'api',
documentationUrl: 'testDocUrl',
level: 'warning',
message: 'testMessage',
domainId: 'security',
},
{
title: 'mock-deprecation-title',
correctiveActions: {
manualSteps: [],
},
apiId: 'foo',
deprecationType: 'api',
documentationUrl: 'testDocUrl',
level: 'critical',
message: 'testMessage',
domainId: 'security',
},
{
title: 'mock-deprecation-title',
correctiveActions: {
manualSteps: [],
},
apiId: 'foo',
deprecationType: 'api',
documentationUrl: 'testDocUrl',
level: 'critical',
message: 'testMessage',
domainId: 'security',
},
]);

await expect(getKibanaUpgradeStatus(deprecationsClient)).resolves.toHaveProperty(
'totalCriticalDeprecations',
0
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export const getKibanaUpgradeStatus = async (deprecationsClient: DeprecationsCli
const kibanaDeprecations: DomainDeprecationDetails[] =
await deprecationsClient.getAllDeprecations();

const totalCriticalDeprecations = kibanaDeprecations.filter((d) => d.level === 'critical').length;
const totalCriticalDeprecations = kibanaDeprecations.filter(
(d) => d.deprecationType !== 'api' && d.level === 'critical'
).length;

return {
totalCriticalDeprecations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export default function ({ getService }: FtrProviderContext) {
// await kibanaServer.savedObjects.cleanStandardList();
await esArchiver.emptyKibanaIndex();
});
it('returns does not return api deprecations if the routes are not called', async () => {
it('does not return api deprecations if deprecated routes are not called', async () => {
const { deprecations } = (await supertest.get(`/api/deprecations/`).expect(200)).body;
const apiDeprecations = getApiDeprecations(deprecations);
expect(apiDeprecations.length).to.equal(0);
});

it('returns deprecated APIs when the api is called', async () => {
it('returns deprecated APIs when a deprecated api is called', async () => {
await supertest
.get(`/internal/routing_example/d/internal_versioned_route?apiVersion=1`)
.expect(200);
Expand Down Expand Up @@ -207,6 +207,29 @@ export default function ({ getService }: FtrProviderContext) {
);
});
});
it('GET /api/upgrade_assistant/status does not return { readyForUpgrade: false } if there are only critical API deprecations', async () => {
/** Throw in another critical deprecation... */
await supertest.get(`/api/routing_example/d/removed_route`).expect(200);
// sleep a little until the usage counter is synced into ES
await setTimeoutAsync(3000);
await retry.tryForTime(
15 * 1000,
async () => {
const { deprecations } = (await supertest.get(`/api/deprecations/`).expect(200)).body;
const apiDeprecations = getApiDeprecations(deprecations);
// confirm there is at least one CRITICAL deprecated API usage present
expect(apiDeprecations.some(({ level }) => level === 'critical')).to.be(true);
},
undefined,
2000
);
const { body } = await supertest.get(`/api/upgrade_assistant/status`).expect(200);

// There are critical deprecations, but we expect none of them to be related to Kibana
expect(body.readyForUpgrade).to.be(false);
expect(body.details?.length > 0).to.be(true);
expect(/Kibana/gi.test(body.details)).to.be(false);
});
});
}

Expand Down