[Deprecations service] Expose level field to config deprecations (#111516)

This commit is contained in:
Ahmad Bamieh 2021-09-09 15:59:44 +03:00 committed by GitHub
parent 764256573a
commit b001830d58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 13 deletions

View file

@ -23,6 +23,12 @@ export interface DeprecatedConfigDetails {
title?: string;
/* The message to be displayed for the deprecation. */
message: string;
/**
* levels:
* - warning: will not break deployment upon upgrade
* - critical: needs to be addressed before upgrade.
*/
level?: 'warning' | 'critical';
/* (optional) set false to prevent the config service from logging the deprecation message. */
silent?: boolean;
/* (optional) link to the documentation for more details on the deprecation. */

View file

@ -66,7 +66,7 @@ describe('DeprecationsService', () => {
const deprecationsRegistry = mockDeprecationsRegistry.create();
const getDeprecationsContext = mockDeprecationsRegistry.createGetDeprecationsContext();
it('registers config deprecations', () => {
it('registers config deprecations', async () => {
const deprecationsService = new DeprecationsService(coreContext);
coreContext.configService.getHandledDeprecatedConfigs.mockReturnValue([
[
@ -93,7 +93,7 @@ describe('DeprecationsService', () => {
expect(deprecationsFactory.getRegistry).toBeCalledTimes(1);
expect(deprecationsFactory.getRegistry).toBeCalledWith('testDomain');
expect(deprecationsRegistry.registerDeprecations).toBeCalledTimes(1);
const configDeprecations = deprecationsRegistry.registerDeprecations.mock.calls[0][0].getDeprecations(
const configDeprecations = await deprecationsRegistry.registerDeprecations.mock.calls[0][0].getDeprecations(
getDeprecationsContext
);
expect(configDeprecations).toMatchInlineSnapshot(`
@ -115,5 +115,31 @@ describe('DeprecationsService', () => {
]
`);
});
it('accepts `level` field overrides', async () => {
const deprecationsService = new DeprecationsService(coreContext);
coreContext.configService.getHandledDeprecatedConfigs.mockReturnValue([
[
'testDomain',
[
{
message: 'testMessage',
level: 'warning',
correctiveActions: {
manualSteps: ['step a'],
},
},
],
],
]);
deprecationsFactory.getRegistry.mockReturnValue(deprecationsRegistry);
deprecationsService['registerConfigDeprecationsInfo'](deprecationsFactory);
const configDeprecations = await deprecationsRegistry.registerDeprecations.mock.calls[0][0].getDeprecations(
getDeprecationsContext
);
expect(configDeprecations[0].level).toBe('warning');
});
});
});

View file

@ -186,17 +186,21 @@ export class DeprecationsService
deprecationsRegistry.registerDeprecations({
getDeprecations: () => {
return deprecationsContexts.map(
({ title, message, correctiveActions, documentationUrl }) => {
return {
title: title || `${domainId} has a deprecated setting`,
level: 'critical',
deprecationType: 'config',
message,
correctiveActions,
documentationUrl,
requireRestart: true,
};
}
({
title = `${domainId} has a deprecated setting`,
level = 'critical',
message,
correctiveActions,
documentationUrl,
}) => ({
title,
level,
message,
correctiveActions,
documentationUrl,
deprecationType: 'config',
requireRestart: true,
})
);
},
});