diff --git a/x-pack/plugins/apm/server/saved_objects/apm_indices.ts b/x-pack/plugins/apm/server/saved_objects/apm_indices.ts index 4a3b0d32e9667cf..fe6650fb356ff9c 100644 --- a/x-pack/plugins/apm/server/saved_objects/apm_indices.ts +++ b/x-pack/plugins/apm/server/saved_objects/apm_indices.ts @@ -8,7 +8,6 @@ import { SavedObjectsType } from 'src/core/server'; import { i18n } from '@kbn/i18n'; import { updateApmOssIndexPaths } from './migrations/update_apm_oss_index_paths'; -import { ApmIndicesConfigName } from '..'; export interface APMIndices { apmIndices?: { @@ -22,32 +21,14 @@ export interface APMIndices { isSpaceAware?: boolean; } -const properties: { - apmIndices: { - properties: { - [Property in ApmIndicesConfigName]: { type: 'keyword' }; - }; - }; - isSpaceAware: { type: 'boolean' }; -} = { - apmIndices: { - properties: { - sourcemap: { type: 'keyword' }, - error: { type: 'keyword' }, - onboarding: { type: 'keyword' }, - span: { type: 'keyword' }, - transaction: { type: 'keyword' }, - metric: { type: 'keyword' }, - }, - }, - isSpaceAware: { type: 'boolean' }, -}; - export const apmIndices: SavedObjectsType = { name: 'apm-indices', hidden: false, namespaceType: 'single', - mappings: { properties }, + mappings: { + dynamic: false, + properties: {}, // several fields exist, but we don't need to search or aggregate on them, so we exclude them from the mappings + }, management: { importableAndExportable: true, icon: 'apmApp', @@ -61,5 +42,9 @@ export const apmIndices: SavedObjectsType = { const attributes = updateApmOssIndexPaths(doc.attributes); return { ...doc, attributes }; }, + '8.2.0': (doc) => { + // Any future changes on this structure should be also tested on migrateLegacyAPMIndicesToSpaceAware + return { ...doc, attributes: { apmIndices: doc.attributes } }; + }, }, }; diff --git a/x-pack/plugins/apm/server/saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware.test.ts b/x-pack/plugins/apm/server/saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware.test.ts index 404e08a6b112b14..71488ab007c6769 100644 --- a/x-pack/plugins/apm/server/saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware.test.ts +++ b/x-pack/plugins/apm/server/saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware.test.ts @@ -81,12 +81,14 @@ describe('migrateLegacyAPMIndicesToSpaceAware', () => { updated_at: '2022-02-22T14:17:10.584Z', version: 'WzE1OSwxXQ==', attributes: { - transaction: 'default-apm-*', - span: 'default-apm-*', - error: 'default-apm-*', - metric: 'default-apm-*', - sourcemap: 'default-apm-*', - onboarding: 'default-apm-*', + apmIndices: { + transaction: 'default-apm-*', + span: 'default-apm-*', + error: 'default-apm-*', + metric: 'default-apm-*', + sourcemap: 'default-apm-*', + onboarding: 'default-apm-*', + }, }, references: [], migrationVersion: { @@ -154,12 +156,14 @@ describe('migrateLegacyAPMIndicesToSpaceAware', () => { }), }); const attributes = { - transaction: 'space-apm-*', - span: 'space-apm-*', - error: 'space-apm-*', - metric: 'space-apm-*', - sourcemap: 'space-apm-*', - onboarding: 'space-apm-*', + apmIndices: { + transaction: 'space-apm-*', + span: 'space-apm-*', + error: 'space-apm-*', + metric: 'space-apm-*', + sourcemap: 'space-apm-*', + onboarding: 'space-apm-*', + }, }; const core = { savedObjects: { @@ -197,7 +201,7 @@ describe('migrateLegacyAPMIndicesToSpaceAware', () => { type: APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE, id: APM_INDEX_SETTINGS_SAVED_OBJECT_ID, initialNamespaces: [id], - attributes: { apmIndices: attributes, isSpaceAware: true }, + attributes: { ...attributes, isSpaceAware: true }, }; }) ); diff --git a/x-pack/plugins/apm/server/saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware.ts b/x-pack/plugins/apm/server/saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware.ts index 130070b80ff14f8..3f97191a5b88a7d 100644 --- a/x-pack/plugins/apm/server/saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware.ts +++ b/x-pack/plugins/apm/server/saved_objects/migrations/migrate_legacy_apm_indices_to_space_aware.ts @@ -19,9 +19,10 @@ import { APMIndices } from '../apm_indices'; async function fetchLegacyAPMIndices(repository: ISavedObjectsRepository) { try { - const apmIndices = await repository.get< - Partial - >(APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE, APM_INDEX_SETTINGS_SAVED_OBJECT_ID); + const apmIndices = await repository.get>( + APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE, + APM_INDEX_SETTINGS_SAVED_OBJECT_ID + ); if (apmIndices.attributes.isSpaceAware) { // This has already been migrated to become space-aware return null; @@ -59,8 +60,8 @@ export async function migrateLegacyAPMIndicesToSpaceAware({ fields: ['name'], // to avoid fetching *all* fields }); - const savedObjectAttributes: APMIndices = { - apmIndices: legacyAPMIndices.attributes, + const savedObjectAttributes = { + ...legacyAPMIndices.attributes, isSpaceAware: true, };