Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
5628372
updated logic of the migrations state action machine...
jloleysens Dec 12, 2022
7369b5f
added a first test for skipping reindex...
jloleysens Dec 13, 2022
6821312
merge check for version complete and mappings diff check
jloleysens Dec 13, 2022
3f12454
remove unused import
jloleysens Dec 13, 2022
a09d8e2
updated target index and alias creation logic
jloleysens Dec 13, 2022
d431a24
remove desired mappings and refactor "else if" structure to "if retur…
jloleysens Dec 13, 2022
8c2a160
refactor const name for clarity
jloleysens Dec 13, 2022
c548397
Merge branch 'main' into only-migrate-if-needed-KBNA-4488
jloleysens Dec 14, 2022
b6c7744
remove "skipReindex" flag
jloleysens Dec 14, 2022
60d2987
Merge branch 'main' into only-migrate-if-needed-KBNA-4488
jloleysens Dec 14, 2022
ab1f37b
remove unused import
jloleysens Dec 14, 2022
49fa828
Merge branch 'main' into only-migrate-if-needed-KBNA-4488
jloleysens Dec 15, 2022
ba49e5f
undo mistake from bad conflict resolution and remove "skipReindex" fl…
jloleysens Dec 15, 2022
8c64457
fix minor merge issues and added version index ready actions to actua…
jloleysens Dec 15, 2022
356a6d8
move line to below comment
jloleysens Dec 15, 2022
4761df4
fix jest test
jloleysens Dec 15, 2022
b70596c
added dedicated skip reindex test suite
jloleysens Dec 16, 2022
1e4aadc
back to else-if
jloleysens Dec 16, 2022
0261410
added new state: PREPARE_COMPATIBLE_MIGRATION
jloleysens Dec 16, 2022
197047e
added new state to next
jloleysens Dec 16, 2022
afcc227
added helper to derive alias name from index name
jloleysens Dec 16, 2022
1875049
added handling of new state to model
jloleysens Dec 16, 2022
cbedba4
updated jest integration test to check for new state
jloleysens Dec 16, 2022
eda7945
updated jest test to check for new migration state
jloleysens Dec 16, 2022
ffb7f7f
removed assert and added comment about what we are trying to achieve …
jloleysens Dec 16, 2022
ffe6aa9
added unit test and comment
jloleysens Dec 16, 2022
11d4dfc
Merge branch 'main' into only-migrate-if-needed-KBNA-4488
jloleysens Dec 16, 2022
b10f107
added helper to build remove alias actions dynamically
jloleysens Dec 16, 2022
d5c8c61
remove non existent imports
jloleysens Dec 16, 2022
3b8c10e
Merge branch 'main' into only-migrate-if-needed-KBNA-4488
jloleysens Dec 19, 2022
64799be
set the targetIndexCurrentMappings, should skip UPDATE_TARGET_MAPPING…
jloleysens Dec 19, 2022
bd93480
remove "runs UPDATE_TARGET_MAPPINGS even if the mappings have NOT cha…
jloleysens Dec 19, 2022
eb52fad
remove unused import
jloleysens Dec 19, 2022
59bbb63
update skip reindex test
jloleysens Dec 19, 2022
b6e358e
set the new version alias earlier
jloleysens Dec 19, 2022
28e951d
update model state test to include check for pre transform actions
jloleysens Dec 19, 2022
362f195
fixed some old comments
jloleysens Dec 19, 2022
fa124f8
update expectation after moving alias update actions
jloleysens Dec 19, 2022
75cbee3
rename variable
jloleysens Dec 19, 2022
7f62263
use variable
jloleysens Dec 19, 2022
67390d8
slightly optimise how keys are assigned
jloleysens Dec 19, 2022
aa0ccf8
use the .kibana index when handling "version migration completed" path
jloleysens Dec 19, 2022
9eae3c1
also test that Kibana restart after "compatible migration" works
jloleysens Dec 19, 2022
ecaccf0
Merge branch 'main' into only-migrate-if-needed-KBNA-4488
jloleysens Dec 20, 2022
ba76434
refactored targetIndexCurrentMappings => targetIndexRawMappings
jloleysens Dec 20, 2022
f93136f
Merge branch 'main' into only-migrate-if-needed-KBNA-4488
jloleysens Dec 23, 2022
65b8375
[CI] Auto-commit changed files from 'node scripts/ts_project_linter -…
kibanamachine Dec 23, 2022
c0ef45d
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Dec 23, 2022
5eef37a
Address PR comments
gsoldevila Dec 23, 2022
b8e7193
Fix UT
gsoldevila Dec 23, 2022
0c12d57
Fix CI check errors
gsoldevila Dec 23, 2022
5849c91
Update outdated snapshot
gsoldevila Dec 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
addMustClausesToBoolQuery,
addMustNotClausesToBoolQuery,
getAliases,
buildRemoveAliasActions,
versionMigrationCompleted,
} from './helpers';

