Skip to content

Commit

Permalink
Adds tests to ensure registered SO types aren't removed (elastic#207142)
Browse files Browse the repository at this point in the history
fix elastic#207128

We have an integration test to check that saved objects aren't removed
and another that catches mappings changes.
This PR adds another assertion to ensure that the message is clear:
Removing a saved object type is not allowed after 8.8.

---------

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
2 people authored and viduni94 committed Jan 23, 2025
1 parent f435639 commit afdd15f
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/type

/**
* Types that are no longer registered and need to be removed
* As of 8.8, no new types are allowed to be removed.
* Removing saved object types is not backward compatible
*/
export const REMOVED_TYPES: string[] = [
'apm-services-telemetry',
Expand Down
1 change: 1 addition & 0 deletions src/core/packages/saved-objects/server-internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
MIGRATION_CLIENT_OPTIONS,
SavedObjectsService,
CoreSavedObjectsRouteHandlerContext,
SAVED_OBJECT_TYPES_COUNT,
} from './src';
export type {
InternalSavedObjectsServiceStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export type {
InternalSavedObjectsRequestHandlerContext,
InternalSavedObjectRouter,
} from './internal_types';
export { SAVED_OBJECT_TYPES_COUNT } from './object_types';
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
*/

export { registerCoreObjectTypes } from './registration';

// set minimum number of registered saved objects to ensure no object types are removed after 8.8
// declared in internal implementation exclicilty to prevent unintended changes.
export const SAVED_OBJECT_TYPES_COUNT = 127 as const;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import type { SavedObjectsType } from './saved_objects_type';

/**
* Registry holding information about all the registered {@link SavedObjectsType | saved object types}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
createRootWithCorePlugins,
type TestElasticsearchUtils,
} from '@kbn/core-test-helpers-kbn-server';
import { SAVED_OBJECT_TYPES_COUNT } from '@kbn/core-saved-objects-server-internal';

describe('checking migration metadata changes on all registered SO types', () => {
let esServer: TestElasticsearchUtils;
Expand Down Expand Up @@ -46,6 +47,8 @@ describe('checking migration metadata changes on all registered SO types', () =>
// This test is meant to fail when any change is made in registered types that could potentially impact the SO migration.
// Just update the snapshot by running this test file via jest_integration with `-u` and push the update.
// The intent is to trigger a code review from the Core team to review the SO type changes.
// The number of types in the hashMap should never be reduced, it can only increase.
// Removing saved object types is forbidden after 8.8.
it('detecting migration related changes in registered types', () => {
const allTypes = typeRegistry.getAllTypes();

Expand Down Expand Up @@ -185,5 +188,6 @@ describe('checking migration metadata changes on all registered SO types', () =>
"workplace_search_telemetry": "52b32b47ee576f554ac77cb1d5896dfbcfe9a1fb",
}
`);
expect(Object.keys(hashMap).length).toEqual(SAVED_OBJECT_TYPES_COUNT);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
preset: '@kbn/test/jest_integration',
rootDir: '../../../../..',
roots: [
'<rootDir>/src/core/server/integration_tests/saved_objects/registration',
'<rootDir>/src/core/server/integration_tests/saved_objects/routes',
'<rootDir>/src/core/server/integration_tests/saved_objects/service',
'<rootDir>/src/core/server/integration_tests/saved_objects/validation',
Expand Down

0 comments on commit afdd15f

Please sign in to comment.