Skip to content

Commit

Permalink
add feature flags to apm config and serverless.oblt.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
MiriamAparicio committed Jun 12, 2023
1 parent 5c7753f commit 35422ce
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 12 deletions.
10 changes: 10 additions & 0 deletions config/serverless.oblt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,13 @@ xpack.apm.serverlessOnboarding: true
xpack.fleet.packages:
- name: apm
version: latest
## Disable APM UI components and API calls
xpack.apm.featureFlags.agentConfigurationAvailable: false
xpack.apm.featureFlags.configurableIndicesAvailable: false
xpack.apm.featureFlags.infrastructureTabAvailable: false
xpack.apm.featureFlags.infraUiAvailable: false
xpack.apm.featureFlags.migrationToFleetAvailable: false
xpack.apm.featureFlags.sourcemapApiAvailable: false
xpack.apm.featureFlags.spacesAvailable: false
xpack.apm.featureFlags.schemaAvailable: false
xpack.apm.featureFlags.storageExplorerAvailable: false
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) {
);

const router = useApmRouter();

const isInfraTabAvailable = useApmFeatureFlag(
ApmFeatureFlagName.InfrastructureTabAvailable
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ const coreMock = {
},
} as unknown as Partial<CoreStart>;

const configMock = {
featureFlags: {
agentConfigurationAvailable: true,
schemaAvailable: true,
indicesAvailable: true,
},
};

const stories: Meta<Args> = {
title: 'routing/templates/SettingsTemplate',
component: SettingsTemplate,
Expand All @@ -36,7 +44,12 @@ const stories: Meta<Args> = {

return (
<MockApmPluginStorybook
apmContext={{ core: coreMock } as unknown as ApmPluginContextValue}
apmContext={
{
core: coreMock,
config: configMock,
} as unknown as ApmPluginContextValue
}
>
<StoryComponent />
</MockApmPluginStorybook>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ const mockConfig: ConfigSchema = {
latestAgentVersionsUrl: '',
serverlessOnboarding: false,
managedServiceUrl: '',
featureFlags: {
agentConfigurationAvailable: true,
configurableIndicesAvailable: true,
infrastructureTabAvailable: true,
infraUiAvailable: true,
migrationToFleetAvailable: true,
sourcemapApiAvailable: true,
spacesAvailable: true,
schemaAvailable: true,
storageExplorerAvailable: true,
},
};

const urlService = new UrlService({
Expand Down
11 changes: 3 additions & 8 deletions x-pack/plugins/apm/public/hooks/use_apm_feature_flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@
* 2.0.
*/

import { useMemo } from 'react';
import {
ApmFeatureFlagName,
getApmFeatureFlags,
ValueOfApmFeatureFlag,
} from '../../common/apm_feature_flags';
import { useApmPluginContext } from '../context/apm_plugin/use_apm_plugin_context';

export function useApmFeatureFlag<
TApmFeatureFlagName extends ApmFeatureFlagName
>(
featureFlag: TApmFeatureFlagName
): ValueOfApmFeatureFlag<TApmFeatureFlagName> {
const featureFlags = useMemo(() => {
// this should be replaced with an API call
return getApmFeatureFlags();
}, []);

return featureFlags[featureFlag];
const { config } = useApmPluginContext();
return config.featureFlags[featureFlag];
}
11 changes: 11 additions & 0 deletions x-pack/plugins/apm/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ export interface ConfigSchema {
latestAgentVersionsUrl: string;
serverlessOnboarding: boolean;
managedServiceUrl: string;
featureFlags: {
agentConfigurationAvailable: boolean;
configurableIndicesAvailable: boolean;
infrastructureTabAvailable: boolean;
infraUiAvailable: boolean;
migrationToFleetAvailable: boolean;
sourcemapApiAvailable: boolean;
spacesAvailable: boolean;
schemaAvailable: boolean;
storageExplorerAvailable: boolean;
};
}

export const plugin: PluginInitializer<ApmPluginSetup, ApmPluginStart> = (
Expand Down
75 changes: 75 additions & 0 deletions x-pack/plugins/apm/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,80 @@ const configSchema = schema.object({
schema.string({ defaultValue: '' }),
schema.never()
),
featureFlags: schema.object({
agentConfigurationAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
),
configurableIndicesAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
),
infrastructureTabAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
),
infraUiAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
),
migrationToFleetAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
),
sourcemapApiAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
),
spacesAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
),
schemaAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
),
storageExplorerAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
),
}),
});

// plugin config
Expand Down Expand Up @@ -129,6 +203,7 @@ export const config: PluginConfigDescriptor<APMConfig> = {
latestAgentVersionsUrl: true,
managedServiceUrl: true,
serverlessOnboarding: true,
featureFlags: true,
},
schema: configSchema,
};
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ import { migrateLegacyAPMIndicesToSpaceAware } from './saved_objects/migrations/
import { scheduleSourceMapMigration } from './routes/source_maps/schedule_source_map_migration';
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 { getApmFeatureFlags } from '../common/apm_feature_flags';
import { apmTutorialCustomIntegration } from '../common/tutorial/tutorials';

export class APMPlugin
Expand Down Expand Up @@ -183,7 +182,7 @@ export class APMPlugin
},
logger: this.logger,
config: currentConfig,
featureFlags: getApmFeatureFlags(),
featureFlags: currentConfig.featureFlags,
repository: getGlobalApmServerRouteRepository(),
ruleDataClient,
plugins: resourcePlugins,
Expand Down

0 comments on commit 35422ce

Please sign in to comment.