Skip to content

Commit

Permalink
[ML] Change DatafeedOverride to Datafeed
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Nov 5, 2020
1 parent f54c8e8 commit 7355559
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -640,7 +636,7 @@ export function mlApiServicesProvider(httpService: HttpService) {
earliestMs,
latestMs,
}: {
datafeedConfig: DatafeedOverride;
datafeedConfig?: Datafeed;
analysisConfig: AnalysisConfig;
indexPattern: string;
query: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,10 +71,10 @@ export function resultsServiceRxProvider(mlApiServices: MlApiServices) {
earliestMs: number,
latestMs: number,
intervalMs: number,
dataFeedConfig?: DatafeedOverride
datafeedConfig?: Datafeed
): Observable<MetricData> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -146,7 +145,7 @@ export function calculateModelMemoryLimitProvider(
earliestMs: number,
latestMs: number,
allowMMLGreaterThanMax = false,
datafeedConfig?: DatafeedOverride
datafeedConfig?: Datafeed
): Promise<ModelMemoryEstimationResult> {
const { body: info } = await mlClient.info<MlInfoResponse>();
const maxModelMemoryLimit = info.limits.max_model_memory_limit?.toUpperCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -595,7 +595,7 @@ export class DataVisualizer {
timeFieldName: string,
earliestMs?: number,
latestMs?: number,
datafeedConfig?: DatafeedOverride
datafeedConfig?: Datafeed
) {
const index = indexPatternTitle;
const size = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -40,7 +40,7 @@ export function fieldsServiceProvider({ asCurrentUser }: IScopedClusterClient) {
async function getAggregatableFields(
index: string | string[],
fieldNames: string[],
datafeedConfig?: DatafeedOverride
datafeedConfig?: Datafeed
): Promise<string[]> {
const { body } = await asCurrentUser.fieldCaps({
index,
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/ml/server/routes/job_validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<typeof modelMemoryLimitSchema>;
Expand Down Expand Up @@ -54,7 +53,7 @@ export function jobValidationRoutes(
earliestMs,
latestMs,
undefined,
datafeedConfig as DatafeedOverride
datafeedConfig as Datafeed
);
}

Expand Down

0 comments on commit 7355559

Please sign in to comment.