Skip to content

Commit

Permalink
performs start up migration on the saved objects mapping for apm-indices
Browse files Browse the repository at this point in the history
  • Loading branch information
ogupte committed Oct 1, 2021
1 parent d8d6a4e commit a5d2013
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function Wrapper({ children }: { children?: ReactNode }) {
);
}

// TODO
describe('Settings', () => {
it('renders', async () => {
const routerProps = {
Expand Down
25 changes: 7 additions & 18 deletions x-pack/plugins/apm/server/saved_objects/apm_indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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: {
Expand All @@ -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 };
},
},
};
Original file line number Diff line number Diff line change
@@ -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
);
}

0 comments on commit a5d2013

Please sign in to comment.