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

[RAM] [Rule Form v2] Add feature flag #179184

Merged
merged 16 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/plugins/discover/common/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enableUiSettingsValidations: schema.boolean({ defaultValue: false }),
experimental: schema.maybe(
schema.object({
ruleFormV2Enabled: schema.maybe(schema.boolean({ defaultValue: false })),
})
),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
export type ExperimentalFeatures = ConfigSchema['experimental'];
4 changes: 4 additions & 0 deletions src/plugins/discover/public/customizations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ export interface DiscoverCustomizationContext {
*/
showLogsExplorerTabs: boolean;
};
/*
* Whether or not to use the in-development Rule Form V2
*/
ruleFormV2Enabled: boolean;
}
10 changes: 9 additions & 1 deletion src/plugins/discover/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
} from './components/discover_container';
import { getESQLSearchProvider } from './global_search/search_provider';
import { HistoryService } from './history_service';
import { ConfigSchema, ExperimentalFeatures } from '../common/config';

/**
* @public
Expand Down Expand Up @@ -207,7 +208,10 @@ export interface DiscoverStartPlugins {
export class DiscoverPlugin
implements Plugin<DiscoverSetup, DiscoverStart, DiscoverSetupPlugins, DiscoverStartPlugins>
{
constructor(private readonly initializerContext: PluginInitializerContext) {}
constructor(private readonly initializerContext: PluginInitializerContext<ConfigSchema>) {
this.experimentalFeatures =
initializerContext.config.get().experimental ?? this.experimentalFeatures;
}

private appStateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private historyService = new HistoryService();
Expand All @@ -222,6 +226,9 @@ export class DiscoverPlugin
enabled: false,
showLogsExplorerTabs: false,
};
private experimentalFeatures: ExperimentalFeatures = {
ruleFormV2Enabled: false,
};

setup(
core: CoreSetup<DiscoverStartPlugins, DiscoverStart>,
Expand Down Expand Up @@ -354,6 +361,7 @@ export class DiscoverPlugin
customizationContext: {
displayMode: 'standalone',
inlineTopNav: this.inlineTopNav,
ruleFormV2Enabled: this.experimentalFeatures?.ruleFormV2Enabled ?? false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than incorporating this into the customization context, which is used for a different purpose in Discover, I'd prefer we pass ExperimentalFeatures directly into renderApp instead to keep things separated. Then when we need to use it, we can introduce something like a context provider for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, changed this in the latest commit

},
});

Expand Down
11 changes: 4 additions & 7 deletions src/plugins/discover/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
* Side Public License, v 1.
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { PluginConfigDescriptor } from '@kbn/core-plugins-server';

const configSchema = schema.object({
enableUiSettingsValidations: schema.boolean({ defaultValue: false }),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
import { configSchema, type ConfigSchema } from '../common/config';

export const config: PluginConfigDescriptor<ConfigSchema> = {
schema: configSchema,
exposeToBrowser: {
experimental: true,
},
};
13 changes: 13 additions & 0 deletions x-pack/plugins/ml/common/constants/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ export const ML_EXTERNAL_BASE_PATH = '/api/ml';

export type MlFeatures = Record<'ad' | 'dfa' | 'nlp', boolean>;
export type CompatibleModule = 'security' | 'observability' | 'search';
export type ExperimentalFeatures = Record<'ruleFormV2', boolean>;

export interface ConfigSchema {
ad?: { enabled: boolean };
dfa?: { enabled: boolean };
nlp?: { enabled: boolean };
compatibleModuleType?: CompatibleModule;
experimental?: {
ruleFormV2?: { enabled: boolean };
};
}

export function initEnabledFeatures(enabledFeatures: MlFeatures, config: ConfigSchema) {
Expand All @@ -38,3 +42,12 @@ export function initEnabledFeatures(enabledFeatures: MlFeatures, config: ConfigS
enabledFeatures.nlp = config.nlp.enabled;
}
}

export function initExperimentalFeatures(
experimentalFeatures: ExperimentalFeatures,
config: ConfigSchema
) {
if (config.experimental?.ruleFormV2?.enabled !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

super small nitpick: maybe better to check if its a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trying to repeat the same pattern used elsewhere in this file

experimentalFeatures.ruleFormV2 = config.experimental.ruleFormV2.enabled;
}
}
17 changes: 14 additions & 3 deletions x-pack/plugins/ml/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-pl
import { StorageContextProvider } from '@kbn/ml-local-storage';
import useLifecycles from 'react-use/lib/useLifecycles';
import useObservable from 'react-use/lib/useObservable';
import type { MlFeatures } from '../../common/constants/app';
import type { ExperimentalFeatures, MlFeatures } from '../../common/constants/app';
import { MlLicense } from '../../common/license';
import { MlCapabilitiesService } from './capabilities/check_capabilities';
import { ML_STORAGE_KEYS } from '../../common/types/storage';
Expand Down Expand Up @@ -49,6 +49,7 @@ interface AppProps {
appMountParams: AppMountParameters;
isServerless: boolean;
mlFeatures: MlFeatures;
experimentalFeatures: ExperimentalFeatures;
}

const localStorage = new Storage(window.localStorage);
Expand Down Expand Up @@ -91,7 +92,14 @@ export interface MlServicesContext {

export type MlGlobalServices = ReturnType<typeof getMlGlobalServices>;

const App: FC<AppProps> = ({ coreStart, deps, appMountParams, isServerless, mlFeatures }) => {
const App: FC<AppProps> = ({
coreStart,
deps,
appMountParams,
isServerless,
mlFeatures,
experimentalFeatures,
}) => {
const pageDeps: PageDependencies = {
history: appMountParams.history,
setHeaderActionMenu: appMountParams.setHeaderActionMenu,
Expand Down Expand Up @@ -171,6 +179,7 @@ const App: FC<AppProps> = ({ coreStart, deps, appMountParams, isServerless, mlFe
isServerless={isServerless}
mlFeatures={mlFeatures}
showMLNavMenu={chromeStyle === 'classic'}
experimentalFeatures={experimentalFeatures}
>
<MlRouter pageDeps={pageDeps} />
</EnabledFeaturesContextProvider>
Expand All @@ -188,7 +197,8 @@ export const renderApp = (
deps: MlDependencies,
appMountParams: AppMountParameters,
isServerless: boolean,
mlFeatures: MlFeatures
mlFeatures: MlFeatures,
experimentalFeatures: ExperimentalFeatures
) => {
setDependencyCache({
timefilter: deps.data.query.timefilter,
Expand All @@ -211,6 +221,7 @@ export const renderApp = (
appMountParams={appMountParams}
isServerless={isServerless}
mlFeatures={mlFeatures}
experimentalFeatures={experimentalFeatures}
/>,
appMountParams.element
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { FC } from 'react';
import React, { createContext, useContext, useMemo } from 'react';
import type { MlFeatures } from '../../../../common/constants/app';
import type { ExperimentalFeatures, MlFeatures } from '../../../../common/constants/app';

export interface EnabledFeatures {
showNodeInfo: boolean;
Expand All @@ -16,6 +16,7 @@ export interface EnabledFeatures {
isADEnabled: boolean;
isDFAEnabled: boolean;
isNLPEnabled: boolean;
showRuleFormV2: boolean;
}
export const EnabledFeaturesContext = createContext({
showNodeInfo: true,
Expand All @@ -30,13 +31,15 @@ interface Props {
isServerless: boolean;
mlFeatures: MlFeatures;
showMLNavMenu?: boolean;
experimentalFeatures: ExperimentalFeatures;
}

export const EnabledFeaturesContextProvider: FC<Props> = ({
children,
isServerless,
showMLNavMenu = true,
mlFeatures,
experimentalFeatures,
}) => {
const features: EnabledFeatures = {
showNodeInfo: !isServerless,
Expand All @@ -45,6 +48,7 @@ export const EnabledFeaturesContextProvider: FC<Props> = ({
isADEnabled: mlFeatures.ad,
isDFAEnabled: mlFeatures.dfa,
isNLPEnabled: mlFeatures.nlp,
showRuleFormV2: experimentalFeatures.ruleFormV2,
};

return (
Expand Down
9 changes: 8 additions & 1 deletion x-pack/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ import {
PLUGIN_ICON_SOLUTION,
PLUGIN_ID,
type ConfigSchema,
type ExperimentalFeatures,
initExperimentalFeatures,
} from '../common/constants/app';
import type { MlCapabilities } from './shared';
import type { ElasticModels } from './application/services/elastic_models_service';
Expand Down Expand Up @@ -127,10 +129,14 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
dfa: true,
nlp: true,
};
private experimentalFeatures: ExperimentalFeatures = {
ruleFormV2: false,
};

constructor(private initializerContext: PluginInitializerContext<ConfigSchema>) {
this.isServerless = initializerContext.env.packageInfo.buildFlavor === 'serverless';
initEnabledFeatures(this.enabledFeatures, initializerContext.config.get());
initExperimentalFeatures(this.experimentalFeatures, initializerContext.config.get());
}

setup(
Expand Down Expand Up @@ -183,7 +189,8 @@ export class MlPlugin implements Plugin<MlPluginSetup, MlPluginStart> {
},
params,
this.isServerless,
this.enabledFeatures
this.enabledFeatures,
this.experimentalFeatures
);
},
});
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/ml/server/config_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ export const configSchema = schema.object({
dfa: enabledSchema,
nlp: enabledSchema,
compatibleModuleType: compatibleModuleTypeSchema,
experimental: schema.maybe(
schema.object({
ruleFormV2: enabledSchema,
})
),
});
1 change: 1 addition & 0 deletions x-pack/plugins/ml/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const config: PluginConfigDescriptor<ConfigSchema> = {
ad: true,
dfa: true,
nlp: true,
experimental: true,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface InfraConfig {
logThresholdAlertRuleEnabled: boolean;
alertsAndRulesDropdownEnabled: boolean;
profilingEnabled: boolean;
ruleFormV2Enabled: boolean;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const config: PluginConfigDescriptor<InfraConfig> = {
* enabling this feature flag.
*/
profilingEnabled: schema.boolean({ defaultValue: false }),
ruleFormV2Enabled: schema.boolean({ defaultValue: false }),
}),
}),
exposeToBrowser: publicConfigKeys,
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/observability_solution/uptime/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ import { schema, TypeOf } from '@kbn/config-schema';
const uptimeConfig = schema.object({
index: schema.maybe(schema.string()),
enabled: schema.boolean({ defaultValue: true }),
experimental: schema.maybe(
schema.object({
ruleFormV2Enabled: schema.maybe(schema.boolean({ defaultValue: false })),
})
),
});