Expand Down Expand Up @@ -267,3 +268,22 @@ describe('versionMigrationCompleted', () => {
expect(versionMigrationCompleted('.current-alias', '.version-alias', {})).toBe(false);
});
});

describe('buildRemoveAliasActions', () => {
test('empty', () => {
expect(buildRemoveAliasActions('.kibana_test_123', [], [])).toEqual([]);
});
test('no exclusions', () => {
expect(buildRemoveAliasActions('.kibana_test_123', ['a', 'b', 'c'], [])).toEqual([
{ remove: { index: '.kibana_test_123', alias: 'a', must_exist: true } },
{ remove: { index: '.kibana_test_123', alias: 'b', must_exist: true } },
{ remove: { index: '.kibana_test_123', alias: 'c', must_exist: true } },
]);
});
test('with exclusions', () => {
expect(buildRemoveAliasActions('.kibana_test_123', ['a', 'b', 'c'], ['b'])).toEqual([
{ remove: { index: '.kibana_test_123', alias: 'a', must_exist: true } },
{ remove: { index: '.kibana_test_123', alias: 'c', must_exist: true } },
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
import * as Either from 'fp-ts/lib/Either';
import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal';
import type { State } from '../state';
import type { FetchIndexResponse } from '../actions';
import type { AliasAction, FetchIndexResponse } from '../actions';

/**
* A helper function/type for ensuring that all control state's are handled.
Expand Down Expand Up @@ -189,3 +189,19 @@ export function getAliases(

return Either.right(aliases);
}

/**
* Build a list of alias actions to remove the provided aliases from the given index.
*/
export function buildRemoveAliasActions(
index: string,
aliases: string[],
exclude: string[]
): AliasAction[] {
return aliases.flatMap((alias) => {
if (exclude.includes(alias)) {
return [];
}
return [{ remove: { index, alias, must_exist: true } }];
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as Option from 'fp-ts/lib/Option';
import type { SavedObjectsRawDoc } from '@kbn/core-saved-objects-server';
import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal';
import type {
FatalState,
State,
Expand Down Expand Up @@ -45,6 +46,7 @@ import type {
CheckVersionIndexReadyActions,
UpdateTargetMappingsMeta,
CheckTargetMappingsState,
PrepareCompatibleMigration,
} from '../state';
import { type TransformErrorObjects, TransformSavedObjectDocumentError } from '../core';
import type { AliasAction, RetryableEsClientError } from '../actions';
Expand All @@ -53,6 +55,20 @@ import { createInitialProgress } from './progress';
import { model } from './model';

describe('migrations v2 model', () => {
const indexMapping: IndexMapping = {
properties: {
new_saved_object_type: {
properties: {
value: { type: 'text' },
},
},
},
_meta: {
migrationMappingPropertyHashes: {
new_saved_object_type: '4a11183eee21e6fbad864f7a30b39ad0',
},
},
};
const baseState: BaseState = {
controlState: '',
legacyIndex: '.kibana',
Expand All @@ -67,20 +83,7 @@ describe('migrations v2 model', () => {
discardCorruptObjects: false,
indexPrefix: '.kibana',
outdatedDocumentsQuery: {},
targetIndexMappings: {
properties: {
new_saved_object_type: {
properties: {
value: { type: 'text' },
},
},
},
_meta: {
migrationMappingPropertyHashes: {
new_saved_object_type: '4a11183eee21e6fbad864f7a30b39ad0',
},
},
},
targetIndexMappings: indexMapping,
tempIndexMappings: { properties: {} },
preMigrationScript: Option.none,
currentAlias: '.kibana',
Expand Down Expand Up @@ -265,7 +268,7 @@ describe('migrations v2 model', () => {
settings: {},
},
});
const newState = model(initState, res);
const newState = model(initState, res) as OutdatedDocumentsSearchOpenPit;

expect(newState.controlState).toEqual('OUTDATED_DOCUMENTS_SEARCH_OPEN_PIT');
// This snapshot asserts that we merge the
Expand All @@ -292,6 +295,22 @@ describe('migrations v2 model', () => {
},
}
`);
expect(newState.targetIndexRawMappings).toEqual({
_meta: {
migrationMappingPropertyHashes: {
disabled_saved_object_type: '7997cf5a56cc02bdc9c93361bde732b0',
},
},
properties: {
disabled_saved_object_type: {
properties: {
value: {
type: 'keyword',
},
},
},
},
});
expect(newState.retryCount).toEqual(0);
expect(newState.retryDelay).toEqual(0);
});
Expand Down Expand Up @@ -498,6 +517,7 @@ describe('migrations v2 model', () => {
expect(newState.retryDelay).toEqual(2000);
});
});

describe('if waitForMigrationCompletion=false', () => {
const initState = Object.assign({}, initBaseState, {
waitForMigrationCompletion: false,
Expand Down Expand Up @@ -787,6 +807,67 @@ describe('migrations v2 model', () => {
expect(newState.retryCount).toEqual(0);
expect(newState.retryDelay).toEqual(0);
});

describe('when upgrading to a new stack version', () => {
const unchangedMappingsState: State = {
...baseState,
controlState: 'INIT',
kibanaVersion: '7.12.0', // new version!
currentAlias: '.kibana',
versionAlias: '.kibana_7.12.0',
versionIndex: '.kibana_7.11.0_001',
};
it('INIT -> PREPARE_COMPATIBLE_MIGRATION when the mappings have not changed', () => {
const res: ResponseType<'INIT'> = Either.right({
'.kibana_7.11.0_001': {
aliases: {
'.kibana': {},
'.kibana_7.11.0': {},
},
mappings: indexMapping,
settings: {},
},
});
const newState = model(unchangedMappingsState, res) as PrepareCompatibleMigration;

expect(newState.controlState).toEqual('PREPARE_COMPATIBLE_MIGRATION');
expect(newState.targetIndexRawMappings).toEqual({
_meta: {
migrationMappingPropertyHashes: {
new_saved_object_type: '4a11183eee21e6fbad864f7a30b39ad0',
},
},
properties: {
new_saved_object_type: {
properties: {
value: {
type: 'text',
},
},
},
},
});
expect(newState.versionAlias).toEqual('.kibana_7.12.0');
expect(newState.currentAlias).toEqual('.kibana');
// will point to
expect(newState.targetIndex).toEqual('.kibana_7.11.0_001');
expect(newState.preTransformDocsActions).toEqual([
{
add: {
alias: '.kibana_7.12.0',
index: '.kibana_7.11.0_001',
},
},
{
remove: {
alias: '.kibana_7.11.0',
index: '.kibana_7.11.0_001',
must_exist: true,
},
},
]);
});
});
});
});

Expand Down Expand Up @@ -1893,6 +1974,47 @@ describe('migrations v2 model', () => {
});
});

describe('PREPARE_COMPATIBLE_MIGRATIONS', () => {
const someAliasAction: AliasAction = { add: { index: '.kibana', alias: '.kibana_8.7.0' } };
const state: PrepareCompatibleMigration = {
...baseState,
controlState: 'PREPARE_COMPATIBLE_MIGRATION',
versionIndexReadyActions: Option.none,
sourceIndex: Option.some('.kibana') as Option.Some<string>,
targetIndex: '.kibana_7.11.0_001',
preTransformDocsActions: [someAliasAction],
};

it('PREPARE_COMPATIBLE_MIGRATIONS -> OUTDATED_DOCUMENTS_SEARCH_OPEN_PIT if action succeeds', () => {
const res: ResponseType<'PREPARE_COMPATIBLE_MIGRATION'> = Either.right(
'update_aliases_succeeded'
);
const newState = model(state, res) as OutdatedDocumentsSearchOpenPit;
expect(newState.controlState).toEqual('OUTDATED_DOCUMENTS_SEARCH_OPEN_PIT');
expect(newState.versionIndexReadyActions).toEqual(Option.none);
});

it('PREPARE_COMPATIBLE_MIGRATIONS -> OUTDATED_DOCUMENTS_SEARCH_OPEN_PIT if action fails because the alias is not found', () => {
const res: ResponseType<'PREPARE_COMPATIBLE_MIGRATION'> = Either.left({
type: 'alias_not_found_exception',
});

const newState = model(state, res) as OutdatedDocumentsSearchOpenPit;
expect(newState.controlState).toEqual('OUTDATED_DOCUMENTS_SEARCH_OPEN_PIT');
expect(newState.versionIndexReadyActions).toEqual(Option.none);
});

it('throws an exception if action fails with an error other than a missing alias', () => {
const res: ResponseType<'PREPARE_COMPATIBLE_MIGRATION'> = Either.left({
type: 'remove_index_not_a_concrete_index',
});

expect(() => model(state, res)).toThrowErrorMatchingInlineSnapshot(
`"PREPARE_COMPATIBLE_MIGRATION received unexpected action response: {\\"type\\":\\"remove_index_not_a_concrete_index\\"}"`
);
});
});

describe('OUTDATED_DOCUMENTS_SEARCH_OPEN_PIT', () => {
const state: OutdatedDocumentsSearchOpenPit = {
...baseState,
Expand Down
Loading