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 7 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'];
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ const gatherRoutes = (wrapper: ShallowWrapper) => {
});
};

const mockExperimentalFeatures = {};

const props: DiscoverRoutesProps = {
customizationCallbacks: [],
customizationContext: mockCustomizationContext,
experimentalFeatures: mockExperimentalFeatures,
};

describe('DiscoverRoutes', () => {
Expand Down Expand Up @@ -156,13 +159,15 @@ describe('CustomDiscoverRoutes', () => {
<CustomDiscoverRoutes
profileRegistry={profileRegistry}
customizationContext={mockCustomizationContext}
experimentalFeatures={mockExperimentalFeatures}
/>
);
expect(component.find(DiscoverRoutes).getElement()).toMatchObject(
<DiscoverRoutes
prefix={addProfile('', mockProfile)}
customizationCallbacks={callbacks}
customizationContext={mockCustomizationContext}
experimentalFeatures={mockExperimentalFeatures}
/>
);
});
Expand All @@ -173,6 +178,7 @@ describe('CustomDiscoverRoutes', () => {
<CustomDiscoverRoutes
profileRegistry={profileRegistry}
customizationContext={mockCustomizationContext}
experimentalFeatures={mockExperimentalFeatures}
/>
);
expect(component.find(NotFoundRoute).getElement()).toMatchObject(<NotFoundRoute />);
Expand All @@ -191,6 +197,7 @@ describe('DiscoverRouter', () => {
history={history}
profileRegistry={profileRegistry}
customizationContext={mockCustomizationContext}
experimentalFeatures={mockExperimentalFeatures}
/>
);
gatherRoutes(component);
Expand All @@ -201,6 +208,7 @@ describe('DiscoverRouter', () => {
<DiscoverRoutes
customizationCallbacks={callbacks}
customizationContext={mockCustomizationContext}
experimentalFeatures={mockExperimentalFeatures}
/>
);
});
Expand All @@ -210,6 +218,7 @@ describe('DiscoverRouter', () => {
<CustomDiscoverRoutes
profileRegistry={profileRegistry}
customizationContext={mockCustomizationContext}
experimentalFeatures={mockExperimentalFeatures}
/>
);
});
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/discover/public/application/discover_router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import React, { useCallback, useMemo } from 'react';
import { History } from 'history';
import { EuiErrorBoundary } from '@elastic/eui';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { ExperimentalFeatures } from '../../common/config';
import { ContextAppRoute } from './context';
import { SingleDocRoute } from './doc';
import { DiscoverMainRoute } from './main';
Expand All @@ -26,6 +27,7 @@ export interface DiscoverRoutesProps {
prefix?: string;
customizationCallbacks: CustomizationCallback[];
customizationContext: DiscoverCustomizationContext;
experimentalFeatures: ExperimentalFeatures;
}

export const DiscoverRoutes = ({ prefix, ...mainRouteProps }: DiscoverRoutesProps) => {
Expand Down Expand Up @@ -67,6 +69,7 @@ export const DiscoverRoutes = ({ prefix, ...mainRouteProps }: DiscoverRoutesProp
interface CustomDiscoverRoutesProps {
profileRegistry: DiscoverProfileRegistry;
customizationContext: DiscoverCustomizationContext;
experimentalFeatures: ExperimentalFeatures;
}

export const CustomDiscoverRoutes = ({ profileRegistry, ...props }: CustomDiscoverRoutesProps) => {
Expand All @@ -93,6 +96,7 @@ export interface DiscoverRouterProps {
services: DiscoverServices;
profileRegistry: DiscoverProfileRegistry;
customizationContext: DiscoverCustomizationContext;
experimentalFeatures: ExperimentalFeatures;
history: History;
}

Expand Down
4 changes: 4 additions & 0 deletions src/plugins/discover/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { ExperimentalFeatures } from '../../common/config';
import { DiscoverRouter } from './discover_router';
import { DiscoverServices } from '../build_services';
import type { DiscoverProfileRegistry } from '../customizations/profile_registry';
Expand All @@ -19,13 +20,15 @@ export interface RenderAppProps {
services: DiscoverServices;
profileRegistry: DiscoverProfileRegistry;
customizationContext: DiscoverCustomizationContext;
experimentalFeatures: ExperimentalFeatures;
}

export const renderApp = ({
element,
services,
profileRegistry,
customizationContext,
experimentalFeatures,
}: RenderAppProps) => {
const { history, capabilities, chrome, data, core } = services;

Expand All @@ -45,6 +48,7 @@ export const renderApp = ({
services={services}
profileRegistry={profileRegistry}
customizationContext={customizationContext}
experimentalFeatures={experimentalFeatures}
history={history}
/>,
{
Expand Down
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 @@ -355,6 +362,7 @@ export class DiscoverPlugin
displayMode: 'standalone',
inlineTopNav: this.inlineTopNav,
},
experimentalFeatures: this.experimentalFeatures,
});

return () => {
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,
},
};
2 changes: 1 addition & 1 deletion src/plugins/discover/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { createSearchEmbeddableFactory } from './embeddable';
import { initializeLocatorServices } from './locator';
import { registerSampleData } from './sample_data';
import { getUiSettings } from './ui_settings';
import { ConfigSchema } from './config';
import { ConfigSchema } from '../common/config';

export class DiscoverServerPlugin
implements Plugin<object, DiscoverServerPluginStart, object, DiscoverServerPluginStartDeps>
Expand Down
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 ?? false,
};

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
Loading