[Upgrade Assistant] Critical Kibana API deprecations should not block upgrades (#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
This commit is contained in:
Jean-Louis Leysens 2025-02-03 12:29:05 +01:00 committed by GitHub
parent 07a61abfd4
commit 6bcdac4571
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 124 additions and 9 deletions

View file

@ -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: {
@ -31,7 +31,7 @@ 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);
@ -39,7 +39,7 @@ describe('getKibanaUpgradeStatus', () => {
});
it('returns totalCriticalDeprecations > 0 when critical issues found', async () => {
deprecationsClient.getAllDeprecations.mockResolvedValue(mockKibanaDeprecations);
deprecationsClient.getAllDeprecations.mockResolvedValue(mockKibanaDeprecations());
await expect(getKibanaUpgradeStatus(deprecationsClient)).resolves.toHaveProperty(
'totalCriticalDeprecations',
@ -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
);
});
});

View file

@ -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,

View file

@ -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);
@ -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);
});
});
}

View file

@ -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'));
});
}