Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
58cfa3d
Remove switchToModelVersionAt from SO API definition
TinaHeiligers Apr 26, 2025
dd4af37
Default to 10.0.0 those types that don't define modelVersions
gsoldevila May 20, 2025
79e0c7a
Add integration test to ensure no regression
gsoldevila May 20, 2025
de8ce54
Update version_map.test.ts
gsoldevila May 20, 2025
2ced6d7
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine May 20, 2025
3ca7c68
Enforce Kibana >8.18.0 check
gsoldevila May 23, 2025
abb8ad3
Allow specifying a minimum virtual version for the SO types modelVers…
gsoldevila May 23, 2025
a01627d
Fix failing tests
gsoldevila May 23, 2025
d62dadb
Add 'old' type with no modelVersions. Conditional type=>mv map creation.
gsoldevila May 26, 2025
b30f672
Parametrise kibanaVersionCheck, update test archives.
gsoldevila May 27, 2025
9205ce0
Remove unaccessible scenarios
gsoldevila May 29, 2025
0f06a10
Add missing param
gsoldevila May 29, 2025
c3b5655
Minimum modelVersion is 10.0.0
gsoldevila May 29, 2025
a13bc45
Update test to upgrade from compatible Kibana version
gsoldevila May 29, 2025
64d438a
Update archives to 8.19.0
gsoldevila May 30, 2025
e0c2f79
Use migrator test kit and newer archive
gsoldevila May 30, 2025
ed0ca90
Fix remaining tests
gsoldevila May 30, 2025
c4651c2
Add 'old' SO type to the counts
gsoldevila Jun 2, 2025
e487c4d
Address PR feedback
gsoldevila Jun 9, 2025
5900e85
Fix typing issues
gsoldevila Jun 9, 2025
386a784
Misc enhancements
gsoldevila Jun 20, 2025
ea9a457
Comply with stricter type check for transformFn
gsoldevila Jun 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dev_docs/tutorials/saved_objects.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { SavedObjectsType } from 'src/core/server';
export const dashboardVisualization: SavedObjectsType = {
name: 'dashboard_visualization', [1]
hidden: true, [3]
switchToModelVersionAt: '8.10.0', // this is the default, feel free to omit it unless you intend to switch to using model versions before 8.10.0
namespaceType: 'multiple-isolated', [2]
mappings: {
dynamic: false,
Expand Down
11 changes: 0 additions & 11 deletions docs/extend/saved-objects-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const dashboardVisualization: SavedObjectsType = {
name: 'dashboard_visualization', <1>
hidden: true,
namespaceType: 'multiple-isolated', <2>
switchToModelVersionAt: '8.10.0',
modelVersions: {
1: modelVersion1,
2: modelVersion2,
Expand Down Expand Up @@ -167,7 +166,6 @@ That way:
```ts
const myType: SavedObjectsType = {
name: 'test',
switchToModelVersionAt: '8.10.0',
modelVersions: {
1: modelVersion1, // valid: start with version 1
2: modelVersion2, // valid: no gap between versions
Expand All @@ -181,7 +179,6 @@ const myType: SavedObjectsType = {
```ts
const myType: SavedObjectsType = {
name: 'test',
switchToModelVersionAt: '8.10.0',
modelVersions: {
2: modelVersion2, // invalid: first version must be 1
4: modelVersion3, // invalid: skipped version 3
Expand All @@ -200,7 +197,6 @@ const myType: SavedObjectsType = {
```ts
const myType: SavedObjectsType = {
name: 'test',
switchToModelVersionAt: '8.10.0',
modelVersions: {
1: {
changes: [
Expand Down Expand Up @@ -463,7 +459,6 @@ The definition of the type at version 1 would look like:
const myType: SavedObjectsType = {
name: 'test',
namespaceType: 'single',
switchToModelVersionAt: '8.10.0',
modelVersions: {
// initial (and current) model version
1: {
Expand Down Expand Up @@ -520,7 +515,6 @@ The full type definition after the addition of the new model version:
const myType: SavedObjectsType = {
name: 'test',
namespaceType: 'single',
switchToModelVersionAt: '8.10.0',
modelVersions: {
1: {
changes: [],
Expand Down Expand Up @@ -609,7 +603,6 @@ the full type definition after the addition of the model version 2 would be:
const myType: SavedObjectsType = {
name: 'test',
namespaceType: 'single',
switchToModelVersionAt: '8.10.0',
modelVersions: {
1: {
changes: [
Expand Down Expand Up @@ -705,7 +698,6 @@ The full type definition would look like:
const myType: SavedObjectsType = {
name: 'test',
namespaceType: 'single',
switchToModelVersionAt: '8.10.0',
modelVersions: {
1: {
changes: [
Expand Down Expand Up @@ -778,7 +770,6 @@ The definition of the type at version 1 would look like:
const myType: SavedObjectsType = {
name: 'test',
namespaceType: 'single',
switchToModelVersionAt: '8.10.0',
modelVersions: {
// initial (and current) model version
1: {
Expand Down Expand Up @@ -843,7 +834,6 @@ The full type definition after the addition of the new model version:
const myType: SavedObjectsType = {
name: 'test',
namespaceType: 'single',
switchToModelVersionAt: '8.10.0',
modelVersions: {
// initial (and current) model version
1: {
Expand Down Expand Up @@ -911,7 +901,6 @@ The full type definition after the data removal would look like:
const myType: SavedObjectsType = {
name: 'test',
namespaceType: 'single',
switchToModelVersionAt: '8.10.0',
modelVersions: {
// initial (and current) model version
1: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const typedef: Partial<SavedObjectsType> = {
count: schema.number(),
}),
},
switchToModelVersionAt: '8.10.0',
};

export const typedef1: Partial<SavedObjectsType> = {
Expand All @@ -53,7 +52,6 @@ export const typedef1: Partial<SavedObjectsType> = {
count: schema.number(),
}),
},
switchToModelVersionAt: '8.10.0',
modelVersions: {
'1': {
changes: [
Expand Down Expand Up @@ -96,7 +94,6 @@ export const typedef2: Partial<SavedObjectsType> = {
foo: schema.string(),
}),
},
switchToModelVersionAt: '8.10.0',
modelVersions: {
'1': {
changes: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export {
} from './src/utils';
export {
modelVersionVirtualMajor,
initialModelVersion,
globalSwitchToModelVersionAt,
assertValidModelVersion,
isVirtualModelVersion,
Expand All @@ -64,7 +65,6 @@ export {
getModelVersionMapForTypes,
getLatestModelVersion,
getCurrentVirtualVersion,
getLatestMigrationVersion,
getVirtualVersionMap,
getLatestMappingsVirtualVersionMap,
type ModelVersionMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
SavedObjectsTypeMappingDefinition,
SavedObjectsMappingProperties,
} from '@kbn/core-saved-objects-server';
import type { VirtualVersionMap } from '../model_version';

/**
* A map of {@link SavedObjectsTypeMappingDefinition | saved object type mappings}
Expand Down Expand Up @@ -60,7 +61,15 @@ export interface IndexMapping {
export type IndexTypesMap = Record<string, string[]>;

/** @internal */
export interface V2AlgoIndexMappingMeta {
export interface CommonAlgoIndexMappingMeta {
/**
* The current virtual version of the mapping of the index.
*/
mappingVersions?: VirtualVersionMap;
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just extracting mappingVersions in a common interface, as it is the same for V2 and ZDT.


/** @internal */
export interface V2AlgoIndexMappingMeta extends CommonAlgoIndexMappingMeta {
/**
* A dictionary of key -> md5 hash (e.g. 'dashboard': '24234qdfa3aefa3wa')
* with each key being a root-level mapping property, and each value being
Expand All @@ -76,22 +85,14 @@ export interface V2AlgoIndexMappingMeta {
* @remark: Only defined for indices using the v2 migration algorithm.
*/
indexTypesMap?: IndexTypesMap;
/**
* The current virtual version of the mapping of the index.
*/
mappingVersions?: { [k: string]: string };
}

/** @internal */
export interface ZdtAlgoIndexMappingMeta {
/**
* The current virtual version of the mapping of the index.
*/
mappingVersions?: { [k: string]: string };
export interface ZdtAlgoIndexMappingMeta extends CommonAlgoIndexMappingMeta {
/**
* The current virtual versions of the documents of the index.
*/
docVersions?: { [k: string]: string };
docVersions?: VirtualVersionMap;
/**
* Info about the current state of the migration.
* Should only be present if a migration is in progress or was interrupted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,19 @@ export interface IKibanaMigrator {
* multiple migrations running at the same time. When calling with this parameter, it's expected that the calling
* code should ensure that the initial call resolves before calling the function again.
*
* @param options.skipVersionCheck - If true, the migration logic will NOT check if the current Kibana version (in terms of system indices' aliases) is compatible.
*
* @remarks The main goal of the `skipVersionCheck` parameter is to facilitate the ES archiver imports for testing purposes.
* Notice that for standard deployments, the Kibana migration logic is run at startup, and it is already enforcing a minimum Kibana version.
*
* @returns - A promise which resolves once all migrations have been applied.
* The promise resolves with an array of migration statuses, one for each
* elasticsearch index which was migrated.
*/
runMigrations(options?: { rerun?: boolean }): Promise<MigrationResult[]>;
runMigrations(options?: {
rerun?: boolean;
skipVersionCheck?: boolean;
}): Promise<MigrationResult[]>;

prepareMigrations(): void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
export const modelVersionVirtualMajor = 10;

/**
* The initial model version (starting point for SO types that have NOT yet defined any modelVersions)
*/
export const initialModelVersion = '10.0.0';

/**
* The stack version where all types will be forced to switch to using the model version system.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { modelVersionVirtualMajor, globalSwitchToModelVersionAt } from './constants';
export {
modelVersionVirtualMajor,
initialModelVersion,
globalSwitchToModelVersionAt,
} from './constants';
export {
assertValidModelVersion,
isVirtualModelVersion,
Expand All @@ -19,7 +23,6 @@ export {
getLatestModelVersion,
getCurrentVirtualVersion,
getVirtualVersionMap,
getLatestMigrationVersion,
getLatestMappingsVirtualVersionMap,
type ModelVersionMap,
type VirtualVersionMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,23 @@ describe('getModelVersionsFromMappings', () => {

expect(versionMap).toBeUndefined();
});

it('default to the minimum version if specified', () => {
const mappings = createIndexMapping({
mappingVersions: {
foo: '10.3.0',
bar: '8.16.2',
},
});
const versionMap = getVirtualVersionsFromMappings({
mappings,
source: 'mappingVersions',
minimumVirtualVersion: '10.0.0',
});

expect(versionMap).toEqual({
foo: '10.3.0',
bar: '10.0.0',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { SemVer } from 'semver';
import type { IndexMapping, IndexMappingMeta } from '../mappings';
import type { VirtualVersionMap } from './version_map';
import { assertValidVirtualVersion } from './conversion';
Expand All @@ -16,6 +17,7 @@ export interface GetModelVersionsFromMappingsOpts {
source: 'mappingVersions' | 'docVersions';
/** if specified, will filter the types with the provided list */
knownTypes?: string[];
minimumVirtualVersion?: string;
}

/**
Expand All @@ -25,6 +27,7 @@ export const getVirtualVersionsFromMappings = ({
mappings,
source,
knownTypes,
minimumVirtualVersion,
}: GetModelVersionsFromMappingsOpts): VirtualVersionMap | undefined => {
if (!mappings._meta) {
return undefined;
Expand All @@ -34,6 +37,7 @@ export const getVirtualVersionsFromMappings = ({
meta: mappings._meta,
source,
knownTypes,
minimumVirtualVersion,
});
};

Expand All @@ -42,6 +46,7 @@ export interface GetModelVersionsFromMappingMetaOpts {
source: 'mappingVersions' | 'docVersions';
/** if specified, will filter the types with the provided list */
knownTypes?: string[];
minimumVirtualVersion?: string;
}

/**
Expand All @@ -51,16 +56,23 @@ export const getVirtualVersionsFromMappingMeta = ({
meta,
source,
knownTypes,
minimumVirtualVersion,
}: GetModelVersionsFromMappingMetaOpts): VirtualVersionMap | undefined => {
const indexVersions = source === 'mappingVersions' ? meta.mappingVersions : meta.docVersions;
if (!indexVersions) {
return undefined;
}

const minVersion = minimumVirtualVersion ? new SemVer(minimumVirtualVersion) : undefined;
const typeSet = knownTypes ? new Set(knownTypes) : undefined;

return Object.entries(indexVersions).reduce<VirtualVersionMap>((map, [type, rawVersion]) => {
if (!typeSet || typeSet.has(type)) {
map[type] = assertValidVirtualVersion(rawVersion);
const validatedVersion = assertValidVirtualVersion(rawVersion);
map[type] =
minimumVirtualVersion && minVersion!.compare(validatedVersion) === 1
? minimumVirtualVersion
: validatedVersion;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #219329 index._meta.mappingVersions can now have "downgraded" versions for those types that do not define modelVersions:. This can happen for customers that upgrade through 9.0.1 or 9.0.2.
When updating from any of the versions above, we don't want the logic to determine that those types have been updated, that's why we introduce this new minimumVirtualVersion.

}
return map;
}, {});
Expand Down
Loading
Loading