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

add feature flags to apm config and serverless.oblt.yml #159136

Merged
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
MiriamAparicio marked this conversation as resolved.
Show resolved Hide resolved
xpack.apm.featureFlags.schemaAvailable: false
MiriamAparicio marked this conversation as resolved.
Show resolved Hide resolved
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,
MiriamAparicio marked this conversation as resolved.
Show resolved Hide resolved
},
};

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({
achyutjhunjhunwala marked this conversation as resolved.
Show resolved Hide resolved
agentConfigurationAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
Copy link
Contributor

@achyutjhunjhunwala achyutjhunjhunwala Jun 12, 2023

Choose a reason for hiding this comment

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

I didn't understand the notEqual logic here.

Basically, if we are not running in serverless context, its being enforced to a true literal check and the default value could be true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's like and if/else

Copy link
Contributor

@achyutjhunjhunwala achyutjhunjhunwala Jun 12, 2023

Choose a reason for hiding this comment

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

Yes, i understand the schema.conditional.
What i don't get it is, when we are not running in serverless mode, you always want this settings to be true ? This is what i don't get it.

This config means

If we are running in serverless mode, then default value is false, but it would give *.yml file the preference. Which mean in serverless.oblt.yml file, it needs to be set as true only then it will be enabled.

If we are not running in serverless mode, it will always be true.

is this the expected behaviour ?

Copy link
Contributor

@achyutjhunjhunwala achyutjhunjhunwala Jun 12, 2023

Choose a reason for hiding this comment

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

Reason for asking this is, since you are setting it as true in non serverless mode, you will have to update the security teams tests also where they check for exposed settings.

This might also need documentation update for these exposed settings. The moment you update the security tests, someone from the security team will provide more details

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we are not running in serverless mode, it will always be true.

is this the expected behaviour ?

Yes, we want these values to be true when we are not in serverless

This might also need documentation update for these exposed settings. The moment you update the security tests, someone from the security team will provide more details

As you said I needed to update the security test and the team was ping to review these changes, I'm waiting for them for more details

),
configurableIndicesAvailable: schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
),
MiriamAparicio marked this conversation as resolved.
Show resolved Hide resolved
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