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

Closes https://github.com/elastic/kibana/issues/159040

Add configuration values to hide UI components and block api in
serverless.oblt.yml

Examples

Non Serverless
<img width="1791" alt="image"
src="6657830c-7c0c-460d-bd57-e63eb8b72d6f">

Serverless
<img width="1273" alt="image"
src="be437d99-91fc-43f5-b344-c49593a33f30">
This commit is contained in:
Miriam 2023-06-19 11:18:00 +01:00 committed by GitHub
parent c131f41fd4
commit 56ac338d11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 74 additions and 27 deletions

View file

@ -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
# Specify in telemetry the project type
telemetry.labels.serverless: observability

View file

@ -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)',
'xpack.cases.files.allowedMimeTypes (array)',
'xpack.cases.files.maxSize (number)',
'xpack.cases.markdownPlugins.lens (boolean)',

View file

@ -15,8 +15,6 @@ export enum ApmFeatureFlagName {
InfraUiAvailable = 'infraUiAvailable',
MigrationToFleetAvailable = 'migrationToFleetAvailable',
SourcemapApiAvailable = 'sourcemapApiAvailable',
SpacesAvailable = 'spacesAvailable',
SchemaAvailable = 'schemaAvailable',
StorageExplorerAvailable = 'storageExplorerAvailable',
}
@ -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,

View file

@ -217,7 +217,6 @@ function useTabs({ selectedTab }: { selectedTab: Tab['key'] }) {
);
const router = useApmRouter();
const isInfraTabAvailable = useApmFeatureFlag(
ApmFeatureFlagName.InfrastructureTabAvailable
);

View file

@ -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,
@ -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>

View file

@ -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(
@ -59,7 +59,7 @@ export function SettingsTemplate({ children, selectedTab }: Props) {
router,
defaultEnvironment,
agentConfigurationAvailable,
schemaTabAvailable,
migrationToFleetAvailable,
indicesAvailable,
});
@ -84,7 +84,7 @@ function getTabs({
router,
defaultEnvironment,
agentConfigurationAvailable,
schemaTabAvailable,
migrationToFleetAvailable,
indicesAvailable,
}: {
core: CoreStart;
@ -92,7 +92,7 @@ function getTabs({
router: ApmRouter;
defaultEnvironment: Environment;
agentConfigurationAvailable: boolean;
schemaTabAvailable: boolean;
migrationToFleetAvailable: boolean;
indicesAvailable: boolean;
}) {
const canReadMlJobs = !!core.application.capabilities.ml?.canGetJobs;
@ -171,7 +171,7 @@ function getTabs({
]
: []),
...(schemaTabAvailable
...(migrationToFleetAvailable
? [
{
key: 'schema' as const,

View file

@ -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({

View file

@ -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];
}

View file

@ -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> = (

View file

@ -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({
@ -69,6 +78,15 @@ const configSchema = schema.object({
schema.string({ defaultValue: '' }),
schema.never()
),
featureFlags: schema.object({
agentConfigurationAvailable: disabledOnServerless,
configurableIndicesAvailable: disabledOnServerless,
infrastructureTabAvailable: disabledOnServerless,
infraUiAvailable: disabledOnServerless,
migrationToFleetAvailable: disabledOnServerless,
sourcemapApiAvailable: disabledOnServerless,
storageExplorerAvailable: disabledOnServerless,
}),
});
// plugin config
@ -129,6 +147,7 @@ export const config: PluginConfigDescriptor<APMConfig> = {
latestAgentVersionsUrl: true,
managedServiceUrl: true,
serverlessOnboarding: true,
featureFlags: true,
},
schema: configSchema,
};

View file

@ -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
@ -183,7 +182,7 @@ export class APMPlugin
},
logger: this.logger,
config: currentConfig,
featureFlags: getApmFeatureFlags(),
featureFlags: currentConfig.featureFlags,
repository: getGlobalApmServerRouteRepository(),
ruleDataClient,
plugins: resourcePlugins,