-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Test for a failed clone during split migration #158998
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b539b1a
Single updateAliases() for all migrators when relocating during upgrade
gsoldevila 4d2619f
Fix typeCheck and UT issues
gsoldevila 3508ece
Remove unneccessary return from throw statements
gsoldevila cd9f294
Rollback changes in update_aliases.ts
gsoldevila bceb37c
Merge branch 'main' into kbn-158733-index-migrated-sync
gsoldevila 13e9828
Fix outdated integration test
gsoldevila fa263ee
Fix integration test
gsoldevila 3c50588
Handle "other indices not found" conflict
gsoldevila 23b4e39
Address PR feedback
gsoldevila 6eafe91
Test for failed clone that could lead to data loss during split migra…
rudolf 22e3063
Remove unecessary ts-expect-error
rudolf dc8fd8d
Merge branch 'main' into kbn-158733-test
rudolf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
188 changes: 188 additions & 0 deletions
188
...re/server/integration_tests/saved_objects/migrations/group3/split_failed_to_clone.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,188 @@ | ||
/* | ||
* 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 type { TestElasticsearchUtils } from '@kbn/core-test-helpers-kbn-server'; | ||
import { | ||
type ISavedObjectTypeRegistry, | ||
type SavedObjectsType, | ||
MAIN_SAVED_OBJECT_INDEX, | ||
} from '@kbn/core-saved-objects-server'; | ||
import { DEFAULT_INDEX_TYPES_MAP } from '@kbn/core-saved-objects-base-server-internal'; | ||
import { | ||
clearLog, | ||
startElasticsearch, | ||
getKibanaMigratorTestKit, | ||
getCurrentVersionTypeRegistry, | ||
overrideTypeRegistry, | ||
getAggregatedTypesCount, | ||
type KibanaMigratorTestKit, | ||
} from '../kibana_migrator_test_kit'; | ||
import { delay } from '../test_utils'; | ||
import '../jest_matchers'; | ||
import { CloneIndexParams } from '@kbn/core-saved-objects-migration-server-internal/src/actions'; | ||
|
||
// mock clone_index from packages/core | ||
jest.mock('@kbn/core-saved-objects-migration-server-internal/src/actions/clone_index', () => { | ||
const realModule = jest.requireActual( | ||
'@kbn/core-saved-objects-migration-server-internal/src/actions/clone_index' | ||
); | ||
return { | ||
...realModule, | ||
cloneIndex: (params: CloneIndexParams) => async () => { | ||
// we need to slow down the clone operation for indices other than | ||
// .kibana so that .kibana can completely finish the migration before we | ||
// fail | ||
if (params.target.includes('slow_clone')) | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
return realModule.cloneIndex(params)(); | ||
}, | ||
}; | ||
}); | ||
|
||
// define a type => index distribution | ||
const RELOCATE_TYPES: Record<string, string> = { | ||
dashboard: '.kibana_slow_clone_1', | ||
visualization: '.kibana_slow_clone_1', | ||
'canvas-workpad': '.kibana_slow_clone_1', | ||
search: '.kibana_slow_clone_2', | ||
task: '.kibana_task_manager', | ||
'epm-packages-assets': '.kibana_slow_clone_1', | ||
// the remaining types will be forced to go to '.kibana', | ||
// overriding `indexPattern: foo` defined in the registry | ||
}; | ||
|
||
export const logFilePath = Path.join(__dirname, 'split_failed_to_clone.test.log'); | ||
|
||
describe('when splitting .kibana into multiple indices and one clone fails', () => { | ||
let esServer: TestElasticsearchUtils['es']; | ||
let typeRegistry: ISavedObjectTypeRegistry; | ||
let migratorTestKitFactory: () => Promise<KibanaMigratorTestKit>; | ||
|
||
beforeAll(async () => { | ||
typeRegistry = await getCurrentVersionTypeRegistry({ oss: false }); | ||
await clearLog(logFilePath); | ||
esServer = await startElasticsearch({ | ||
dataArchive: Path.join(__dirname, '..', 'archives', '7.14.0_xpack_sample_saved_objects.zip'), | ||
timeout: 60000, | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await esServer?.stop(); | ||
await delay(2); | ||
}); | ||
|
||
it('after resolving the problem and retrying the migration completes successfully', async () => { | ||
const updatedTypeRegistry = overrideTypeRegistry( | ||
typeRegistry, | ||
(type: SavedObjectsType<any>) => { | ||
return { | ||
...type, | ||
indexPattern: RELOCATE_TYPES[type.name] ?? MAIN_SAVED_OBJECT_INDEX, | ||
}; | ||
} | ||
); | ||
|
||
migratorTestKitFactory = () => | ||
getKibanaMigratorTestKit({ | ||
types: updatedTypeRegistry.getAllTypes(), | ||
kibanaIndex: '.kibana', | ||
logFilePath, | ||
defaultIndexTypesMap: DEFAULT_INDEX_TYPES_MAP, | ||
}); | ||
|
||
const { runMigrations: runMigrationsWhichFailsWhenCloning, client } = | ||
await migratorTestKitFactory(); | ||
|
||
// count of types in the legacy index | ||
expect(await getAggregatedTypesCount(client, '.kibana')).toEqual({ | ||
'apm-telemetry': 1, | ||
application_usage_daily: 4, | ||
'canvas-workpad': 3, | ||
'canvas-workpad-template': 5, | ||
config: 1, | ||
'core-usage-stats': 1, | ||
dashboard: 19, | ||
'epm-packages': 3, | ||
'epm-packages-assets': 293, | ||
event_loop_delays_daily: 1, | ||
'graph-workspace': 3, | ||
'index-pattern': 5, | ||
'ingest-agent-policies': 2, | ||
'ingest-outputs': 1, | ||
'ingest-package-policies': 2, | ||
ingest_manager_settings: 1, | ||
map: 3, | ||
'osquery-usage-metric': 1, | ||
'sample-data-telemetry': 3, | ||
search: 14, | ||
space: 1, | ||
'spaces-usage-stats': 1, | ||
telemetry: 1, | ||
'ui-metric': 5, | ||
'usage-counters': 4, | ||
visualization: 173, | ||
}); | ||
|
||
// cause a failure when cloning .kibana_slow_clone_* indices | ||
client.cluster.putSettings({ persistent: { 'cluster.max_shards_per_node': 15 } }); | ||
|
||
await expect(runMigrationsWhichFailsWhenCloning()).rejects.toThrowError( | ||
/cluster_shard_limit_exceeded/ | ||
); | ||
|
||
// remove the failure | ||
client.cluster.putSettings({ persistent: { 'cluster.max_shards_per_node': 20 } }); | ||
|
||
const { runMigrations: runMigrations2ndTime } = await migratorTestKitFactory(); | ||
await runMigrations2ndTime(); | ||
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, consider wrapping in await expect(runMigrations2ndTime()).resolves.toBe(undefined) |
||
|
||
expect(await getAggregatedTypesCount(client, '.kibana')).toMatchInlineSnapshot(` | ||
Object { | ||
"apm-telemetry": 1, | ||
"application_usage_daily": 4, | ||
"canvas-workpad-template": 5, | ||
"config": 1, | ||
"core-usage-stats": 1, | ||
"epm-packages": 3, | ||
"event_loop_delays_daily": 1, | ||
"graph-workspace": 3, | ||
"index-pattern": 5, | ||
"ingest-agent-policies": 2, | ||
"ingest-outputs": 1, | ||
"ingest-package-policies": 2, | ||
"ingest_manager_settings": 1, | ||
"map": 3, | ||
"sample-data-telemetry": 3, | ||
"space": 1, | ||
"spaces-usage-stats": 1, | ||
"telemetry": 1, | ||
"ui-metric": 5, | ||
"usage-counters": 4, | ||
} | ||
`); | ||
expect(await getAggregatedTypesCount(client, '.kibana_slow_clone_1')).toMatchInlineSnapshot(` | ||
Object { | ||
"canvas-workpad": 3, | ||
"dashboard": 19, | ||
"epm-packages-assets": 293, | ||
"visualization": 173, | ||
} | ||
`); | ||
expect(await getAggregatedTypesCount(client, '.kibana_slow_clone_2')).toMatchInlineSnapshot(` | ||
Object { | ||
"search": 14, | ||
} | ||
`); | ||
|
||
// If we run a third time, we should not get any errors | ||
const { runMigrations: runMigrations3rdTime } = await migratorTestKitFactory(); | ||
await runMigrations3rdTime(); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit, we can leverage jest, should result in slight better error reporting (same for further down)