Skip to content

Commit

Permalink
[APM] Add feature flag to sourcemap endpoints (#157997)
Browse files Browse the repository at this point in the history
Part of #153776

Disallow uploading source maps endpoints to make it clear that it won't
work by returning 501 Not Implemented status code
  • Loading branch information
MiriamAparicio authored May 22, 2023
1 parent 8a081dc commit 97e6c84
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions x-pack/plugins/apm/server/routes/source_maps/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -40,6 +41,14 @@ export const sourceMapRt = t.intersection([

export type SourceMap = t.TypeOf<typeof sourceMapRt>;

function throwNotImplementedIfSourceMapNotAvailable(
featureFlags: ApmFeatureFlags
): void {
if (!featureFlags.sourcemapApiAvailable) {
throw Boom.notImplemented();
}
}

const listSourceMapRoute = createApmServerRoute({
endpoint: 'GET /api/apm/sourcemaps',
options: { tags: ['access:apm'] },
Expand All @@ -52,7 +61,10 @@ const listSourceMapRoute = createApmServerRoute({
async handler({
params,
plugins,
featureFlags,
}): Promise<ListSourceMapArtifactsResponse | undefined> {
throwNotImplementedIfSourceMapNotAvailable(featureFlags);

const { page, perPage } = params.query;

try {
Expand Down Expand Up @@ -97,7 +109,10 @@ const uploadSourceMapRoute = createApmServerRoute({
plugins,
core,
logger,
featureFlags,
}): Promise<Artifact | undefined> => {
throwNotImplementedIfSourceMapNotAvailable(featureFlags);

const {
service_name: serviceName,
service_version: serviceVersion,
Expand Down Expand Up @@ -162,7 +177,9 @@ const deleteSourceMapRoute = createApmServerRoute({
id: t.string,
}),
}),
handler: async ({ params, plugins, core }): Promise<void> => {
handler: async ({ params, plugins, core, featureFlags }): Promise<void> => {
throwNotImplementedIfSourceMapNotAvailable(featureFlags);

const fleetPluginStart = await plugins.fleet?.start();
const { id } = params.path;
const coreStart = await core.start();
Expand Down Expand Up @@ -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<void> => {
handler: async ({ plugins, core, logger, featureFlags }): Promise<void> => {
throwNotImplementedIfSourceMapNotAvailable(featureFlags);

const fleet = await plugins.fleet?.start();
const coreStart = await core.start();
const internalESClient = coreStart.elasticsearch.client.asInternalUser;
Expand Down

0 comments on commit 97e6c84

Please sign in to comment.