Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
4 changes: 4 additions & 0 deletions config/serverless.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ no_data_page.analyticsNoDataPageFlavor: 'serverless_search'
# Disable Dev tools
xpack.grokdebugger.enabled: false
xpack.painless_lab.enabled: false

xpack.ml.ad.enabled: false
xpack.ml.dfa.enabled: false
xpack.ml.nlp.enabled: true
4 changes: 4 additions & 0 deletions config/serverless.oblt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ xpack.apm.featureFlags.storageExplorerAvailable: false

# Specify in telemetry the project type
telemetry.labels.serverless: observability

xpack.ml.ad.enabled: true
xpack.ml.dfa.enabled: false
xpack.ml.nlp.enabled: false
4 changes: 4 additions & 0 deletions config/serverless.security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ xpack.fleet.internal.registry.spec.max: '3.0'
# Serverless security specific options
xpack.securitySolution.enableExperimental:
- discoverInTimeline

xpack.ml.ad.enabled: true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably not related to the changes here, but should the Memory usage page be accessible in the Security project? There is a link to it from the ML home page, but I get the 'Access denied' page.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The memory usage page is currently disabled in serverless.
This may be a mistake. I've pushed a fix to another WIP PR to change this. As that PR has some similar client side changes.

xpack.ml.dfa.enabled: true
xpack.ml.nlp.enabled: false
21 changes: 21 additions & 0 deletions x-pack/plugins/ml/server/config_schema.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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { schema, type TypeOf } from '@kbn/config-schema';

const enabledSchema = schema.maybe(
schema.object({
enabled: schema.boolean(),
})
);

export const configSchema = schema.object({
ad: enabledSchema,
dfa: enabledSchema,
nlp: enabledSchema,
});

