From 73555598dd6f29ff6b11152e4a07791cc23fb218 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 5 Nov 2020 17:50:21 -0600 Subject: [PATCH] [ML] Change DatafeedOverride to Datafeed --- .../application/services/ml_api_service/index.ts | 8 ++------ .../services/results_service/result_service_rx.ts | 10 +++++----- .../calculate_model_memory_limit.ts | 7 +++---- .../server/models/data_visualizer/data_visualizer.ts | 4 ++-- .../ml/server/models/fields_service/fields_service.ts | 6 +++--- x-pack/plugins/ml/server/routes/job_validation.ts | 5 ++--- 6 files changed, 17 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/ml/public/application/services/ml_api_service/index.ts b/x-pack/plugins/ml/public/application/services/ml_api_service/index.ts index d5aeacf65a174..b67b5015dbd6c 100644 --- a/x-pack/plugins/ml/public/application/services/ml_api_service/index.ts +++ b/x-pack/plugins/ml/public/application/services/ml_api_service/index.ts @@ -32,11 +32,7 @@ import { FieldHistogramRequestConfig, FieldRequestConfig, } from '../../datavisualizer/index_based/common'; -import { - DatafeedOverride, - DataRecognizerConfigResponse, - Module, -} from '../../../../common/types/modules'; +import { DataRecognizerConfigResponse, Module } from '../../../../common/types/modules'; import { getHttp } from '../../util/dependency_cache'; export interface MlInfoResponse { @@ -640,7 +636,7 @@ export function mlApiServicesProvider(httpService: HttpService) { earliestMs, latestMs, }: { - datafeedConfig: DatafeedOverride; + datafeedConfig?: Datafeed; analysisConfig: AnalysisConfig; indexPattern: string; query: any; diff --git a/x-pack/plugins/ml/public/application/services/results_service/result_service_rx.ts b/x-pack/plugins/ml/public/application/services/results_service/result_service_rx.ts index 9e51d87300856..fb3c068139e51 100644 --- a/x-pack/plugins/ml/public/application/services/results_service/result_service_rx.ts +++ b/x-pack/plugins/ml/public/application/services/results_service/result_service_rx.ts @@ -16,11 +16,11 @@ import { map } from 'rxjs/operators'; import { each, get } from 'lodash'; import { Dictionary } from '../../../../common/types/common'; import { ML_MEDIAN_PERCENTS } from '../../../../common/util/job_utils'; -import { JobId } from '../../../../common/types/anomaly_detection_jobs'; +import { Datafeed, JobId } from '../../../../common/types/anomaly_detection_jobs'; import { MlApiServices } from '../ml_api_service'; import { CriteriaField } from './index'; -import type { DatafeedOverride } from '../../../../common/types/modules'; import { findAggField } from '../../../../common/util/validation_utils'; +import { getDatafeedAggregations } from '../../../../common/util/datafeed_utils'; interface ResultResponse { success: boolean; @@ -71,10 +71,10 @@ export function resultsServiceRxProvider(mlApiServices: MlApiServices) { earliestMs: number, latestMs: number, intervalMs: number, - dataFeedConfig?: DatafeedOverride + datafeedConfig?: Datafeed ): Observable { - const scriptFields = dataFeedConfig?.script_fields; - const aggFields = dataFeedConfig?.aggs ?? dataFeedConfig?.aggregations; + const scriptFields = datafeedConfig?.script_fields; + const aggFields = getDatafeedAggregations(datafeedConfig); // Build the criteria to use in the bool filter part of the request. // Add criteria for the time range, entity fields, diff --git a/x-pack/plugins/ml/server/models/calculate_model_memory_limit/calculate_model_memory_limit.ts b/x-pack/plugins/ml/server/models/calculate_model_memory_limit/calculate_model_memory_limit.ts index 853019de9ebf8..865f305f2ff9f 100644 --- a/x-pack/plugins/ml/server/models/calculate_model_memory_limit/calculate_model_memory_limit.ts +++ b/x-pack/plugins/ml/server/models/calculate_model_memory_limit/calculate_model_memory_limit.ts @@ -7,10 +7,9 @@ import numeral from '@elastic/numeral'; import { IScopedClusterClient } from 'kibana/server'; import { MLCATEGORY } from '../../../common/constants/field_types'; -import { AnalysisConfig } from '../../../common/types/anomaly_detection_jobs'; +import { AnalysisConfig, Datafeed } from '../../../common/types/anomaly_detection_jobs'; import { fieldsServiceProvider } from '../fields_service'; import { MlInfoResponse } from '../../../common/types/ml_server_info'; -import { DatafeedOverride } from '../../../common/types/modules'; import type { MlClient } from '../../lib/ml_client'; export interface ModelMemoryEstimationResult { @@ -48,7 +47,7 @@ const cardinalityCheckProvider = (client: IScopedClusterClient) => { timeFieldName: string, earliestMs: number, latestMs: number, - datafeedConfig?: DatafeedOverride + datafeedConfig?: Datafeed ): Promise<{ overallCardinality: { [key: string]: number }; maxBucketCardinality: { [key: string]: number }; @@ -146,7 +145,7 @@ export function calculateModelMemoryLimitProvider( earliestMs: number, latestMs: number, allowMMLGreaterThanMax = false, - datafeedConfig?: DatafeedOverride + datafeedConfig?: Datafeed ): Promise { const { body: info } = await mlClient.info(); const maxModelMemoryLimit = info.limits.max_model_memory_limit?.toUpperCase(); diff --git a/x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.ts b/x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.ts index dbd780bc31975..0142e44276eee 100644 --- a/x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.ts +++ b/x-pack/plugins/ml/server/models/data_visualizer/data_visualizer.ts @@ -16,8 +16,8 @@ import { getSamplerAggregationsResponsePath, } from '../../lib/query_utils'; import { AggCardinality } from '../../../common/types/fields'; -import { DatafeedOverride } from '../../../common/types/modules'; import { getDatafeedAggregations } from '../../../common/util/datafeed_utils'; +import { Datafeed } from '../../../common/types/anomaly_detection_jobs'; const SAMPLER_TOP_TERMS_THRESHOLD = 100000; const SAMPLER_TOP_TERMS_SHARD_SIZE = 5000; @@ -595,7 +595,7 @@ export class DataVisualizer { timeFieldName: string, earliestMs?: number, latestMs?: number, - datafeedConfig?: DatafeedOverride + datafeedConfig?: Datafeed ) { const index = indexPatternTitle; const size = 0; diff --git a/x-pack/plugins/ml/server/models/fields_service/fields_service.ts b/x-pack/plugins/ml/server/models/fields_service/fields_service.ts index 7455c4634deda..17f35967a626d 100644 --- a/x-pack/plugins/ml/server/models/fields_service/fields_service.ts +++ b/x-pack/plugins/ml/server/models/fields_service/fields_service.ts @@ -9,10 +9,10 @@ import { IScopedClusterClient } from 'kibana/server'; import { duration } from 'moment'; import { parseInterval } from '../../../common/util/parse_interval'; import { initCardinalityFieldsCache } from './fields_aggs_cache'; -import { DatafeedOverride } from '../../../common/types/modules'; import { AggCardinality } from '../../../common/types/fields'; import { isValidAggregationField } from '../../../common/util/validation_utils'; import { getDatafeedAggregations } from '../../../common/util/datafeed_utils'; +import { Datafeed } from '../../../common/types/anomaly_detection_jobs'; /** * Service for carrying out queries to obtain data @@ -40,7 +40,7 @@ export function fieldsServiceProvider({ asCurrentUser }: IScopedClusterClient) { async function getAggregatableFields( index: string | string[], fieldNames: string[], - datafeedConfig?: DatafeedOverride + datafeedConfig?: Datafeed ): Promise { const { body } = await asCurrentUser.fieldCaps({ index, @@ -87,7 +87,7 @@ export function fieldsServiceProvider({ asCurrentUser }: IScopedClusterClient) { timeFieldName: string, earliestMs: number, latestMs: number, - datafeedConfig?: DatafeedOverride + datafeedConfig?: Datafeed ): Promise<{ [key: string]: number }> { const aggregatableFields = await getAggregatableFields(index, fieldNames, datafeedConfig); diff --git a/x-pack/plugins/ml/server/routes/job_validation.ts b/x-pack/plugins/ml/server/routes/job_validation.ts index 7ee292dba1325..769405c6ef7c2 100644 --- a/x-pack/plugins/ml/server/routes/job_validation.ts +++ b/x-pack/plugins/ml/server/routes/job_validation.ts @@ -7,7 +7,7 @@ import Boom from '@hapi/boom'; import { IScopedClusterClient } from 'kibana/server'; import { TypeOf } from '@kbn/config-schema'; -import { AnalysisConfig } from '../../common/types/anomaly_detection_jobs'; +import { AnalysisConfig, Datafeed } from '../../common/types/anomaly_detection_jobs'; import { wrapError } from '../client/error_wrapper'; import { RouteInitialization } from '../types'; import { @@ -19,7 +19,6 @@ import { import { estimateBucketSpanFactory } from '../models/bucket_span_estimator'; import { calculateModelMemoryLimitProvider } from '../models/calculate_model_memory_limit'; import { validateJob, validateCardinality } from '../models/job_validation'; -import { DatafeedOverride } from '../../common/types/modules'; import type { MlClient } from '../lib/ml_client'; type CalculateModelMemoryLimitPayload = TypeOf; @@ -54,7 +53,7 @@ export function jobValidationRoutes( earliestMs, latestMs, undefined, - datafeedConfig as DatafeedOverride + datafeedConfig as Datafeed ); }