Skip to content
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

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -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