export type ConfigSchema = TypeOf<typeof configSchema>;
9 changes: 7 additions & 2 deletions x-pack/plugins/ml/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { PluginInitializerContext } from '@kbn/core/server';
import type { PluginConfigDescriptor, PluginInitializerContext } from '@kbn/core/server';
import { MlServerPlugin } from './plugin';
export type { MlPluginSetup, MlPluginStart } from './plugin';
export type {
Expand All @@ -26,5 +26,10 @@ export {
InsufficientMLCapabilities,
MLPrivilegesUninitialized,
} from './shared';
import { configSchema, type ConfigSchema } from './config_schema';

export const plugin = (ctx: PluginInitializerContext) => new MlServerPlugin(ctx);
export const config: PluginConfigDescriptor<ConfigSchema> = {
schema: configSchema,
};

export const plugin = (ctx: PluginInitializerContext<ConfigSchema>) => new MlServerPlugin(ctx);
16 changes: 8 additions & 8 deletions x-pack/plugins/ml/server/lib/alerts/alerting_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import Boom from '@hapi/boom';
import { i18n } from '@kbn/i18n';
import rison from '@kbn/rison';
import { Duration } from 'moment/moment';
import type { Duration } from 'moment/moment';
import { memoize } from 'lodash';
import {
FIELD_FORMAT_IDS,
IFieldFormat,
SerializedFieldFormat,
type IFieldFormat,
type SerializedFieldFormat,
} from '@kbn/field-formats-plugin/common';
import { isDefined } from '@kbn/ml-is-defined';
import {
Expand All @@ -24,24 +24,24 @@ import {
ML_ANOMALY_RESULT_TYPE,
} from '@kbn/ml-anomaly-utils';
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
import { MlClient } from '../ml_client';
import {
import type { MlClient } from '../ml_client';
import type {
MlAnomalyDetectionAlertParams,
MlAnomalyDetectionAlertPreviewRequest,
} from '../../routes/schemas/alerting_schema';
import {
import type {
AlertExecutionResult,
InfluencerAnomalyAlertDoc,
PreviewResponse,
PreviewResultsKeys,
RecordAnomalyAlertDoc,
TopHitsResultsKeys,
} from '../../../common/types/alerts';
import { AnomalyDetectionAlertContext } from './register_anomaly_detection_alert_type';
import type { AnomalyDetectionAlertContext } from './register_anomaly_detection_alert_type';
import { resolveMaxTimeInterval } from '../../../common/util/job_utils';
import { getTopNBuckets, resolveLookbackInterval } from '../../../common/util/alerts';
import type { DatafeedsService } from '../../models/job_service/datafeeds';
import { FieldFormatsRegistryProvider } from '../../../common/types/kibana';
import type { FieldFormatsRegistryProvider } from '../../../common/types/kibana';
import type { AwaitReturnType } from '../../../common/types/common';
import { getTypicalAndActualValues } from '../../models/results_service/results_service';
import type { GetDataViewsService } from '../data_views_utils';
Expand Down
20 changes: 10 additions & 10 deletions x-pack/plugins/ml/server/lib/alerts/jobs_health_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
*/

import { groupBy, keyBy, memoize, partition } from 'lodash';
import { KibanaRequest, Logger, SavedObjectsClientContract } from '@kbn/core/server';
import type { KibanaRequest, Logger, SavedObjectsClientContract } from '@kbn/core/server';
import { i18n } from '@kbn/i18n';
import { MlJob } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { MlJob } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { isDefined } from '@kbn/ml-is-defined';
import { MlClient } from '../ml_client';
import { JobSelection } from '../../routes/schemas/alerting_schema';
import { datafeedsProvider, DatafeedsService } from '../../models/job_service/datafeeds';
import type { MlClient } from '../ml_client';
import type { JobSelection } from '../../routes/schemas/alerting_schema';
import { datafeedsProvider, type DatafeedsService } from '../../models/job_service/datafeeds';
import { ALL_JOBS_SELECTION, HEALTH_CHECK_NAMES } from '../../../common/constants/alerts';
import { DatafeedStats } from '../../../common/types/anomaly_detection_jobs';
import { GetGuards } from '../../shared_services/shared_services';
import {
import type { DatafeedStats } from '../../../common/types/anomaly_detection_jobs';
import type { GetGuards } from '../../shared_services/shared_services';
import type {
AnomalyDetectionJobsHealthAlertContext,
DelayedDataResponse,
JobsErrorsResponse,
Expand All @@ -28,12 +28,12 @@ import {
getResultJobsHealthRuleConfig,
resolveLookbackInterval,
} from '../../../common/util/alerts';
import { AnnotationService } from '../../models/annotation_service/annotation';
import type { AnnotationService } from '../../models/annotation_service/annotation';
import { annotationServiceProvider } from '../../models/annotation_service';
import { parseInterval } from '../../../common/util/parse_interval';
import {
jobAuditMessagesProvider,
JobAuditMessagesService,
type JobAuditMessagesService,
} from '../../models/job_audit_messages/job_audit_messages';
import type { FieldFormatsRegistryProvider } from '../../../common/types/kibana';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import { i18n } from '@kbn/i18n';
import { KibanaRequest } from '@kbn/core/server';
import {
import type { KibanaRequest } from '@kbn/core/server';
import type {
ActionGroup,
AlertInstanceContext,
AlertInstanceState,
Expand All @@ -17,11 +17,14 @@ import { ML_ALERT_TYPES } from '../../../common/constants/alerts';
import { PLUGIN_ID } from '../../../common/constants/app';
import { MINIMUM_FULL_LICENSE } from '../../../common/license';
import {
MlAnomalyDetectionAlertParams,
type MlAnomalyDetectionAlertParams,
mlAnomalyDetectionAlertParams,
} from '../../routes/schemas/alerting_schema';
import { RegisterAlertParams } from './register_ml_alerts';
import { InfluencerAnomalyAlertDoc, RecordAnomalyAlertDoc } from '../../../common/types/alerts';
import type { RegisterAlertParams } from './register_ml_alerts';
import {
InfluencerAnomalyAlertDoc,
type RecordAnomalyAlertDoc,
} from '../../../common/types/alerts';

/**
* Base Anomaly detection alerting rule context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

import { i18n } from '@kbn/i18n';
import { KibanaRequest } from '@kbn/core/server';
import {
import type { KibanaRequest } from '@kbn/core/server';
import type {
MlDatafeedState,
MlJobState,
MlJobStats,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import {
import type {
ActionGroup,
AlertInstanceContext,
AlertInstanceState,
Expand All @@ -24,9 +24,9 @@ import { PLUGIN_ID } from '../../../common/constants/app';
import { MINIMUM_FULL_LICENSE } from '../../../common/license';
import {
anomalyDetectionJobsHealthRuleParams,
AnomalyDetectionJobsHealthRuleParams,
type AnomalyDetectionJobsHealthRuleParams,
} from '../../routes/schemas/alerting_schema';
import { RegisterAlertParams } from './register_ml_alerts';
import type { RegisterAlertParams } from './register_ml_alerts';
import type { JobMessage } from '../../../common/types/audit_message';

type ModelSizeStats = MlJobStats['model_size_stats'];
Expand Down
17 changes: 10 additions & 7 deletions x-pack/plugins/ml/server/lib/alerts/register_ml_alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* 2.0.
*/

import { Logger } from '@kbn/core/server';
import { AlertingPlugin } from '@kbn/alerting-plugin/server';
import type { Logger } from '@kbn/core/server';
import type { AlertingPlugin } from '@kbn/alerting-plugin/server';
import { registerAnomalyDetectionAlertType } from './register_anomaly_detection_alert_type';
import { SharedServices } from '../../shared_services';
import type { SharedServices } from '../../shared_services';
import { registerJobsMonitoringRuleType } from './register_jobs_monitoring_rule_type';
import { MlServicesProviders } from '../../shared_services/shared_services';
import type { MlServicesProviders } from '../../shared_services/shared_services';
import type { MlFeatures } from '../../types';

export interface RegisterAlertParams {
alerting: AlertingPlugin['setup'];
Expand All @@ -19,7 +20,9 @@ export interface RegisterAlertParams {
mlServicesProviders: MlServicesProviders;
}

export function registerMlAlerts(alertParams: RegisterAlertParams) {
registerAnomalyDetectionAlertType(alertParams);
registerJobsMonitoringRuleType(alertParams);
export function registerMlAlerts(alertParams: RegisterAlertParams, enabledFeatures: MlFeatures) {
if (enabledFeatures.ad === true) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question/suggestion: did you consider performing a check before registerMlAlerts and registerCasesPersistableState are called?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm passing in the enabled features into registerMlAlerts and have the check happen in there.
I did it this way to allow for future non AD alerts to still be registered by this function. As in, the registerMlAlerts function will decide which alerts to register.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

To move the check out into the plugin.ts file, these register functions would need to be renamed to have AD or similar in the name e.g. registerMlADAlerts
I thought it would be neater to have one function to register all ML alerts, and have it decide which ones to register based on feature enablement.

registerAnomalyDetectionAlertType(alertParams);
registerJobsMonitoringRuleType(alertParams);
}
}
17 changes: 10 additions & 7 deletions x-pack/plugins/ml/server/lib/register_cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import {
CASE_ATTACHMENT_TYPE_ID_ANOMALY_EXPLORER_CHARTS,
CASE_ATTACHMENT_TYPE_ID_ANOMALY_SWIMLANE,
} from '../../common/constants/cases';
import type { MlFeatures } from '../types';

export function registerCasesPersistableState(cases: CasesSetup) {
cases.attachmentFramework.registerPersistableState({
id: CASE_ATTACHMENT_TYPE_ID_ANOMALY_SWIMLANE,
});
export function registerCasesPersistableState(cases: CasesSetup, enabledFeatures: MlFeatures) {
if (enabledFeatures.ad === true) {
cases.attachmentFramework.registerPersistableState({
id: CASE_ATTACHMENT_TYPE_ID_ANOMALY_SWIMLANE,
});

cases.attachmentFramework.registerPersistableState({
id: CASE_ATTACHMENT_TYPE_ID_ANOMALY_EXPLORER_CHARTS,
});
cases.attachmentFramework.registerPersistableState({
id: CASE_ATTACHMENT_TYPE_ID_ANOMALY_EXPLORER_CHARTS,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type { HomeServerPluginSetup } from '@kbn/home-plugin/server';
import type { MlFeatures } from '../types';

export function registerSampleDataSetLinks(
enabledFeatures: MlFeatures,
home: HomeServerPluginSetup
home: HomeServerPluginSetup,
enabledFeatures: MlFeatures
) {
if (enabledFeatures.ad === true) {
const sampleDataLinkLabel = i18n.translate('xpack.ml.sampleDataLinkLabel', {
Expand Down
Loading