From b0ef90dad1e5e876c87297533c516c1f20ab4f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Mon, 2 Oct 2023 13:01:23 +0200 Subject: [PATCH] [APM] Ensure APM data view is available across all spaces (#167704) --- x-pack/plugins/apm/server/plugin.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/x-pack/plugins/apm/server/plugin.ts b/x-pack/plugins/apm/server/plugin.ts index 79e5f353f3ce3..96e47f0edad19 100644 --- a/x-pack/plugins/apm/server/plugin.ts +++ b/x-pack/plugins/apm/server/plugin.ts @@ -11,6 +11,7 @@ import { Logger, Plugin, PluginInitializerContext, + SavedObjectsClient, } from '@kbn/core/server'; import { isEmpty, mapValues } from 'lodash'; import { Dataset } from '@kbn/rule-registry-plugin/server'; @@ -48,6 +49,7 @@ import { scheduleSourceMapMigration } from './routes/source_maps/schedule_source import { createApmSourceMapIndexTemplate } from './routes/source_maps/create_apm_source_map_index_template'; import { addApiKeysToEveryPackagePolicyIfMissing } from './routes/fleet/api_keys/add_api_keys_to_policies_if_missing'; import { apmTutorialCustomIntegration } from '../common/tutorial/tutorials'; +import { APM_STATIC_DATA_VIEW_ID } from '../common/data_view_constants'; export class APMPlugin implements @@ -119,6 +121,26 @@ export class APMPlugin ], }); + // ensure that the APM data view is globally available + getCoreStart() + .then(async (coreStart) => { + const soClient = new SavedObjectsClient( + coreStart.savedObjects.createInternalRepository() + ); + + await soClient.updateObjectsSpaces( + [{ id: APM_STATIC_DATA_VIEW_ID, type: 'index-pattern' }], + ['*'], + [] + ); + }) + .catch((e) => { + this.logger?.error( + 'Failed to make APM data view available globally', + e + ); + }); + const resourcePlugins = mapValues(plugins, (value, key) => { return { setup: value,