-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f566e17
commit 1fdbf28
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+2.13 MB
...e/server/saved_objects/migrationsv2/integration_tests/archives/7.13.0_with_unknown_so.zip
Binary file not shown.
133 changes: 133 additions & 0 deletions
133
...erver/saved_objects/migrationsv2/integration_tests/migration_7_13_0_unknown_types.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,133 @@ | ||
/* | ||
* 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 { estypes } from '@elastic/elasticsearch'; | ||
import * as kbnTestServer from '../../../../test_helpers/kbn_server'; | ||
import { Root } from '../../../root'; | ||
|
||
const logFilePath = Path.join(__dirname, '7_13_unknown_types_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', | ||
// dataset contains 2 type of unknown docs | ||
// `foo` documents | ||
// `space` documents (to mimic a migration with disabled plugins) | ||
dataArchive: Path.join(__dirname, 'archives', '7.13.0_with_unknown_so.zip'), | ||
}, | ||
}, | ||
}); | ||
|
||
root = createRoot(); | ||
|
||
esServer = await startES(); | ||
await root.setup(); | ||
|
||
try { | ||
await root.start(); | ||
} catch (err) { | ||
const errorMessage = err.message; | ||
|
||
expect( | ||
errorMessage.startsWith( | ||
'Unable to complete saved object migrations for the [.kibana] index: Migration failed because documents ' + | ||
'from unknown types were found. To proceed with the migration, please delete these documents from the ' + | ||
'".kibana_7.13.0_001" index.' | ||
) | ||
).toBeTruthy(); | ||
|
||
const unknownDocs = [ | ||
{ type: 'space', id: 'space:default' }, | ||
{ type: 'space', id: 'space:first' }, | ||
{ type: 'space', id: 'space:second' }, | ||
{ type: 'space', id: 'space:third' }, | ||
{ type: 'space', id: 'space:forth' }, | ||
{ type: 'space', id: 'space:fifth' }, | ||
{ type: 'space', id: 'space:sixth' }, | ||
{ type: 'foo', id: 'P2SQfHkBs3dBRGh--No5' }, | ||
{ type: 'foo', id: 'QGSZfHkBs3dBRGh-ANoD' }, | ||
{ type: 'foo', id: 'QWSZfHkBs3dBRGh-hNob' }, | ||
]; | ||
|
||
unknownDocs.forEach(({ id, type }) => { | ||
expect(errorMessage).toEqual(expect.stringContaining(`- "${id}" (type: "${type}")`)); | ||
}); | ||
|
||
const client = esServer.es.getClient(); | ||
const { body: response } = await client.indices.getSettings({ index: '.kibana_7.13.0_001' }); | ||
const settings = response['.kibana_7.13.0_001'] | ||
.settings as estypes.IndicesIndexStatePrefixedSettings; | ||
expect(settings.index).not.toBeUndefined(); | ||
expect(settings.index!.blocks?.write).not.toEqual('true'); | ||
} | ||
}); | ||
}); | ||
|
||
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, | ||
} | ||
); | ||
} |