Skip to content
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

Add migrations.discardCorruptObjects flag #132984

Merged
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0f053fd
Add migrations.ignoreUnknownObjects flag
gsoldevila May 12, 2022
6f2170e
Misc enhancements following PR comments, fix UTs
gsoldevila May 16, 2022
7aaa4da
Merge branch 'main' into kbn-126672-129016-ignore-unknown-objects
gsoldevila May 16, 2022
0280825
Fix validation
gsoldevila May 16, 2022
1324337
Make check_for_unknown_docs flag-agnostic. Misc enhancements
gsoldevila May 18, 2022
d2f5ea7
Merge branch 'main' into kbn-126672-129016-ignore-unknown-objects
gsoldevila May 18, 2022
f910871
Minor fixes
gsoldevila May 18, 2022
88f4462
Fix UTs
gsoldevila May 18, 2022
d22fa73
misc doc updates
gsoldevila May 18, 2022
51c429a
Simplify excludeOnUpgradeQuery helper methods
gsoldevila May 20, 2022
1ef635e
Merge branch 'main' into kbn-126672-129016-ignore-unknown-objects
gsoldevila May 20, 2022
9376ffa
Improve unknown type detection, improve e2e tests
gsoldevila May 23, 2022
13947ae
Merge branch 'main' into kbn-126672-129016-ignore-unknown-objects
gsoldevila May 23, 2022
24c4e48
Fix tests
gsoldevila May 23, 2022
4e44a35
Simplify queries for unknown types, use "missing:" in agg
gsoldevila May 24, 2022
7a4ffaf
Merge branch 'main' into kbn-126672-129016-ignore-unknown-objects
gsoldevila May 24, 2022
a23db47
Unify logic from unknown_object_types and check_for_unknown_docs
gsoldevila May 25, 2022
9fd3853
Merge branch 'main' into kbn-126672-129016-ignore-unknown-objects
gsoldevila May 25, 2022
072a71a
Merge branch 'main' into kbn-126672-129016-ignore-unknown-objects
gsoldevila May 25, 2022
11fe187
Merge branch 'main' into kbn-126672-129016-ignore-unknown-objects
gsoldevila May 26, 2022
4ef37f4
Small code enhancements
gsoldevila May 26, 2022
0afc773
Merge branch 'main' into kbn-126672-129016-ignore-unknown-objects
gsoldevila May 30, 2022
05016c2
Update FTs datasets mappings, ensure saved object type is a "keyword"
gsoldevila May 30, 2022
f433877
Undo changes in non-related type
gsoldevila May 30, 2022
f9145a1
Fix UTs
gsoldevila May 31, 2022
7114334
Add migrations.discardCorruptObjects flag
gsoldevila Jun 1, 2022
0b7b20e
Add migrations.discardCorruptObjects flag
gsoldevila Jun 1, 2022
f62276f
Add migrations.discardCorruptObjects flag
gsoldevila Jun 1, 2022
46386f5
Fix imports that change with new packages
gsoldevila Jun 1, 2022
bde00dc
Merge branch 'kbn-126672-129016-ignore-unknown-objects' into kbn-1290…
gsoldevila Jun 1, 2022
17912b4
Merge branch 'kbn-129018-discard-corrupts-objects' of https://github.…
gsoldevila Jun 1, 2022
a46049d
Merge branch 'main' into kbn-129018-discard-corrupts-objects
gsoldevila Jun 1, 2022
c539b62
Fix imports that change with new packages
gsoldevila Jun 1, 2022
bd58f36
Merge branch 'kbn-129018-discard-corrupts-objects' of https://github.…
gsoldevila Jun 1, 2022
4bb5be0
Fix tests
gsoldevila Jun 2, 2022
a272c37
Update Jest snapshot
gsoldevila Jun 2, 2022
926cf1f
Merge branch 'main' into kbn-129018-discard-corrupts-objects
gsoldevila Jun 2, 2022
fdf96ea
Fix snapshots
gsoldevila Jun 2, 2022
a048caa
Merge branch 'main' into kbn-129018-discard-corrupts-objects
kibanamachine Jun 6, 2022
9e687e2
Update ascii docs, revert unwanted mapping update
gsoldevila Jun 9, 2022
45e7ac0
Merge branch 'main' into kbn-129018-discard-corrupts-objects
gsoldevila Jun 9, 2022
c75533e
Revert to default log output type
gsoldevila Jun 13, 2022
5265cd6
Merge branch 'main' into kbn-129018-discard-corrupts-objects
gsoldevila Jun 13, 2022
688c1a3
Fix typo [Prebot => Preboot]
gsoldevila Jun 13, 2022
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
16 changes: 13 additions & 3 deletions docs/setup/upgrade/resolving-migration-failures.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ DELETE .kibana_7.12.0_001/_doc/marketing_space:dashboard:e3c5fc71-ac71-4805-bcab
+
The dashboard with the `e3c5fc71-ac71-4805-bcab-2bcc9cc93275` ID that belongs to the `marketing_space` space **is no longer available**.

