Skip to content

Commit

Permalink
[APM] Add feature flag for not available apm schema (elastic#158911)
Browse files Browse the repository at this point in the history
Part of elastic#153776

How to test:

- change default value in x-pack/plugins/apm/common/apm_feature_flags.ts
  • Loading branch information
MiriamAparicio authored and saarikabhasi committed Jun 14, 2023
1 parent 9543c91 commit 8cef5e8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export function SettingsTemplate({ children, selectedTab }: Props) {
const agentConfigurationAvailable = useApmFeatureFlag(
ApmFeatureFlagName.AgentConfigurationAvailable
);
const schemaAvailable = useApmFeatureFlag(ApmFeatureFlagName.SchemaAvailable);
const schemaTabAvailable = useApmFeatureFlag(
ApmFeatureFlagName.MigrationToFleetAvailable
);
const indicesAvailable = useApmFeatureFlag(
ApmFeatureFlagName.ConfigurableIndicesAvailable
);
Expand All @@ -57,7 +59,7 @@ export function SettingsTemplate({ children, selectedTab }: Props) {
router,
defaultEnvironment,
agentConfigurationAvailable,
schemaAvailable,
schemaTabAvailable,
indicesAvailable,
});

Expand All @@ -82,15 +84,15 @@ function getTabs({
router,
defaultEnvironment,
agentConfigurationAvailable,
schemaAvailable,
schemaTabAvailable,
indicesAvailable,
}: {
core: CoreStart;
selectedTab: Tab['key'];
router: ApmRouter;
defaultEnvironment: Environment;
agentConfigurationAvailable: boolean;
schemaAvailable: boolean;
schemaTabAvailable: boolean;
indicesAvailable: boolean;
}) {
const canReadMlJobs = !!core.application.capabilities.ml?.canGetJobs;
Expand Down Expand Up @@ -169,7 +171,7 @@ function getTabs({
]
: []),

...(schemaAvailable
...(schemaTabAvailable
? [
{
key: 'schema' as const,
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/apm/server/routes/fleet/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
APM_SERVER_SCHEMA_SAVED_OBJECT_ID,
APM_SERVER_SCHEMA_SAVED_OBJECT_TYPE,
} from '../../../common/apm_saved_object_constants';
import { ApmFeatureFlags } from '../../../common/apm_feature_flags';
import { createInternalESClientWithContext } from '../../lib/helpers/create_es_client/create_internal_es_client';
import { getInternalSavedObjectsClient } from '../../lib/helpers/get_internal_saved_objects_client';
import { createApmServerRoute } from '../apm_routes/create_apm_server_route';
Expand All @@ -30,6 +31,14 @@ import {
RunMigrationCheckResponse,
} from './run_migration_check';

function throwNotFoundIfFleetMigrationNotAvailable(
featureFlags: ApmFeatureFlags
): void {
if (!featureFlags.migrationToFleetAvailable) {
throw Boom.notFound();
}
}

const hasFleetDataRoute = createApmServerRoute({
endpoint: 'GET /internal/apm/fleet/has_apm_policies',
options: { tags: [] },
Expand Down Expand Up @@ -68,6 +77,7 @@ const saveApmServerSchemaRoute = createApmServerRoute({
}),
}),
handler: async (resources): Promise<void> => {
throwNotFoundIfFleetMigrationNotAvailable(resources.featureFlags);
const { params, logger, core } = resources;
const coreStart = await core.start();
const savedObjectsClient = await getInternalSavedObjectsClient(coreStart);
Expand All @@ -87,6 +97,7 @@ const getUnsupportedApmServerSchemaRoute = createApmServerRoute({
handler: async (
resources
): Promise<{ unsupported: UnsupportedApmServerSchema }> => {
throwNotFoundIfFleetMigrationNotAvailable(resources.featureFlags);
const { context } = resources;
const savedObjectsClient = (await context.core).savedObjects.client;
return {
Expand All @@ -101,6 +112,8 @@ const getMigrationCheckRoute = createApmServerRoute({
handler: async (resources): Promise<RunMigrationCheckResponse> => {
const { core, plugins, context, config, request } = resources;

throwNotFoundIfFleetMigrationNotAvailable(resources.featureFlags);

const { fleet, security } = plugins;

if (!fleet || !security) {
Expand Down

0 comments on commit 8cef5e8

Please sign in to comment.