mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
# Backport This will backport the following commits from `main` to `8.8`: - [Test for a failed clone during split migration (#158998)](https://github.com/elastic/kibana/pull/158998) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Rudolf Meijering","email":"skaapgif@gmail.com"},"sourceCommit":{"committedDate":"2023-06-05T09:24:28Z","message":"Test for a failed clone during split migration (#158998)\n\n## Summary\r\n\r\nAdds a test for #158733. This is based on the un-merged #158940, so see\r\nthe last commit\r\n[#6eafe910424414b5670e5f325accc59d87dd6dc4](6eafe91042
)\r\nfor the actual changes proposed by this PR\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [ ] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] Any UI touched in this PR is usable by keyboard only (learn more\r\nabout [keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI touched in this PR does not create any new axe failures\r\n(run axe in browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n- [ ] If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n- [ ] This renders correctly on smaller devices using a responsive\r\nlayout. (You can test this [in your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n- [ ] This was checked for [cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n### Risk Matrix\r\n\r\nDelete this section if it is not applicable to this PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other developers to\r\nidentify risks that should be tested prior to the change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider some of the following examples\r\nand how they may potentially impact the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes |\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n| Multiple Spaces—unexpected behavior in non-default Kibana Space.\r\n| Low | High | Integration tests will verify that all features are still\r\nsupported in non-default Kibana Space and when user switches between\r\nspaces. |\r\n| Multiple nodes—Elasticsearch polling might have race conditions\r\nwhen multiple Kibana nodes are polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so executing them multiple times will not result\r\nin logical error, but will degrade performance. To test for this case we\r\nadd plenty of unit tests around this logic and document manual testing\r\nprocedure. |\r\n| Code should gracefully handle cases when feature X or plugin Y are\r\ndisabled. | Medium | High | Unit tests will verify that any feature flag\r\nor plugin combination still results in our service operational. |\r\n| [See more potential risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by: Gerard Soldevila <gerard.soldevila@elastic.co>","sha":"75ec1ec7c3b78b3b9ff17874e2c3008079942abd","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","backport:prev-minor","Epic:KBNA-7838","v8.9.0"],"number":158998,"url":"https://github.com/elastic/kibana/pull/158998","mergeCommit":{"message":"Test for a failed clone during split migration (#158998)\n\n## Summary\r\n\r\nAdds a test for #158733. This is based on the un-merged #158940, so see\r\nthe last commit\r\n[#6eafe910424414b5670e5f325accc59d87dd6dc4](6eafe91042
)\r\nfor the actual changes proposed by this PR\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [ ] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] Any UI touched in this PR is usable by keyboard only (learn more\r\nabout [keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI touched in this PR does not create any new axe failures\r\n(run axe in browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n- [ ] If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n- [ ] This renders correctly on smaller devices using a responsive\r\nlayout. (You can test this [in your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n- [ ] This was checked for [cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n### Risk Matrix\r\n\r\nDelete this section if it is not applicable to this PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other developers to\r\nidentify risks that should be tested prior to the change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider some of the following examples\r\nand how they may potentially impact the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes |\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n| Multiple Spaces—unexpected behavior in non-default Kibana Space.\r\n| Low | High | Integration tests will verify that all features are still\r\nsupported in non-default Kibana Space and when user switches between\r\nspaces. |\r\n| Multiple nodes—Elasticsearch polling might have race conditions\r\nwhen multiple Kibana nodes are polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so executing them multiple times will not result\r\nin logical error, but will degrade performance. To test for this case we\r\nadd plenty of unit tests around this logic and document manual testing\r\nprocedure. |\r\n| Code should gracefully handle cases when feature X or plugin Y are\r\ndisabled. | Medium | High | Unit tests will verify that any feature flag\r\nor plugin combination still results in our service operational. |\r\n| [See more potential risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by: Gerard Soldevila <gerard.soldevila@elastic.co>","sha":"75ec1ec7c3b78b3b9ff17874e2c3008079942abd"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/158998","number":158998,"mergeCommit":{"message":"Test for a failed clone during split migration (#158998)\n\n## Summary\r\n\r\nAdds a test for #158733. This is based on the un-merged #158940, so see\r\nthe last commit\r\n[#6eafe910424414b5670e5f325accc59d87dd6dc4](6eafe91042
)\r\nfor the actual changes proposed by this PR\r\n\r\n\r\n### Checklist\r\n\r\nDelete any items that are not applicable to this PR.\r\n\r\n- [ ] Any text added follows [EUI's writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\r\nsentence case text and includes [i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n- [ ]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas added for features that require explanation or tutorials\r\n- [ ] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [ ] Any UI touched in this PR is usable by keyboard only (learn more\r\nabout [keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n- [ ] Any UI touched in this PR does not create any new axe failures\r\n(run axe in browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n- [ ] If a plugin configuration key changed, check if it needs to be\r\nallowlisted in the cloud and added to the [docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n- [ ] This renders correctly on smaller devices using a responsive\r\nlayout. (You can test this [in your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n- [ ] This was checked for [cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n### Risk Matrix\r\n\r\nDelete this section if it is not applicable to this PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other developers to\r\nidentify risks that should be tested prior to the change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider some of the following examples\r\nand how they may potentially impact the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes |\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n| Multiple Spaces—unexpected behavior in non-default Kibana Space.\r\n| Low | High | Integration tests will verify that all features are still\r\nsupported in non-default Kibana Space and when user switches between\r\nspaces. |\r\n| Multiple nodes—Elasticsearch polling might have race conditions\r\nwhen multiple Kibana nodes are polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so executing them multiple times will not result\r\nin logical error, but will degrade performance. To test for this case we\r\nadd plenty of unit tests around this logic and document manual testing\r\nprocedure. |\r\n| Code should gracefully handle cases when feature X or plugin Y are\r\ndisabled. | Medium | High | Unit tests will verify that any feature flag\r\nor plugin combination still results in our service operational. |\r\n| [See more potential risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for breaking API changes and was [labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by: Gerard Soldevila <gerard.soldevila@elastic.co>","sha":"75ec1ec7c3b78b3b9ff17874e2c3008079942abd"}}]}] BACKPORT--> Co-authored-by: Rudolf Meijering <skaapgif@gmail.com>
This commit is contained in:
parent
ab7bcb8846
commit
49a8e57273
1 changed files with 188 additions and 0 deletions
|
@ -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();
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue