-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapt the ZDT migration algorithm to support v2 migrations #155981
Adapt the ZDT migration algorithm to support v2 migrations #155981
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-review
/** @internal */ | ||
export type IndexMappingMeta = V2AlgoIndexMappingMeta & ZdtAlgoIndexMappingMeta; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got tired of having to check which properties are used by each algo everytime I read the type, so it's now split (still using an union though, otherwise we would need to manually specify which one we're using everytime)
const virtualVersion = virtualVersions[type.name]; | ||
return { | ||
bool: { | ||
must: [ | ||
{ term: { type: type.name } }, | ||
{ | ||
bool: { | ||
should: [ | ||
{ | ||
bool: { | ||
must: { exists: { field: 'migrationVersion' } }, | ||
must_not: { term: { [`migrationVersion.${type.name}`]: virtualVersion } }, | ||
}, | ||
}, | ||
{ | ||
bool: { | ||
must_not: [ | ||
{ exists: { field: 'migrationVersion' } }, | ||
{ term: { typeMigrationVersion: virtualVersion } }, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
must: [{ term: { type: type.name } }], | ||
must_not: [{ term: { typeMigrationVersion: virtualVersion } }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query was copied from the v2 algo, but we effectively don't need to support the old migrationVersion.{type}
syntax given that zdt will be introduced this change, so I cleaned that up.
roots: ['<rootDir>/src/core/server/integration_tests/saved_objects/migrations/zdt_v2_compat'], | ||
// must override to match all test given there is no `integration_tests` subfolder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a dedicated suite for the v2 compat tests. The reasoning was that we may eventually want to get rid of the support later, so having dedicated test suites would make the removal easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking the same thing: Isolate our newest changes in new CI groups.
Pinging @elastic/kibana-core (Team:Core) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @pgayvallet , a lot of comments stem from missing some parts of the context in which these changes were made, but I think I could piece most of them together. FWIW, perhaps some of my questions can translate into doc comments that could help other devs grok how the different parts interact.
migrations: { | ||
'7.17.2': dummyMigration, | ||
'8.6.0': dummyMigration, | ||
}, | ||
modelVersions: { | ||
1: dummyModelVersion(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to make sure I understand this correctly, but what is the plan moving forward for these two sets of values? Will consumers specify when they are switching to model versions and then we will assume all "virtual" version migrations should be run first after which the "model versions" take over?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will consumers specify when they are switching to model versions
Correct, via switchToModelVersionAt
kibana/packages/core/saved-objects/core-saved-objects-server/src/saved_objects_type.ts
Line 230 in 7136039
switchToModelVersionAt?: string; |
|
||
/** | ||
* Returns the current virtual version for the given type. | ||
* If will either be the latest model version if the type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* If will either be the latest model version if the type | |
* It will either be the latest model version if the type |
|
||
export type ModelVersionMap = Record<string, number>; | ||
export type VirtualVersion = string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a doc comment to this type explaining what VirtualVersion
is, perhaps in relation to ModelVersion
?
const meta: IndexMappingMeta = { | ||
mappingVersions: { | ||
foo: 1, | ||
bar: 1, | ||
foo: '10.1.0', | ||
bar: '10.1.0', | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting (and a little scary) times! Will we, at some point in time, potentially have mixed state of VirtualVersion
s and "regular" stack versions in this map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel like the "missing link" for my understanding is the intended co-existence of these values in the future and what form that will take specifically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I think I got the answer to my own q when reading this test:
VirtualVersion
is a "special" major combined with model version as minor - fully decoupled from stack (or so it seems).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, virtual
versions is a compatibility format between stack versions and model versions, making the assumption that we will no longer be using stack versioning before this arbitrary 10
version, that serves as a delimiter / identifier for model versions (10.{modelVersion}.0
)
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
…55981) ## Summary Adapt the `zdt` migration algorithm to run the v2 migrations in addition to the model version transformations. The intent is to be able to use the current migration system in a zero-downtime upgrade friendly-ish way ### Technicals elastic#148656 was a precondition, as the zdt algo requires that mapping changes are compatible (given we keep the same index). Technically, it means we're now storing the `virtualVersion` instead of the `modelVersion` in the index's meta (`mappingVersions` and `docVersions`), to allow keeping track of mixed stack and model versions per type. Note that switching to model versioning is still a one way, non-revertible action. Once using model versioning (by specifying `switchToModelVersionAt` on your type), there is no going back.
Summary
Part of #150309
Adapt the
zdt
migration algorithm to run the v2 migrations in addition to the model version transformations.The intent is to be able to use the current migration system in a zero-downtime upgrade friendly-ish way
Technicals
#148656 was a precondition, as the zdt algo requires that mapping changes are compatible (given we keep the same index).
Technically, it means we're now storing the
virtualVersion
instead of themodelVersion
in the index's meta (mappingVersions
anddocVersions
), to allow keeping track of mixed stack and model versions per type.Note that switching to model versioning is still a one way, non-revertible action. Once using model versioning (by specifying
switchToModelVersionAt
on your type), there is no going back.