Skip to content

Commit

Permalink
[APM] Make UI indices space aware (support for spaces) (elastic#126378)
Browse files Browse the repository at this point in the history
* changing structure of the saved object when migrating

* addressing PR changes

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
2 people authored and lucasfcosta committed Mar 7, 2022
1 parent 91e0cbb commit 8d8c5d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 41 deletions.
31 changes: 8 additions & 23 deletions x-pack/plugins/apm/server/saved_objects/apm_indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?: {
Expand All @@ -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',
Expand All @@ -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 } };
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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 },
};
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import { APMIndices } from '../apm_indices';

async function fetchLegacyAPMIndices(repository: ISavedObjectsRepository) {
try {
const apmIndices = await repository.get<
Partial<ApmIndicesConfig & { isSpaceAware: boolean }>
>(APM_INDEX_SETTINGS_SAVED_OBJECT_TYPE, APM_INDEX_SETTINGS_SAVED_OBJECT_ID);
const apmIndices = await repository.get<Partial<APMIndices>>(
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;
Expand Down Expand Up @@ -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,
};

Expand Down

0 comments on commit 8d8c5d0

Please sign in to comment.