[SLM] Hide system indices in snapshot restore flow (#123365)

* Dedupe system indices from indices array

* commit using @elastic.co

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Ignacio Rivas 2022-01-24 10:15:03 +01:00 committed by GitHub
parent 556d00d3a8
commit ed5185283f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 8 deletions

View file

@ -18,7 +18,7 @@ describe('Snapshot serialization and deserialization', () => {
repository: 'repositoryName',
version_id: 5,
version: 'version',
indices: ['index2', 'index3', 'index1'],
indices: ['index2', 'index3', 'index1', '.kibana'],
include_global_state: false,
state: 'SUCCESS',
start_time: '0',
@ -31,6 +31,12 @@ describe('Snapshot serialization and deserialization', () => {
failed: 1,
successful: 2,
},
feature_states: [
{
feature_name: 'kibana',
indices: ['.kibana'],
},
],
failures: [
{
index: 'z',
@ -71,6 +77,12 @@ describe('Snapshot serialization and deserialization', () => {
failed: 1,
successful: 2,
},
feature_states: [
{
feature_name: 'kibana',
indices: ['.kibana'],
},
],
failures: [
{
index: 'z',
@ -98,7 +110,7 @@ describe('Snapshot serialization and deserialization', () => {
uuid: 'UUID',
versionId: 5,
version: 'version',
// Indices are sorted.
// Indices are sorted and dont include any of the system indices listed in feature_state
indices: ['index1', 'index2', 'index3'],
dataStreams: [],
includeGlobalState: false,

View file

@ -6,6 +6,7 @@
*/
import { sortBy } from 'lodash';
import { flow, map, flatten, uniq } from 'lodash/fp';
import {
SnapshotDetails,
@ -20,6 +21,19 @@ import { deserializeTime, serializeTime } from './time_serialization';
import { csvToArray } from './utils';
export const convertFeaturesToIndicesArray = (
features: SnapshotDetailsEs['feature_states']
): string[] => {
return flow(
// Map each feature into Indices[]
map('indices'),
// Flatten the array
flatten,
// And finally dedupe the indices
uniq
)(features);
};
export function deserializeSnapshotDetails(
snapshotDetailsEs: SnapshotDetailsEs,
managedRepository?: string,
@ -46,21 +60,27 @@ export function deserializeSnapshotDetails(
duration_in_millis: durationInMillis,
failures = [],
shards,
feature_states: featureStates = [],
metadata: { policy: policyName } = { policy: undefined },
} = snapshotDetailsEs;
const systemIndices = convertFeaturesToIndicesArray(featureStates);
const snapshotIndicesWithoutSystemIndices = indices
.filter((index) => !systemIndices.includes(index))
.sort();
// If an index has multiple failures, we'll want to see them grouped together.
const indexToFailuresMap = failures.reduce((map, failure) => {
const indexToFailuresMap = failures.reduce((aggregation, failure) => {
const { index, ...rest } = failure;
if (!map[index]) {
map[index] = {
if (!aggregation[index]) {
aggregation[index] = {
index,
failures: [],
};
}
map[index].failures.push(rest);
return map;
aggregation[index].failures.push(rest);
return aggregation;
}, {});
// Sort all failures by their shard.
@ -80,7 +100,7 @@ export function deserializeSnapshotDetails(
uuid,
versionId,
version,
indices: [...indices].sort(),
indices: snapshotIndicesWithoutSystemIndices,
dataStreams: [...dataStreams].sort(),
includeGlobalState,
state,

View file

@ -68,6 +68,10 @@ export interface SnapshotDetailsEs {
duration_in_millis: number;
failures: any[];
shards: SnapshotDetailsShardsStatusEs;
feature_states: Array<{
feature_name: string;
indices: string[];
}>;
metadata?: {
policy: string;
[key: string]: any;