Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Add feature flag for not available apm schema #158911

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
Copy link
Contributor

@ogupte ogupte Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we give the same check (throwNotFoundIfApmSchemaNotAvailable) in GET /internal/apm/fleet/migration_check? It's an API that's call from 2 places:

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