diff --git a/x-pack/plugins/snapshot_restore/common/lib/snapshot_serialization.test.ts b/x-pack/plugins/snapshot_restore/common/lib/snapshot_serialization.test.ts index de769686dc99c1..22e1e9329ca2c5 100644 --- a/x-pack/plugins/snapshot_restore/common/lib/snapshot_serialization.test.ts +++ b/x-pack/plugins/snapshot_restore/common/lib/snapshot_serialization.test.ts @@ -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, diff --git a/x-pack/plugins/snapshot_restore/common/lib/snapshot_serialization.ts b/x-pack/plugins/snapshot_restore/common/lib/snapshot_serialization.ts index f2803a571c475c..e6e047cfa5d7db 100644 --- a/x-pack/plugins/snapshot_restore/common/lib/snapshot_serialization.ts +++ b/x-pack/plugins/snapshot_restore/common/lib/snapshot_serialization.ts @@ -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, diff --git a/x-pack/plugins/snapshot_restore/common/types/snapshot.ts b/x-pack/plugins/snapshot_restore/common/types/snapshot.ts index 97f3b00d97326d..baddcac7f50947 100644 --- a/x-pack/plugins/snapshot_restore/common/types/snapshot.ts +++ b/x-pack/plugins/snapshot_restore/common/types/snapshot.ts @@ -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;