From 97e6c84f82955f2ddee9d4117b7659d1e49fb2b9 Mon Sep 17 00:00:00 2001 From: Miriam <31922082+MiriamAparicio@users.noreply.github.com> Date: Mon, 22 May 2023 08:56:03 +0100 Subject: [PATCH] [APM] Add feature flag to sourcemap endpoints (#157997) Part of https://github.com/elastic/kibana/issues/153776 Disallow uploading source maps endpoints to make it clear that it won't work by returning 501 Not Implemented status code --- .../apm/server/routes/source_maps/route.ts | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/server/routes/source_maps/route.ts b/x-pack/plugins/apm/server/routes/source_maps/route.ts index 8e538cebe1841..c3a748fe2a034 100644 --- a/x-pack/plugins/apm/server/routes/source_maps/route.ts +++ b/x-pack/plugins/apm/server/routes/source_maps/route.ts @@ -9,6 +9,7 @@ import { SavedObjectsClientContract } from '@kbn/core/server'; import { Artifact } from '@kbn/fleet-plugin/server'; import { jsonRt, toNumberRt } from '@kbn/io-ts-utils'; import * as t from 'io-ts'; +import { ApmFeatureFlags } from '../../../common/apm_feature_flags'; import { getInternalSavedObjectsClient } from '../../lib/helpers/get_internal_saved_objects_client'; import { stringFromBufferRt } from '../../utils/string_from_buffer_rt'; import { createApmServerRoute } from '../apm_routes/create_apm_server_route'; @@ -40,6 +41,14 @@ export const sourceMapRt = t.intersection([ export type SourceMap = t.TypeOf; +function throwNotImplementedIfSourceMapNotAvailable( + featureFlags: ApmFeatureFlags +): void { + if (!featureFlags.sourcemapApiAvailable) { + throw Boom.notImplemented(); + } +} + const listSourceMapRoute = createApmServerRoute({ endpoint: 'GET /api/apm/sourcemaps', options: { tags: ['access:apm'] }, @@ -52,7 +61,10 @@ const listSourceMapRoute = createApmServerRoute({ async handler({ params, plugins, + featureFlags, }): Promise { + throwNotImplementedIfSourceMapNotAvailable(featureFlags); + const { page, perPage } = params.query; try { @@ -97,7 +109,10 @@ const uploadSourceMapRoute = createApmServerRoute({ plugins, core, logger, + featureFlags, }): Promise => { + throwNotImplementedIfSourceMapNotAvailable(featureFlags); + const { service_name: serviceName, service_version: serviceVersion, @@ -162,7 +177,9 @@ const deleteSourceMapRoute = createApmServerRoute({ id: t.string, }), }), - handler: async ({ params, plugins, core }): Promise => { + handler: async ({ params, plugins, core, featureFlags }): Promise => { + throwNotImplementedIfSourceMapNotAvailable(featureFlags); + const fleetPluginStart = await plugins.fleet?.start(); const { id } = params.path; const coreStart = await core.start(); @@ -192,7 +209,9 @@ const deleteSourceMapRoute = createApmServerRoute({ const migrateFleetArtifactsSourceMapRoute = createApmServerRoute({ endpoint: 'POST /internal/apm/sourcemaps/migrate_fleet_artifacts', options: { tags: ['access:apm', 'access:apm_write'] }, - handler: async ({ plugins, core, logger }): Promise => { + handler: async ({ plugins, core, logger, featureFlags }): Promise => { + throwNotImplementedIfSourceMapNotAvailable(featureFlags); + const fleet = await plugins.fleet?.start(); const coreStart = await core.start(); const internalESClient = coreStart.elasticsearch.client.asInternalUser;