From a69a456e698d5905753359e6ee10a7b3d1cfbe38 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 13 Dec 2024 09:27:16 +0000 Subject: [PATCH] [ML] Removing ignore_throttled from anomaly detection job results searches (#203788) `ignore_throttled` is automatically added to AD jobs when created. These are then reused in various searches where the whole `indices_options` object from the datafeed is passed in the search call. This PR adds a function to remove `ignore_throttled` in these situations to avoid triggering deprecation warnings. --- .../plugins/shared/ml/common/util/datafeed_utils.ts | 8 ++++++++ .../revert_model_snapshot_flyout/chart_loader.ts | 3 ++- .../ml/server/models/fields_service/fields_service.ts | 6 +++--- .../ml/server/models/job_validation/job_validation.ts | 4 ++-- .../ml/server/models/results_service/results_service.ts | 3 ++- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/x-pack/platform/plugins/shared/ml/common/util/datafeed_utils.ts b/x-pack/platform/plugins/shared/ml/common/util/datafeed_utils.ts index 9f66ac143ffe1..31c526a8b1706 100644 --- a/x-pack/platform/plugins/shared/ml/common/util/datafeed_utils.ts +++ b/x-pack/platform/plugins/shared/ml/common/util/datafeed_utils.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { omit } from 'lodash'; import type { Aggregation, Datafeed } from '../types/anomaly_detection_jobs'; export function getAggregations(obj: any): T | undefined { @@ -18,3 +19,10 @@ export const getDatafeedAggregations = ( ): Aggregation | undefined => { return getAggregations(datafeedConfig); }; + +export function getIndicesOptions(datafeedConfig?: Datafeed) { + // remove ignore_throttled from indices_options to avoid deprecation warnings in the logs + return datafeedConfig?.indices_options + ? omit(datafeedConfig.indices_options, 'ignore_throttled') + : {}; +} diff --git a/x-pack/platform/plugins/shared/ml/public/application/components/model_snapshots/revert_model_snapshot_flyout/chart_loader.ts b/x-pack/platform/plugins/shared/ml/public/application/components/model_snapshots/revert_model_snapshot_flyout/chart_loader.ts index b18d3e444d73d..573b850fcd2a5 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/components/model_snapshots/revert_model_snapshot_flyout/chart_loader.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/components/model_snapshots/revert_model_snapshot_flyout/chart_loader.ts @@ -6,6 +6,7 @@ */ import { getSeverityType } from '@kbn/ml-anomaly-utils'; +import { getIndicesOptions } from '../../../../../common/util/datafeed_utils'; import type { MlResultsService } from '../../../services/results_service'; import type { CombinedJobWithStats } from '../../../../../common/types/anomaly_detection_jobs'; import type { Anomaly } from '../../../jobs/new_job/common/results_loader/results_loader'; @@ -32,7 +33,7 @@ export function chartLoaderProvider(mlResultsService: MlResultsService) { job.data_counts.latest_record_timestamp!, intervalMs, job.datafeed_config.runtime_mappings, - job.datafeed_config.indices_options + getIndicesOptions(job.datafeed_config) ); if (resp.error !== undefined) { throw resp.error; diff --git a/x-pack/platform/plugins/shared/ml/server/models/fields_service/fields_service.ts b/x-pack/platform/plugins/shared/ml/server/models/fields_service/fields_service.ts index 95e97ef01e3b3..f68a7b0c7560d 100644 --- a/x-pack/platform/plugins/shared/ml/server/models/fields_service/fields_service.ts +++ b/x-pack/platform/plugins/shared/ml/server/models/fields_service/fields_service.ts @@ -17,7 +17,7 @@ import { parseInterval } from '@kbn/ml-parse-interval'; import { initCardinalityFieldsCache } from './fields_aggs_cache'; import { isValidAggregationField } from '../../../common/util/validation_utils'; -import { getDatafeedAggregations } from '../../../common/util/datafeed_utils'; +import { getDatafeedAggregations, getIndicesOptions } from '../../../common/util/datafeed_utils'; import type { Datafeed, IndicesOptions } from '../../../common/types/anomaly_detection_jobs'; /** @@ -190,7 +190,7 @@ export function fieldsServiceProvider({ asCurrentUser }: IScopedClusterClient) { { index, body, - ...(datafeedConfig?.indices_options ?? {}), + ...getIndicesOptions(datafeedConfig), }, { maxRetries: 0 } ); @@ -418,7 +418,7 @@ export function fieldsServiceProvider({ asCurrentUser }: IScopedClusterClient) { { index, body, - ...(datafeedConfig?.indices_options ?? {}), + ...getIndicesOptions(datafeedConfig), }, { maxRetries: 0 } ); diff --git a/x-pack/platform/plugins/shared/ml/server/models/job_validation/job_validation.ts b/x-pack/platform/plugins/shared/ml/server/models/job_validation/job_validation.ts index fff24e7730f18..a44083df9f9f4 100644 --- a/x-pack/platform/plugins/shared/ml/server/models/job_validation/job_validation.ts +++ b/x-pack/platform/plugins/shared/ml/server/models/job_validation/job_validation.ts @@ -25,7 +25,7 @@ import { validateTimeRange, isValidTimeField } from './validate_time_range'; import type { validateJobSchema } from '../../routes/schemas/job_validation_schema'; import type { CombinedJob } from '../../../common/types/anomaly_detection_jobs'; import type { MlClient } from '../../lib/ml_client'; -import { getDatafeedAggregations } from '../../../common/util/datafeed_utils'; +import { getDatafeedAggregations, getIndicesOptions } from '../../../common/util/datafeed_utils'; import type { AuthorizationHeader } from '../../lib/request_authorization'; export type ValidateJobPayload = TypeOf; @@ -74,7 +74,7 @@ export async function validateJob( timeField, job.datafeed_config.query, job.datafeed_config.runtime_mappings, - job.datafeed_config.indices_options + getIndicesOptions(job.datafeed_config) ); } diff --git a/x-pack/platform/plugins/shared/ml/server/models/results_service/results_service.ts b/x-pack/platform/plugins/shared/ml/server/models/results_service/results_service.ts index bbf9c4def4722..a0a11bfcc912c 100644 --- a/x-pack/platform/plugins/shared/ml/server/models/results_service/results_service.ts +++ b/x-pack/platform/plugins/shared/ml/server/models/results_service/results_service.ts @@ -19,6 +19,7 @@ import { ML_JOB_ID, ML_PARTITION_FIELD_VALUE, } from '@kbn/ml-anomaly-utils'; +import { getIndicesOptions } from '../../../common/util/datafeed_utils'; import { buildAnomalyTableItems } from './build_anomaly_table_items'; import { ANOMALIES_TABLE_DEFAULT_QUERY_SIZE } from '../../../common/constants/search'; import { getPartitionFieldsValuesFactory } from './get_partition_fields_values'; @@ -727,7 +728,7 @@ export function resultsServiceProvider(mlClient: MlClient, client?: IScopedClust }, size: 0, }, - ...(datafeedConfig?.indices_options ?? {}), + ...getIndicesOptions(datafeedConfig), }; if (client) {