Skip to content

Commit

Permalink
[SLM] Hide system indices in snapshot restore flow (#123365)
Browse files Browse the repository at this point in the history
* Dedupe system indices from indices array

* commit using @elastic.co

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
sabarasaba and kibanamachine authored Jan 24, 2022
1 parent 556d00d commit ed51852
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -31,6 +31,12 @@ describe('Snapshot serialization and deserialization', () => {
failed: 1,
successful: 2,
},
feature_states: [
{
feature_name: 'kibana',
indices: ['.kibana'],
},
],
failures: [
{
index: 'z',
Expand Down Expand Up @@ -71,6 +77,12 @@ describe('Snapshot serialization and deserialization', () => {
failed: 1,
successful: 2,
},
feature_states: [
{
feature_name: 'kibana',
indices: ['.kibana'],
},
],
failures: [
{
index: 'z',
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { sortBy } from 'lodash';
import { flow, map, flatten, uniq } from 'lodash/fp';

import {
SnapshotDetails,
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -80,7 +100,7 @@ export function deserializeSnapshotDetails(
uuid,
versionId,
version,
indices: [...indices].sort(),
indices: snapshotIndicesWithoutSystemIndices,
dataStreams: [...dataStreams].sort(),
includeGlobalState,
state,
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/snapshot_restore/common/types/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ed51852

Please sign in to comment.