export const config: PluginConfigDescriptor = {
schema: uptimeConfig,
exposeToBrowser: {
experimental: true,
},
};

export type UptimeConfig = TypeOf<typeof uptimeConfig>;
export type ExperimentalFeatures = UptimeConfig['experimental'];
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { i18n as i18nFormatter } from '@kbn/i18n';
import { AppMountParameters, CoreStart } from '@kbn/core/public';
import { getIntegratedAppAvailability } from '../lib/adapters/framework/capabilities_adapter';
import { DEFAULT_TIMEPICKER_QUICK_RANGES, INTEGRATED_SOLUTIONS } from '../../../common/constants';
import type { ExperimentalFeatures } from '../../../common/config';
import { UptimeApp, UptimeAppProps } from './uptime_app';
import { ClientPluginsSetup, ClientPluginsStart } from '../../plugin';

Expand All @@ -19,7 +20,8 @@ export function renderApp(
plugins: ClientPluginsSetup,
startPlugins: ClientPluginsStart,
appMountParameters: AppMountParameters,
isDev: boolean
isDev: boolean,
experimentalFeatures: ExperimentalFeatures
) {
const {
application: { capabilities },
Expand Down
18 changes: 16 additions & 2 deletions x-pack/plugins/observability_solution/uptime/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
ObservabilityAIAssistantPublicSetup,
} from '@kbn/observability-ai-assistant-plugin/public';
import { PLUGIN } from '../common/constants/plugin';
import { UptimeConfig } from '../common/config';
import {
LazySyntheticsPolicyCreateExtension,
LazySyntheticsPolicyEditExtension,
Expand Down Expand Up @@ -119,9 +120,15 @@ export type ClientStart = void;
export class UptimePlugin
implements Plugin<ClientSetup, ClientStart, ClientPluginsSetup, ClientPluginsStart>
{
constructor(private readonly initContext: PluginInitializerContext) {}
constructor(private readonly initContext: PluginInitializerContext<UptimeConfig>) {
this.experimentalFeatures =
this.initContext.config.get().experimental || this.experimentalFeatures;
}

private uptimeAppUpdater = new BehaviorSubject<AppUpdater>(() => ({}));
private experimentalFeatures: UptimeConfig['experimental'] = {
ruleFormV2Enabled: false,
};

public setup(core: CoreSetup<ClientPluginsStart, unknown>, plugins: ClientPluginsSetup): void {
if (plugins.home) {
Expand Down Expand Up @@ -202,7 +209,14 @@ export class UptimePlugin
mount: async (params: AppMountParameters) => {
const [coreStart, corePlugins] = await core.getStartServices();
const { renderApp } = await import('./legacy_uptime/app/render_app');
return renderApp(coreStart, plugins, corePlugins, params, this.initContext.env.mode.dev);
return renderApp(
coreStart,
plugins,
corePlugins,
params,
this.initContext.env.mode.dev,
this.experimentalFeatures
);
},
updater$: this.uptimeAppUpdater,
});
Expand Down
20 changes: 20 additions & 0 deletions x-pack/plugins/transform/common/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { TypeOf } from '@kbn/config-schema';
import { schema } from '@kbn/config-schema';

export const configSchema = schema.object({
experimental: schema.maybe(
schema.object({
ruleFormV2Enabled: schema.maybe(schema.boolean()),
})
),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
export type ExperimentalFeatures = ConfigSchema['experimental'];
Loading
Loading