forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SO migrations: Improves transformation error creation and testing (el…
- Loading branch information
1 parent
65e466c
commit 01ab915
Showing
10 changed files
with
207 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+2.13 MB
...ects/migrationsv2/integration_tests/archives/7_13_corrupt_and_transform_failures_docs.zip
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
.../saved_objects/migrationsv2/integration_tests/migration_7_13_0_transform_failures.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import Path from 'path'; | ||
import Fs from 'fs'; | ||
import Util from 'util'; | ||
import * as kbnTestServer from '../../../../test_helpers/kbn_server'; | ||
import { Root } from '../../../root'; | ||
|
||
const logFilePath = Path.join(__dirname, '7_13_corrupt_transform_failures_test.log'); | ||
|
||
const asyncUnlink = Util.promisify(Fs.unlink); | ||
async function removeLogFile() { | ||
// ignore errors if it doesn't exist | ||
await asyncUnlink(logFilePath).catch(() => void 0); | ||
} | ||
|
||
describe('migration v2', () => { | ||
let esServer: kbnTestServer.TestElasticsearchUtils; | ||
let root: Root; | ||
|
||
beforeAll(async () => { | ||
await removeLogFile(); | ||
}); | ||
|
||
afterAll(async () => { | ||
if (root) { | ||
await root.shutdown(); | ||
} | ||
if (esServer) { | ||
await esServer.stop(); | ||
} | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 10000)); | ||
}); | ||
|
||
it('migrates the documents to the highest version', async () => { | ||
const { startES } = kbnTestServer.createTestServers({ | ||
adjustTimeout: (t: number) => jest.setTimeout(t), | ||
settings: { | ||
es: { | ||
license: 'basic', | ||
// example of original 'foo' SO with corrupt id: | ||
// _id: one | ||
// { | ||
// foo: { | ||
// name: 'one', | ||
// }, | ||
// type: 'foo', | ||
// references: [], | ||
// migrationVersion: { | ||
// foo: '7.13.0', | ||
// }, | ||
// "coreMigrationVersion": "7.13.0", | ||
// "updated_at": "2021-05-16T18:16:45.450Z" | ||
// }, | ||
|
||
// SO that will fail transformation: | ||
// { | ||
// type: 'space', | ||
// space: {}, | ||
// }, | ||
// | ||
// | ||
dataArchive: Path.join( | ||
__dirname, | ||
'archives', | ||
'7_13_corrupt_and_transform_failures_docs.zip' | ||
), | ||
}, | ||
}, | ||
}); | ||
|
||
root = createRoot(); | ||
|
||
esServer = await startES(); | ||
const coreSetup = await root.setup(); | ||
|
||
coreSetup.savedObjects.registerType({ | ||
name: 'foo', | ||
hidden: false, | ||
mappings: { | ||
properties: {}, | ||
}, | ||
namespaceType: 'agnostic', | ||
migrations: { | ||
'7.14.0': (doc) => doc, | ||
}, | ||
}); | ||
try { | ||
await root.start(); | ||
} catch (err) { | ||
const errorMessage = err.message; | ||
expect( | ||
errorMessage.startsWith( | ||
'Unable to complete saved object migrations for the [.kibana] index: Migrations failed. Reason: Corrupt saved object documents: ' | ||
) | ||
).toBeTruthy(); | ||
expect( | ||
errorMessage.endsWith(' To allow migrations to proceed, please delete these documents.') | ||
).toBeTruthy(); | ||
|
||
const expectedCorruptDocIds = [ | ||
'P2SQfHkBs3dBRGh--No5', | ||
'QGSZfHkBs3dBRGh-ANoD', | ||
'QWSZfHkBs3dBRGh-hNob', | ||
'QmSZfHkBs3dBRGh-w9qH', | ||
'one', | ||
'two', | ||
'Q2SZfHkBs3dBRGh-9dp2', | ||
]; | ||
for (const corruptDocId of expectedCorruptDocIds) { | ||
expect(errorMessage.includes(corruptDocId)).toBeTruthy(); | ||
} | ||
const expectedTransformErrorMessage = | ||
'Transformation errors: space:default: Document "default" has property "space" which belongs to a more recent version of Kibana [6.6.0]. The last known version is [undefined]'; | ||
expect(errorMessage.includes(expectedTransformErrorMessage)).toBeTruthy(); | ||
} | ||
}); | ||
}); | ||
|
||
function createRoot() { | ||
return kbnTestServer.createRootWithCorePlugins( | ||
{ | ||
migrations: { | ||
skip: false, | ||
enableV2: true, | ||
batchSize: 5, | ||
}, | ||
logging: { | ||
appenders: { | ||
file: { | ||
type: 'file', | ||
fileName: logFilePath, | ||
layout: { | ||
type: 'json', | ||
}, | ||
}, | ||
}, | ||
loggers: [ | ||
{ | ||
name: 'root', | ||
appenders: ['file'], | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
oss: true, | ||
} | ||
); | ||
} |
Oops, something went wrong.