You can configure {kib} to automatically discard all corrupt objects and transform errors that occur during a migration. When setting the configuration option `migrations.discardCorruptObjects`, {kib} will delete the conflicting objects and proceed with the migration.
For instance, for an upgrade to 8.4.0, you can define the following setting in kibana.yml:

[source,yaml]
--------------------------------------------
migrations.discardCorruptObjects: "8.4.0"
--------------------------------------------

**WARNING:** Enabling the flag above will cause the system to discard all corrupt objects, as well as those causing transform errors. Thus, it is HIGHLY recommended that you carefully review the list of conflicting objects in the logs.

[float]
[[unknown-saved-object-types]]
==== Documents for unknown saved objects
Expand Down Expand Up @@ -113,12 +123,12 @@ Unable to complete saved object migrations for the [.kibana] index: Migration fa
To proceed with the migration you can configure Kibana to discard unknown saved objects for this migration.
--------------------------------------------

To proceed with the migration, re-enable any plugins that previously created these saved objects. Alternatively, carefully review the list of unknown saved objects in the Kibana log entry. If the corresponding disabled plugins and their associated saved objects will no longer be used, they can be deleted by setting the configuration option `migrations.discardUnknownObjects` to the version you are upgrading to.
For instance, for an upgrade to 8.3.0, you can define the following setting in kibana.yml:
To proceed with the migration, re-enable any plugins that previously created these saved objects. Alternatively, carefully review the list of unknown saved objects in the {kib} log entry. If the corresponding disabled plugins and their associated saved objects will no longer be used, they can be deleted by setting the configuration option `migrations.discardUnknownObjects` to the version you are upgrading to.
For instance, for an upgrade to 8.4.0, you can define the following setting in kibana.yml:

[source,yaml]
--------------------------------------------
migrations.discardUnknownObjects: "8.3.0"
migrations.discardUnknownObjects: "8.4.0"
--------------------------------------------

[float]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,15 @@ describe('migrateRawDocsSafely', () => {
const result = (await task()) as Either.Left<DocumentsTransformFailed>;
expect(transform).toHaveBeenCalledTimes(1);
expect(result._tag).toEqual('Left');
expect(Object.keys(result.left)).toEqual(['type', 'corruptDocumentIds', 'transformErrors']);
expect(Object.keys(result.left)).toEqual([
'type',
'corruptDocumentIds',
'transformErrors',
'processedDocs',
]);
expect(result.left.corruptDocumentIds.length).toEqual(1);
expect(result.left.transformErrors.length).toEqual(0);
expect(result.left.processedDocs.length).toEqual(1);
});

