forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate migrations.enableV2 (elastic#96398)
* deprecate migrations.enableV2 * provide deprecation test tool from core * use deprecation test tool in tests * add a test for SO depreacations
- Loading branch information
1 parent
41c9cc4
commit 56335ed
Showing
7 changed files
with
151 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import type { ConfigDeprecationProvider } from '@kbn/config'; | ||
import { configDeprecationFactory, applyDeprecations } from '@kbn/config'; | ||
|
||
function collectDeprecations( | ||
provider: ConfigDeprecationProvider, | ||
settings: Record<string, any>, | ||
path: string | ||
) { | ||
const deprecations = provider(configDeprecationFactory); | ||
const deprecationMessages: string[] = []; | ||
const migrated = applyDeprecations( | ||
settings, | ||
deprecations.map((deprecation) => ({ | ||
deprecation, | ||
path, | ||
})), | ||
() => ({ message }) => deprecationMessages.push(message) | ||
); | ||
return { | ||
messages: deprecationMessages, | ||
migrated, | ||
}; | ||
} | ||
|
||
export const getDeprecationsFor = ({ | ||
provider, | ||
settings = {}, | ||
path, | ||
}: { | ||
provider: ConfigDeprecationProvider; | ||
settings?: Record<string, any>; | ||
path: string; | ||
}) => { | ||
return collectDeprecations(provider, { [path]: settings }, path); | ||
}; | ||
|
||
export const getDeprecationsForGlobalSettings = ({ | ||
provider, | ||
settings = {}, | ||
}: { | ||
provider: ConfigDeprecationProvider; | ||
settings?: Record<string, any>; | ||
}) => { | ||
return collectDeprecations(provider, settings, ''); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/core/server/saved_objects/saved_objects_config.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { savedObjectsMigrationConfig } from './saved_objects_config'; | ||
import { getDeprecationsFor } from '../config/test_utils'; | ||
|
||
const applyMigrationsDeprecations = (settings: Record<string, any> = {}) => | ||
getDeprecationsFor({ | ||
provider: savedObjectsMigrationConfig.deprecations!, | ||
settings, | ||
path: 'migrations', | ||
}); | ||
|
||
describe('migrations config', function () { | ||
describe('deprecations', () => { | ||
it('logs a warning if migrations.enableV2 is set: true', () => { | ||
const { messages } = applyMigrationsDeprecations({ enableV2: true }); | ||
expect(messages).toMatchInlineSnapshot(` | ||
Array [ | ||
"\\"migrations.enableV2\\" is deprecated and will be removed in an upcoming release without any further notice.", | ||
] | ||
`); | ||
}); | ||
|
||
it('logs a warning if migrations.enableV2 is set: false', () => { | ||
const { messages } = applyMigrationsDeprecations({ enableV2: false }); | ||
expect(messages).toMatchInlineSnapshot(` | ||
Array [ | ||
"\\"migrations.enableV2\\" is deprecated and will be removed in an upcoming release without any further notice.", | ||
] | ||
`); | ||
}); | ||
}); | ||
|
||
it('does not log a warning if migrations.enableV2 is not set', () => { | ||
const { messages } = applyMigrationsDeprecations({ batchSize: 1_000 }); | ||
expect(messages).toMatchInlineSnapshot(`Array []`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters