-
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
Prevent future convertToMultiNamespaceType migrations #147369
Changes from 3 commits
2ce5baa
ec69b92
4c6a0f3
5d0c374
6fbdfdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,8 +66,6 @@ import { | |
import { MigrationLogger } from './migration_logger'; | ||
import { TransformSavedObjectDocumentError } from '.'; | ||
|
||
const DEFAULT_MINIMUM_CONVERT_VERSION = '8.0.0'; | ||
|
||
export type MigrateFn = (doc: SavedObjectUnsanitizedDoc) => SavedObjectUnsanitizedDoc; | ||
export type MigrateAndConvertFn = (doc: SavedObjectUnsanitizedDoc) => SavedObjectUnsanitizedDoc[]; | ||
|
||
|
@@ -95,7 +93,7 @@ interface TransformOptions { | |
interface DocumentMigratorOptions { | ||
kibanaVersion: string; | ||
typeRegistry: ISavedObjectTypeRegistry; | ||
minimumConvertVersion?: string; | ||
convertVersion?: string; | ||
log: Logger; | ||
} | ||
|
||
|
@@ -142,7 +140,7 @@ export interface VersionedTransformer { | |
* A concrete implementation of the VersionedTransformer interface. | ||
*/ | ||
export class DocumentMigrator implements VersionedTransformer { | ||
private documentMigratorOptions: Omit<DocumentMigratorOptions, 'minimumConvertVersion'>; | ||
private documentMigratorOptions: Omit<DocumentMigratorOptions, 'convertVersion'>; | ||
private migrations?: ActiveMigrations; | ||
private transformDoc?: ApplyTransformsFn; | ||
|
||
|
@@ -152,17 +150,12 @@ export class DocumentMigrator implements VersionedTransformer { | |
* @param {DocumentMigratorOptions} opts | ||
* @prop {string} kibanaVersion - The current version of Kibana | ||
* @prop {SavedObjectTypeRegistry} typeRegistry - The type registry to get type migrations from | ||
* @prop {string} minimumConvertVersion - The minimum version of Kibana in which documents can be converted to multi-namespace types | ||
* @prop {string} convertVersion - The version of Kibana in which documents can be converted to multi-namespace types | ||
* @prop {Logger} log - The migration logger | ||
* @memberof DocumentMigrator | ||
*/ | ||
constructor({ | ||
typeRegistry, | ||
kibanaVersion, | ||
minimumConvertVersion = DEFAULT_MINIMUM_CONVERT_VERSION, | ||
log, | ||
}: DocumentMigratorOptions) { | ||
validateMigrationDefinition(typeRegistry, kibanaVersion, minimumConvertVersion); | ||
constructor({ typeRegistry, kibanaVersion, convertVersion, log }: DocumentMigratorOptions) { | ||
validateMigrationDefinition(typeRegistry, kibanaVersion, convertVersion); | ||
|
||
this.documentMigratorOptions = { typeRegistry, kibanaVersion, log }; | ||
} | ||
|
@@ -300,7 +293,7 @@ function validateMigrationsMapObject( | |
function validateMigrationDefinition( | ||
registry: ISavedObjectTypeRegistry, | ||
kibanaVersion: string, | ||
minimumConvertVersion: string | ||
convertVersion?: string | ||
) { | ||
function assertObjectOrFunction(entity: any, prefix: string) { | ||
if (!entity || (typeof entity !== 'function' && typeof entity !== 'object')) { | ||
|
@@ -321,9 +314,9 @@ function validateMigrationDefinition( | |
throw new Error( | ||
`Invalid convertToMultiNamespaceTypeVersion for type ${type}. Expected value to be a semver, but got '${convertToMultiNamespaceTypeVersion}'.` | ||
); | ||
} else if (Semver.lt(convertToMultiNamespaceTypeVersion, minimumConvertVersion)) { | ||
} else if (convertVersion && Semver.neq(convertToMultiNamespaceTypeVersion, convertVersion)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My gut feeling would have been to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That could we useful if in the future we wish to unfreeze the functionality. |
||
throw new Error( | ||
`Invalid convertToMultiNamespaceTypeVersion for type ${type}. Value '${convertToMultiNamespaceTypeVersion}' cannot be less than '${minimumConvertVersion}'.` | ||
`Invalid convertToMultiNamespaceTypeVersion for type ${type}. Value '${convertToMultiNamespaceTypeVersion}' cannot be any other than '${convertVersion}'.` | ||
); | ||
} else if (Semver.gt(convertToMultiNamespaceTypeVersion, kibanaVersion)) { | ||
throw new Error( | ||
|
@@ -345,6 +338,7 @@ function validateMigrationDefinition( | |
); | ||
} | ||
if (convertToMultiNamespaceTypeVersion) { | ||
// CHECKPOINT 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Checkpoint! |
||
assertValidConvertToMultiNamespaceType( | ||
namespaceType, | ||
convertToMultiNamespaceTypeVersion, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,10 @@ import { createIndexMap } from './core/build_index_map'; | |
import { runResilientMigrator } from './run_resilient_migrator'; | ||
import { migrateRawDocsSafely } from './core/migrate_raw_docs'; | ||
|
||
// ensure plugins don't try to convert SO namespaceTypes after 8.0.0 | ||
// see https://github.com/elastic/kibana/issues/147344 | ||
const ALLOWED_CONVERT_VERSION = '8.0.0'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll defer to @rudolf, but are we sure we don't want to allow type owners to migrate to shareable until some versions to come? This PR basically hard block any type from being converted as soon as merged. I want to make sure we're fine with the consequences. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if I understood correctly, this is a pre-requisite to only migrate an index if necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW I just saw #147198, but it is converting from "agnostic". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My 2cents are: as claimed in #147344, if we are not reindexing when there are no mapping updates (or, at least, no breaking changes), we cannot support any further version unless we change the current logic to identify that we need reindex anyway because a conversion must happen. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah if someone REALLY REALLY REALLY needs this we'll need to re-enable and detect this to ensure we reindex (which again will introduce downtime). Re #147198 this is sort of a unique case because it's a new saved object type, there aren't any |
||
|
||
export interface KibanaMigratorOptions { | ||
client: ElasticsearchClient; | ||
typeRegistry: ISavedObjectTypeRegistry; | ||
|
@@ -92,6 +96,7 @@ export class KibanaMigrator implements IKibanaMigrator { | |
this.kibanaVersion = kibanaVersion; | ||
this.documentMigrator = new DocumentMigrator({ | ||
kibanaVersion: this.kibanaVersion, | ||
convertVersion: ALLOWED_CONVERT_VERSION, | ||
typeRegistry, | ||
log: this.log, | ||
}); | ||
|
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.