test('handles when one document is transformed into multiple documents', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface DocumentsTransformFailed {
readonly type: string;
readonly corruptDocumentIds: string[];
readonly transformErrors: TransformErrorObjects[];
readonly processedDocs: SavedObjectsRawDoc[];
}

export interface DocumentsTransformSuccess {
Expand Down Expand Up @@ -139,6 +140,7 @@ export function migrateRawDocsSafely({
type: 'documents_transform_failed',
corruptDocumentIds: [...corruptSavedObjectIds],
transformErrors,
processedDocs,
});
}
return Either.right({ processedDocs });
Expand Down
53 changes: 52 additions & 1 deletion src/core/server/saved_objects/migrations/initial_state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ describe('createInitialState', () => {
docLinks = docLinksServiceMock.createSetupContract();
});

afterEach(() => jest.clearAllMocks());

const migrationsConfig = {
retryAttempts: 15,
batchSize: 1000,
maxBatchSizeBytes: ByteSizeValue.parse('100mb'),
} as unknown as SavedObjectsMigrationConfigType;

it('creates the initial state for the model based on the passed in parameters', () => {
expect(
createInitialState({
Expand All @@ -51,6 +54,7 @@ describe('createInitialState', () => {
"batchSize": 1000,
"controlState": "INIT",
"currentAlias": ".kibana_task_manager",
"discardCorruptObjects": false,
"discardUnknownObjects": false,
"excludeFromUpgradeFilterHooks": Object {},
"excludeOnUpgradeQuery": Object {
Expand Down Expand Up @@ -400,7 +404,7 @@ describe('createInitialState', () => {
expect(initialState.discardUnknownObjects).toEqual(false);
expect(logger.warn).toBeCalledTimes(1);
expect(logger.warn).toBeCalledWith(
'The flag `migrations.discardUnknownObjects` is defined but does not match the current kibana version; unknown objects will NOT be ignored.'
'The flag `migrations.discardUnknownObjects` is defined but does not match the current kibana version; unknown objects will NOT be discarded.'
);
});

Expand All @@ -424,4 +428,51 @@ describe('createInitialState', () => {

expect(initialState.discardUnknownObjects).toEqual(true);
});

it('initializes the `discardCorruptObjects` flag to false if the value provided in the config does not match the current kibana version', () => {
const logger = mockLogger.get();
const initialState = createInitialState({
kibanaVersion: '8.1.0',
targetMappings: {
dynamic: 'strict',
properties: { my_type: { properties: { title: { type: 'text' } } } },
},
migrationVersionPerType: {},
indexPrefix: '.kibana_task_manager',
migrationsConfig: {
...migrationsConfig,
discardCorruptObjects: '8.0.0',
},
typeRegistry,
docLinks,
logger,
});

expect(initialState.discardCorruptObjects).toEqual(false);
expect(logger.warn).toBeCalledTimes(1);
expect(logger.warn).toBeCalledWith(
'The flag `migrations.discardCorruptObjects` is defined but does not match the current kibana version; corrupt objects will NOT be discarded.'
);
});

it('initializes the `discardCorruptObjects` flag to true if the value provided in the config matches the current kibana version', () => {
const initialState = createInitialState({
kibanaVersion: '8.1.0',
targetMappings: {
dynamic: 'strict',
properties: { my_type: { properties: { title: { type: 'text' } } } },
},
migrationVersionPerType: {},
indexPrefix: '.kibana_task_manager',
migrationsConfig: {
...migrationsConfig,
discardCorruptObjects: '8.1.0',
},
typeRegistry,
docLinks,
logger: mockLogger.get(),
});

expect(initialState.discardCorruptObjects).toEqual(true);
});
});
12 changes: 11 additions & 1 deletion src/core/server/saved_objects/migrations/initial_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@ export const createInitialState = ({
migrationsConfig.discardUnknownObjects !== kibanaVersion
) {
logger.warn(
'The flag `migrations.discardUnknownObjects` is defined but does not match the current kibana version; unknown objects will NOT be ignored.'
'The flag `migrations.discardUnknownObjects` is defined but does not match the current kibana version; unknown objects will NOT be discarded.'
);
}

if (
migrationsConfig.discardCorruptObjects &&
migrationsConfig.discardCorruptObjects !== kibanaVersion
) {
logger.warn(
'The flag `migrations.discardCorruptObjects` is defined but does not match the current kibana version; corrupt objects will NOT be discarded.'
);
}

Expand All @@ -101,6 +110,7 @@ export const createInitialState = ({
batchSize: migrationsConfig.batchSize,
maxBatchSizeBytes: migrationsConfig.maxBatchSizeBytes.getValueInBytes(),
discardUnknownObjects: migrationsConfig.discardUnknownObjects === kibanaVersion,
discardCorruptObjects: migrationsConfig.discardCorruptObjects === kibanaVersion,
logs: [],
excludeOnUpgradeQuery: excludeUnusedTypesQuery,
knownTypes,
Expand Down
Loading