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
8 changes: 8 additions & 0 deletions config/serverless.oblt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ 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.storageExplorerAvailable: false
Comment on lines +30 to +37
Copy link
Member

@afharo afharo Jun 19, 2023

Choose a reason for hiding this comment

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

NIT: we could also use the YAML tree format to avoid repetition 😇

Suggested change
## 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.storageExplorerAvailable: false
## Disable APM UI components and API calls
xpack.apm.featureFlags:
agentConfigurationAvailable: false
configurableIndicesAvailable: false
infrastructureTabAvailable: false
infraUiAvailable: false
migrationToFleetAvailable: false
sourcemapApiAvailable: false
storageExplorerAvailable: false


# Specify in telemetry the project type
telemetry.labels.serverless: observability
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.apm.managedServiceUrl (any)',
'xpack.apm.serverlessOnboarding (any)',
'xpack.apm.latestAgentVersionsUrl (string)',
'xpack.apm.featureFlags.agentConfigurationAvailable (any)',
'xpack.apm.featureFlags.configurableIndicesAvailable (any)',
'xpack.apm.featureFlags.infrastructureTabAvailable (any)',
'xpack.apm.featureFlags.infraUiAvailable (any)',
'xpack.apm.featureFlags.migrationToFleetAvailable (any)',
'xpack.apm.featureFlags.sourcemapApiAvailable (any)',
'xpack.apm.featureFlags.storageExplorerAvailable (any)',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these should be booleans

Copy link
Contributor Author

@MiriamAparicio MiriamAparicio Jun 14, 2023

Choose a reason for hiding this comment

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

hi @thomheymann,
I set them initially to boolean in this commit bf0a260, but the test were failing
image

Copy link
Contributor

Choose a reason for hiding this comment

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

That's strange. Maybe the renderer doesn't infer the type correctly because of the context conditional:
https://github.com/elastic/kibana/pull/159136/files#diff-fa8fe01d402a7eb5cbc387759a4ea3930f3cc056d90477c04232d3ab91afaac7R17-R25
Let's leave as is for now in that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes if we use a conditional rendering, the renderer is currently unable to infer the type based on provided default value. Hence it will always result in any type

'xpack.cases.files.allowedMimeTypes (array)',
'xpack.cases.files.maxSize (number)',
'xpack.cases.markdownPlugins.lens (boolean)',
Expand Down
10 changes: 0 additions & 10 deletions x-pack/plugins/apm/common/apm_feature_flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export enum ApmFeatureFlagName {
InfraUiAvailable = 'infraUiAvailable',
MigrationToFleetAvailable = 'migrationToFleetAvailable',
SourcemapApiAvailable = 'sourcemapApiAvailable',
SpacesAvailable = 'spacesAvailable',
SchemaAvailable = 'schemaAvailable',
StorageExplorerAvailable = 'storageExplorerAvailable',
}

Expand Down Expand Up @@ -45,14 +43,6 @@ const apmFeatureFlagMap = {
default: true,
type: t.boolean,
},
[ApmFeatureFlagName.SpacesAvailable]: {
default: true,
type: t.boolean,
},
[ApmFeatureFlagName.SchemaAvailable]: {
default: true,
type: t.boolean,
},
[ApmFeatureFlagName.StorageExplorerAvailable]: {
default: true,
type: t.boolean,
Expand Down
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,13 @@ const coreMock = {
},
} as unknown as Partial<CoreStart>;

const configMock = {
featureFlags: {
agentConfigurationAvailable: true,
configurableIndicesAvailable: true,
},
};

const stories: Meta<Args> = {
title: 'routing/templates/SettingsTemplate',
component: SettingsTemplate,
Expand All @@ -36,7 +43,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 @@ -46,7 +46,7 @@ export function SettingsTemplate({ children, selectedTab }: Props) {
const agentConfigurationAvailable = useApmFeatureFlag(
ApmFeatureFlagName.AgentConfigurationAvailable
);
const schemaTabAvailable = useApmFeatureFlag(
const migrationToFleetAvailable = useApmFeatureFlag(
ApmFeatureFlagName.MigrationToFleetAvailable
);
const indicesAvailable = useApmFeatureFlag(
Expand All @@ -59,7 +59,7 @@ export function SettingsTemplate({ children, selectedTab }: Props) {
router,
defaultEnvironment,
agentConfigurationAvailable,
schemaTabAvailable,
migrationToFleetAvailable,
indicesAvailable,
});

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

...(schemaTabAvailable
...(migrationToFleetAvailable
? [
{
key: 'schema' as const,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ const mockConfig: ConfigSchema = {
latestAgentVersionsUrl: '',
serverlessOnboarding: false,
managedServiceUrl: '',
featureFlags: {
agentConfigurationAvailable: true,
configurableIndicesAvailable: true,
infrastructureTabAvailable: true,
infraUiAvailable: true,
migrationToFleetAvailable: true,
sourcemapApiAvailable: 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];
}
9 changes: 9 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,15 @@ export interface ConfigSchema {
latestAgentVersionsUrl: string;
serverlessOnboarding: boolean;
managedServiceUrl: string;
featureFlags: {
agentConfigurationAvailable: boolean;
configurableIndicesAvailable: boolean;
infrastructureTabAvailable: boolean;
infraUiAvailable: boolean;
migrationToFleetAvailable: boolean;
sourcemapApiAvailable: boolean;
storageExplorerAvailable: boolean;
};
}

export const plugin: PluginInitializer<ApmPluginSetup, ApmPluginStart> = (
Expand Down
19 changes: 19 additions & 0 deletions x-pack/plugins/apm/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import { maxSuggestions } from '@kbn/observability-plugin/common';
import { SearchAggregatedTransactionSetting } from '../common/aggregated_transactions';
import { APMPlugin } from './plugin';

const disabledOnServerless = schema.conditional(
schema.contextRef('serverless'),
true,
schema.boolean({
defaultValue: false,
}),
schema.oneOf([schema.literal(true)], { defaultValue: true })
);

// All options should be documented in the APM configuration settings: https://github.com/elastic/kibana/blob/main/docs/settings/apm-settings.asciidoc
// and be included on cloud allow list unless there are specific reasons not to
const configSchema = schema.object({
Expand Down Expand Up @@ -69,6 +78,15 @@ const configSchema = schema.object({
schema.string({ defaultValue: '' }),
schema.never()
),
featureFlags: schema.object({
achyutjhunjhunwala marked this conversation as resolved.
Show resolved Hide resolved
agentConfigurationAvailable: disabledOnServerless,
configurableIndicesAvailable: disabledOnServerless,
infrastructureTabAvailable: disabledOnServerless,
infraUiAvailable: disabledOnServerless,
migrationToFleetAvailable: disabledOnServerless,
sourcemapApiAvailable: disabledOnServerless,
storageExplorerAvailable: disabledOnServerless,
}),
});

// plugin config
Expand Down Expand Up @@ -129,6 +147,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