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 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 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
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
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,15 +5,24 @@
* 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) {
export function getPatternAnalysisAvailable(
licensing: LicensingPluginStart,
application: ApplicationStart
) {
const lic = firstValueFrom(licensing.license$);
return async (dataView: DataView) => {
const isPlatinum = (await lic).hasAtLeast('platinum');
const aiopsEnabled = application.capabilities.aiops.enabled;
if (!aiopsEnabled) {
return false;
}

return (
isPlatinum &&
dataView.isTimeBased() &&
Expand Down
5 changes: 3 additions & 2 deletions x-pack/platform/plugins/shared/aiops/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export class AiopsPlugin
Promise.all([firstValueFrom(licensing.license$), core.getStartServices()]).then(
([license, [coreStart, pluginStart]]) => {
const { canUseAiops } = coreStart.application.capabilities.ml;
const aiopsEnabled = coreStart.application.capabilities.aiops.enabled;

if (license.hasAtLeast('platinum') && canUseAiops) {
if (license.hasAtLeast('platinum') && canUseAiops && aiopsEnabled) {
if (embeddable) {
registerEmbeddables(embeddable, core);
}
Expand All @@ -58,7 +59,7 @@ export class AiopsPlugin
const { getPatternAnalysisAvailable } = await import(
'./components/log_categorization/log_categorization_enabled'
);
return getPatternAnalysisAvailable(plugins.licensing);
return getPatternAnalysisAvailable(plugins.licensing, core.application);
},
PatternAnalysisComponent,
};
Expand Down
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()),
})
),
});

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';
31 changes: 31 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,31 @@
/*
* 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 type { AiopsPluginStartDeps } from '../types';

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

core.capabilities.registerSwitcher(
async (request, capabilities, useDefaultCapabilities) => {
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
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