Skip to content

[ML] AIOps: Adding ability to disable AIOps in kibana #221286

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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4b1fdda
[ML] AIOps: Adding ability to disable AIOps in kibana
jgowdyelastic May 22, 2025
cd02e46
updating jsonc files
jgowdyelastic May 22, 2025
4db48ca
Merge branch 'main' into adding-ablility-to-disable-aiops-in-kibana
jgowdyelastic May 23, 2025
111a6d0
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine May 23, 2025
0076366
Merge branch 'main' into adding-ablility-to-disable-aiops-in-kibana
jgowdyelastic May 23, 2025
0e11a2a
Merge branch 'main' into adding-ablility-to-disable-aiops-in-kibana
jgowdyelastic May 23, 2025
48980c4
switching to ui.enabled
jgowdyelastic May 23, 2025
bdbcf1f
updating test
jgowdyelastic May 23, 2025
96213c9
Merge branch 'adding-ablility-to-disable-aiops-in-kibana' of github.c…
jgowdyelastic May 23, 2025
67bb42b
fixing test
jgowdyelastic May 23, 2025
934ae28
reverting config change
jgowdyelastic May 23, 2025
c75808d
fixing discover
jgowdyelastic May 23, 2025
180d0b9
Merge branch 'main' into adding-ablility-to-disable-aiops-in-kibana
jgowdyelastic May 23, 2025
51706c2
fixing types
jgowdyelastic May 24, 2025
285a2b3
Merge branch 'adding-ablility-to-disable-aiops-in-kibana' of github.c…
jgowdyelastic May 24, 2025
bda3f08
Merge branch 'main' into adding-ablility-to-disable-aiops-in-kibana
jgowdyelastic May 27, 2025
7a61e90
removing exposing to browser
jgowdyelastic May 27, 2025
5968b25
Merge branch 'main' into adding-ablility-to-disable-aiops-in-kibana
jgowdyelastic May 27, 2025
1420876
updating capability path
jgowdyelastic May 27, 2025
7dc8ae0
Merge branch 'adding-ablility-to-disable-aiops-in-kibana' of github.c…
jgowdyelastic May 27, 2025
4c24a8a
reverting auto lint change
jgowdyelastic May 27, 2025
675b92e
reverting auto linting change
jgowdyelastic May 27, 2025
800f5ec
reverting auto linting change
jgowdyelastic May 27, 2025
94311ec
Merge branch 'main' into adding-ablility-to-disable-aiops-in-kibana
jgowdyelastic May 27, 2025
e4f20d2
fixing discover check
jgowdyelastic May 27, 2025
d67e715
Merge branch 'main' into adding-ablility-to-disable-aiops-in-kibana
jgowdyelastic May 27, 2025
4b06489
improving capabilities check
jgowdyelastic May 27, 2025
5761ed2
Merge branch 'adding-ablility-to-disable-aiops-in-kibana' of github.c…
jgowdyelastic May 27, 2025
922e83b
Merge branch 'main' into adding-ablility-to-disable-aiops-in-kibana
jgowdyelastic May 28, 2025
2f62baf
fixing aiops links in ml
jgowdyelastic May 28, 2025
a2cfe60
reverting auto lint change
jgowdyelastic May 28, 2025
b3b212d
Merge branch 'main' into adding-ablility-to-disable-aiops-in-kibana
jgowdyelastic May 30, 2025
eaa61c5
adding license check to switcher
jgowdyelastic May 30, 2025
e650afe
reinstating getPatternAnalysisAvailable
jgowdyelastic May 30, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export function createDiscoverServicesMock(): DiscoverServices {
FieldStatisticsTable: jest.fn(() => createElement('div')),
},
aiops: {
getPatternAnalysisAvailable: jest.fn().mockResolvedValue(jest.fn().mockResolvedValue(true)),
getPatternAnalysisAvailable: jest.fn().mockResolvedValue(jest.fn(() => true)),
PatternAnalysisComponent: jest.fn(() => createElement('div')),
},
docLinks: docLinksServiceMock.createStartContract(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Document view mode toggle component', () => {
aiops: {
getPatternAnalysisAvailable: jest
.fn()
.mockResolvedValue(jest.fn().mockResolvedValue(useDataViewWithTextFields)),
.mockResolvedValue(jest.fn(() => useDataViewWithTextFields)),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ export const DocumentViewModeToggle = ({
aiopsService
.getPatternAnalysisAvailable()
.then((patternAnalysisAvailable) => {
patternAnalysisAvailable(dataView)
.then(setShowPatternAnalysisTabWrapper)
.catch(() => setShowPatternAnalysisTabWrapper(false));
const available = patternAnalysisAvailable(dataView);
setShowPatternAnalysisTabWrapper(available);
})
.catch(() => setShowPatternAnalysisTabWrapper(false));
},
Expand Down
3 changes: 2 additions & 1 deletion x-pack/platform/plugins/shared/aiops/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"id": "aiops",
"browser": true,
"server": true,
"configPath": ["xpack", "aiops"],
"requiredPlugins": [
"charts",
"data",
Expand Down Expand Up @@ -38,4 +39,4 @@
"cases"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
* 2.0.
*/

import type { ApplicationStart } from '@kbn/core/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import { ES_FIELD_TYPES } from '@kbn/field-types';
import type { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import { firstValueFrom } from 'rxjs';

export function getPatternAnalysisAvailable(licensing: LicensingPluginStart) {
const lic = firstValueFrom(licensing.license$);
return async (dataView: DataView) => {
const isPlatinum = (await lic).hasAtLeast('platinum');
export function getPatternAnalysisAvailable(application: ApplicationStart) {
return (dataView: DataView) => {
const aiopsEnabled = application.capabilities.aiops.enabled;
if (!aiopsEnabled) {
return false;
}

return (
isPlatinum &&
dataView.isTimeBased() &&
dataView.fields.some((f) => f.esTypes?.includes(ES_FIELD_TYPES.TEXT))
);
Expand Down
37 changes: 16 additions & 21 deletions x-pack/platform/plugins/shared/aiops/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import type { CoreStart, Plugin } from '@kbn/core/public';
import { type CoreSetup } from '@kbn/core/public';
import { firstValueFrom } from 'rxjs';

import { getChangePointDetectionComponent } from './shared_components';
import { LogCategorizationForDiscover as PatternAnalysisComponent } from './shared_lazy_components';
Expand All @@ -26,29 +25,25 @@ export type AiopsCoreSetup = CoreSetup<AiopsPluginStartDeps, AiopsPluginStart>;
export class AiopsPlugin
implements Plugin<AiopsPluginSetup, AiopsPluginStart, AiopsPluginSetupDeps, AiopsPluginStartDeps>
{
public setup(
core: AiopsCoreSetup,
{ embeddable, cases, licensing, uiActions }: AiopsPluginSetupDeps
) {
Promise.all([firstValueFrom(licensing.license$), core.getStartServices()]).then(
([license, [coreStart, pluginStart]]) => {
const { canUseAiops } = coreStart.application.capabilities.ml;

if (license.hasAtLeast('platinum') && canUseAiops) {
if (embeddable) {
registerEmbeddables(embeddable, core);
}
public setup(core: AiopsCoreSetup, { embeddable, cases, uiActions }: AiopsPluginSetupDeps) {
core.getStartServices().then(([coreStart, pluginStart]) => {
const { canUseAiops } = coreStart.application.capabilities.ml;
const aiopsEnabled = coreStart.application.capabilities.aiops.enabled;

if (canUseAiops && aiopsEnabled) {
if (embeddable) {
registerEmbeddables(embeddable, core);
}

if (uiActions) {
registerAiopsUiActions(uiActions, coreStart, pluginStart);
}
if (uiActions) {
registerAiopsUiActions(uiActions, coreStart, pluginStart);
}

if (cases) {
registerCases(cases, coreStart, pluginStart);
}
if (cases) {
registerCases(cases, coreStart, pluginStart);
}
}
);
});
}

public start(core: CoreStart, plugins: AiopsPluginStartDeps): AiopsPluginStart {
Expand All @@ -58,7 +53,7 @@ export class AiopsPlugin
const { getPatternAnalysisAvailable } = await import(
'./components/log_categorization/log_categorization_enabled'
);
return getPatternAnalysisAvailable(plugins.licensing);
return getPatternAnalysisAvailable(core.application);
},
PatternAnalysisComponent,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface AiopsPluginStartDeps {

export type AiopsPluginSetup = void;
export interface AiopsPluginStart {
getPatternAnalysisAvailable: () => Promise<(dataView: DataView) => Promise<boolean>>;
getPatternAnalysisAvailable: () => Promise<(dataView: DataView) => boolean>;
PatternAnalysisComponent: React.ComponentType<LogCategorizationEmbeddableWrapperProps>;
ChangePointDetectionComponent: ChangePointDetectionSharedComponent;
}
23 changes: 23 additions & 0 deletions x-pack/platform/plugins/shared/aiops/server/config_schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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';
import type { PluginConfigDescriptor } from '@kbn/core/server';

export const configSchema = schema.object({
ui: schema.maybe(
schema.object({
enabled: schema.maybe(schema.boolean()),
Copy link
Contributor

Choose a reason for hiding this comment

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

This would expose this config option to on-prem users which I think is unintentional, I think we should at least wrap it in a offeringBasedSchema

Copy link
Member Author

@jgowdyelastic jgowdyelastic May 30, 2025

Choose a reason for hiding this comment

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

Would it be a problem to also allow this for on-prem users?
We have ML feature flags which are similar e.g. xpack.ml.ad.enabled and in a recent security issue they've come in useful as we've suggested disabling ad as a possible solution until a fix is available.

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 we should carefully consider what we expose and weigh it up against the benefit on-prem users could get.

Config exposed to on-prem is a public API contract that we cannot break until the next major. Every config option adds to the possible permutations that should be tested. When we only allow this to be set for a specific serverless tier, we can treat the combination of config flags as a single permutation.

So in the absence of a strong use case for an on-prem user and assuming we're only doing this because of essentials tier, I would not expose this to on-prem users.

Copy link
Member Author

Choose a reason for hiding this comment

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

When we only allow this to be set for a specific serverless tier, we can treat the combination of config flags as a single permutation

Just to clarify in case I've missed something, offeringBasedSchema doesn't appear to be able to specify a serverless tier, you can just specify that the setting is serverless or not (or traditional or not)?

I'm happy to make xpack.aiops.ui.enabled serverless only, but I think it should be a product decision. cc @arisonl @peteharverson @sophiec20

})
),
});

export type ConfigSchema = TypeOf<typeof configSchema>;

export const config: PluginConfigDescriptor<ConfigSchema> = {
schema: configSchema,
};
5 changes: 4 additions & 1 deletion x-pack/platform/plugins/shared/aiops/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
*/

import type { PluginInitializerContext } from '@kbn/core/server';
import type { ConfigSchema } from './config_schema';

export async function plugin(initializerContext: PluginInitializerContext) {
export async function plugin(initializerContext: PluginInitializerContext<ConfigSchema>) {
const { AiopsPlugin } = await import('./plugin');
return new AiopsPlugin(initializerContext);
}

export type { AiopsPluginSetup, AiopsPluginStart } from './types';

export { config, type ConfigSchema } from './config_schema';
39 changes: 39 additions & 0 deletions x-pack/platform/plugins/shared/aiops/server/lib/capabilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 { CoreSetup } from '@kbn/core/server';
import { firstValueFrom } from 'rxjs';
import type { AiopsPluginStartDeps } from '../types';

export const setupCapabilities = (core: CoreSetup<AiopsPluginStartDeps>, enabled: boolean) => {
core.capabilities.registerProvider(() => {
return {
aiops: {
enabled,
},
};
});

core.capabilities.registerSwitcher(
async (request, capabilities, useDefaultCapabilities) => {
const [, { licensing }] = await core.getStartServices();
const lic = await firstValueFrom(licensing.license$);
if (lic.hasAtLeast('platinum') === false) {
return {
aiops: {
enabled: false,
},
};
}

return {};
},
{
capabilityPath: 'aiops.*',
}
);
};
9 changes: 7 additions & 2 deletions x-pack/platform/plugins/shared/aiops/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,28 @@ import { defineRoute as defineLogRateAnalysisFieldCandidatesRoute } from './rout
import { defineRoute as defineLogRateAnalysisRoute } from './routes/log_rate_analysis/define_route';
import { defineRoute as defineCategorizationFieldValidationRoute } from './routes/categorization_field_validation/define_route';
import { registerCasesPersistableState } from './register_cases';
import type { ConfigSchema } from './config_schema';
import { setupCapabilities } from './lib/capabilities';

export class AiopsPlugin
implements Plugin<AiopsPluginSetup, AiopsPluginStart, AiopsPluginSetupDeps, AiopsPluginStartDeps>
{
private readonly logger: Logger;
private licenseSubscription: Subscription | null = null;
private usageCounter?: UsageCounter;
private aiopsEnabled: boolean = true;

constructor(initializerContext: PluginInitializerContext) {
constructor(initializerContext: PluginInitializerContext<ConfigSchema>) {
this.logger = initializerContext.logger.get();
this.aiopsEnabled = initializerContext.config.get().ui?.enabled ?? true;
}

public setup(
core: CoreSetup<AiopsPluginStartDeps, AiopsPluginSetupDeps>,
plugins: AiopsPluginSetupDeps
) {
this.logger.debug('aiops: Setup');
setupCapabilities(core, this.aiopsEnabled);

this.usageCounter = plugins.usageCollection?.createUsageCounter(AIOPS_PLUGIN_ID);

// Subscribe to license changes and store the current license in `currentLicense`.
Expand Down
3 changes: 2 additions & 1 deletion x-pack/platform/plugins/shared/aiops/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { PluginSetup, PluginStart } from '@kbn/data-plugin/server';
import type { LicensingPluginSetup } from '@kbn/licensing-plugin/server';
import type { LicensingPluginSetup, LicensingPluginStart } from '@kbn/licensing-plugin/server';
import type { CasesServerSetup } from '@kbn/cases-plugin/server';
import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';

Expand All @@ -19,6 +19,7 @@ export interface AiopsPluginSetupDeps {

export interface AiopsPluginStartDeps {
data: PluginStart;
licensing: LicensingPluginStart;
}

/**
Expand Down
1 change: 1 addition & 0 deletions x-pack/platform/plugins/shared/aiops/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"@kbn/observability-ai-assistant-plugin",
"@kbn/apm-utils",
"@kbn/ml-field-stats-flyout",
"@kbn/config-schema",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ export const LinksMenuUI = (props: LinksMenuProps) => {
};

const { anomaly, showViewSeriesLink } = props;
const canUpdateJob = usePermissionCheck('canUpdateJob');
const [canUpdateJob, canUseAiops] = usePermissionCheck(['canUpdateJob', 'canUseAiops']);
const canConfigureRules = isRuleSupported(anomaly.source) && canUpdateJob;

const contextMenuItems = useMemo(() => {
Expand Down Expand Up @@ -929,7 +929,7 @@ export const LinksMenuUI = (props: LinksMenuProps) => {
);
}

if (openInLogRateAnalysisUrl) {
if (openInLogRateAnalysisUrl && canUseAiops) {
items.push(
<EuiContextMenuItem
key="log_rate_analysis"
Expand All @@ -945,7 +945,7 @@ export const LinksMenuUI = (props: LinksMenuProps) => {
);
}

if (messageField !== null) {
if (messageField !== null && canUseAiops) {
items.push(
<EuiContextMenuItem
key="run_pattern_analysis"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { isFullLicense } from '../../license';
import type { MlRoute } from '../../routing';
import { ML_PAGES } from '../../../../common/constants/locator';
import { useEnabledFeatures } from '../../contexts/ml';
import { usePermissionCheck } from '../../capabilities/check_capabilities';

export interface Tab {
id: string;
Expand All @@ -38,6 +39,7 @@ export function useSideNavItems(activeRoute: MlRoute | undefined) {

const mlFeaturesDisabled = !isFullLicense();
const { isADEnabled, isDFAEnabled } = useEnabledFeatures();
const [canUseAiops] = usePermissionCheck(['canUseAiops']);

const [globalState] = useUrlState('_g');

Expand Down Expand Up @@ -158,6 +160,10 @@ export function useSideNavItems(activeRoute: MlRoute | undefined) {
: []),
];

if (canUseAiops === false) {
return mlTabs;
}

mlTabs.push({
id: 'aiops_section',
name: i18n.translate('xpack.ml.navMenu.aiopsTabLinkText', {
Expand Down Expand Up @@ -203,7 +209,7 @@ export function useSideNavItems(activeRoute: MlRoute | undefined) {
});

return mlTabs;
}, [mlFeaturesDisabled, isADEnabled, isDFAEnabled]);
}, [mlFeaturesDisabled, isADEnabled, isDFAEnabled, canUseAiops]);

const getTabItem: (tab: Tab) => EuiSideNavItemType<unknown> = useCallback(
(tab: Tab) => {
Expand Down
Loading