Skip to content

Commit

Permalink
[ML] Removing ignore_throttled from anomaly detection job results sea…
Browse files Browse the repository at this point in the history
…rches (elastic#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.
  • Loading branch information
jgowdyelastic authored Dec 13, 2024
1 parent 46a1535 commit a69a456
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { omit } from 'lodash';
import type { Aggregation, Datafeed } from '../types/anomaly_detection_jobs';

export function getAggregations<T>(obj: any): T | undefined {
Expand All @@ -18,3 +19,10 @@ export const getDatafeedAggregations = (
): Aggregation | undefined => {
return getAggregations<Aggregation>(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')
: {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -190,7 +190,7 @@ export function fieldsServiceProvider({ asCurrentUser }: IScopedClusterClient) {
{
index,
body,
...(datafeedConfig?.indices_options ?? {}),
...getIndicesOptions(datafeedConfig),
},
{ maxRetries: 0 }
);
Expand Down Expand Up @@ -418,7 +418,7 @@ export function fieldsServiceProvider({ asCurrentUser }: IScopedClusterClient) {
{
index,
body,
...(datafeedConfig?.indices_options ?? {}),
...getIndicesOptions(datafeedConfig),
},
{ maxRetries: 0 }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof validateJobSchema>;
Expand Down Expand Up @@ -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)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -727,7 +728,7 @@ export function resultsServiceProvider(mlClient: MlClient, client?: IScopedClust
},
size: 0,
},
...(datafeedConfig?.indices_options ?? {}),
...getIndicesOptions(datafeedConfig),
};

if (client) {
Expand Down

0 comments on commit a69a456

Please sign in to comment.