Skip to content

Commit

Permalink
[Upgrade Assistant] Critical Kibana API deprecations should not block…
Browse files Browse the repository at this point in the history
… upgrades (elastic#209128)

## Summary

Filters out any deprecated Kibana API usages from blocking upgrade
status.


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### Risks

Should be mitigated by E2E tests
  • Loading branch information
jloleysens authored Feb 3, 2025
1 parent 07a61ab commit 6bcdac4
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 9 deletions.
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 @@ -42,13 +42,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 @@ -206,6 +206,25 @@ 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);
expect(body.readyForUpgrade).to.be(true);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import { FtrProviderContext } from '../../common/ftr_provider_context';

export default function ({ loadTestFile }: FtrProviderContext) {
// FAILING VERSION BUMP: https://github.com/elastic/kibana/issues/209048
describe.skip('upgrade assistant', function () {
loadTestFile(require.resolve('./reindexing'));
describe('upgrade assistant', function () {
// FAILING VERSION BUMP: https://github.com/elastic/kibana/issues/209048
// loadTestFile(require.resolve('./reindexing'));
loadTestFile(require.resolve('./api_deprecations'));
});
}

0 comments on commit 6bcdac4

Please sign in to comment.