diff --git a/x-pack/plugins/apm/public/components/routing/templates/settings_template.test.tsx b/x-pack/plugins/apm/public/components/routing/templates/settings_template.test.tsx index c717389361012..b760bb3125722 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/settings_template.test.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/settings_template.test.tsx @@ -51,7 +51,6 @@ function Wrapper({ children }: { children?: ReactNode }) { ); } -// TODO describe('Settings', () => { it('renders', async () => { const routerProps = { 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 e652d9cb870a8..ff7453a4b965e 100644 --- a/x-pack/plugins/apm/server/saved_objects/apm_indices.ts +++ b/x-pack/plugins/apm/server/saved_objects/apm_indices.ts @@ -7,6 +7,7 @@ import { SavedObjectsType } from 'src/core/server'; import { i18n } from '@kbn/i18n'; +import { updateApmOssIndexPaths } from './migrations/update_apm_oss_index_paths'; export const apmIndices: SavedObjectsType = { name: 'apm-indices', @@ -33,24 +34,6 @@ export const apmIndices: SavedObjectsType = { 'xpack.apm.metricsIndices': { type: 'keyword', }, - 'apm_oss.sourcemapIndices': { - type: 'keyword', - }, - 'apm_oss.errorIndices': { - type: 'keyword', - }, - 'apm_oss.onboardingIndices': { - type: 'keyword', - }, - 'apm_oss.spanIndices': { - type: 'keyword', - }, - 'apm_oss.transactionIndices': { - type: 'keyword', - }, - 'apm_oss.metricsIndices': { - type: 'keyword', - }, }, }, management: { @@ -61,4 +44,10 @@ export const apmIndices: SavedObjectsType = { defaultMessage: 'APM Settings - Index', }), }, + migrations: { + '7.16.0': (doc) => { + const attributes = updateApmOssIndexPaths(doc.attributes); + return { ...doc, attributes }; + }, + }, }; diff --git a/x-pack/plugins/apm/server/saved_objects/migrations/update_apm_oss_index_paths.ts b/x-pack/plugins/apm/server/saved_objects/migrations/update_apm_oss_index_paths.ts new file mode 100644 index 0000000000000..5999a37ee44b1 --- /dev/null +++ b/x-pack/plugins/apm/server/saved_objects/migrations/update_apm_oss_index_paths.ts @@ -0,0 +1,39 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +const apmIndexConfigPaths = [ + ['xpack.apm.sourcemapIndices', 'apm_oss.sourcemapIndices'], + ['xpack.apm.errorIndices', 'apm_oss.errorIndices'], + ['xpack.apm.onboardingIndices', 'apm_oss.onboardingIndices'], + ['xpack.apm.spanIndices', 'apm_oss.spanIndices'], + ['xpack.apm.transactionIndices', 'apm_oss.transactionIndices'], + ['xpack.apm.metricsIndices', 'apm_oss.metricsIndices'], +] as const; + +type ApmIndexConfigsPaths = typeof apmIndexConfigPaths[number][0]; +type ApmIndicesSavedObjectAttributes = Partial<{ + [Property in ApmIndexConfigsPaths]: string; +}>; +type DeprecatedApmIndexConfigsPaths = typeof apmIndexConfigPaths[number][1]; +type DeprecatedApmIndicesSavedObjectAttributes = Partial<{ + [Property in DeprecatedApmIndexConfigsPaths]: string; +}>; + +export function updateApmOssIndexPaths( + attributes: DeprecatedApmIndicesSavedObjectAttributes +) { + return apmIndexConfigPaths.reduce( + (attrs, [configPath, deprecatedConfigPath]) => { + const indexConfig: string | undefined = attributes[deprecatedConfigPath]; + if (indexConfig) { + attrs[configPath] = indexConfig; + } + return attrs; + }, + {} as ApmIndicesSavedObjectAttributes + ); +}