|
7 | 7 | import fs from 'fs'; |
8 | 8 | import Boom from 'boom'; |
9 | 9 | import numeral from '@elastic/numeral'; |
10 | | -import { CallAPIOptions, APICaller, SavedObjectsClientContract } from 'kibana/server'; |
| 10 | +import { APICaller, SavedObjectsClientContract } from 'kibana/server'; |
11 | 11 | import moment from 'moment'; |
12 | 12 | import { IndexPatternAttributes } from 'src/plugins/data/server'; |
13 | 13 | import { merge } from 'lodash'; |
14 | 14 | import { AnalysisLimits, CombinedJobWithStats } from '../../../common/types/anomaly_detection_jobs'; |
| 15 | +import { MlInfoResponse } from '../../../common/types/ml_server_info'; |
15 | 16 | import { |
16 | 17 | KibanaObjects, |
17 | 18 | ModuleDataFeed, |
@@ -113,22 +114,15 @@ export class DataRecognizer { |
113 | 114 | modulesDir = `${__dirname}/modules`; |
114 | 115 | indexPatternName: string = ''; |
115 | 116 | indexPatternId: string | undefined = undefined; |
116 | | - savedObjectsClient: SavedObjectsClientContract; |
117 | 117 | /** |
118 | 118 | * List of job ids that require model memory estimation |
119 | 119 | */ |
120 | | - jobsForModelMemoryEstimation: string[] = []; |
| 120 | + jobsForModelMemoryEstimation: ModuleJob[] = []; |
121 | 121 |
|
122 | | - callAsCurrentUser: ( |
123 | | - endpoint: string, |
124 | | - clientParams?: Record<string, any>, |
125 | | - options?: CallAPIOptions |
126 | | - ) => Promise<any>; |
127 | | - |
128 | | - constructor(callAsCurrentUser: APICaller, savedObjectsClient: SavedObjectsClientContract) { |
129 | | - this.callAsCurrentUser = callAsCurrentUser; |
130 | | - this.savedObjectsClient = savedObjectsClient; |
131 | | - } |
| 122 | + constructor( |
| 123 | + private callAsCurrentUser: APICaller, |
| 124 | + private savedObjectsClient: SavedObjectsClientContract |
| 125 | + ) {} |
132 | 126 |
|
133 | 127 | // list all directories under the given directory |
134 | 128 | async listDirs(dirName: string): Promise<string[]> { |
@@ -385,8 +379,8 @@ export class DataRecognizer { |
385 | 379 | startDatafeed?: boolean, |
386 | 380 | start?: number, |
387 | 381 | end?: number, |
388 | | - jobOverrides?: JobOverride[], |
389 | | - datafeedOverrides?: DatafeedOverride[], |
| 382 | + jobOverrides?: JobOverride | JobOverride[], |
| 383 | + datafeedOverrides?: DatafeedOverride | DatafeedOverride[], |
390 | 384 | estimateModelMemory?: boolean |
391 | 385 | ) { |
392 | 386 | // load the config from disk |
@@ -983,27 +977,25 @@ export class DataRecognizer { |
983 | 977 | const calculateModelMemoryLimit = calculateModelMemoryLimitProvider(this.callAsCurrentUser); |
984 | 978 | const query = moduleConfig.query ?? null; |
985 | 979 |
|
986 | | - const jobs = moduleConfig.jobs.filter(job => |
987 | | - this.jobsForModelMemoryEstimation.includes(job.id) |
988 | | - ); |
989 | | - |
990 | 980 | // Checks if all jobs in the module have the same time field configured |
991 | | - const isSameTimeFields = jobs.every( |
992 | | - job => job.config.data_description.time_field === jobs[0].config.data_description.time_field |
| 981 | + const isSameTimeFields = this.jobsForModelMemoryEstimation.every( |
| 982 | + job => |
| 983 | + job.config.data_description.time_field === |
| 984 | + this.jobsForModelMemoryEstimation[0].config.data_description.time_field |
993 | 985 | ); |
994 | 986 |
|
995 | 987 | if (isSameTimeFields && (start === undefined || end === undefined)) { |
996 | 988 | // In case of time range is not provided and the time field is the same |
997 | 989 | // set the fallback range for all jobs |
998 | 990 | const { start: fallbackStart, end: fallbackEnd } = await this.getFallbackTimeRange( |
999 | | - jobs[0].config.data_description.time_field, |
| 991 | + this.jobsForModelMemoryEstimation[0].config.data_description.time_field, |
1000 | 992 | query |
1001 | 993 | ); |
1002 | 994 | start = fallbackStart; |
1003 | 995 | end = fallbackEnd; |
1004 | 996 | } |
1005 | 997 |
|
1006 | | - for (const job of jobs) { |
| 998 | + for (const job of this.jobsForModelMemoryEstimation) { |
1007 | 999 | let earliestMs = start; |
1008 | 1000 | let latestMs = end; |
1009 | 1001 | if (earliestMs === undefined || latestMs === undefined) { |
@@ -1032,7 +1024,7 @@ export class DataRecognizer { |
1032 | 1024 | } |
1033 | 1025 | } |
1034 | 1026 |
|
1035 | | - const { limits } = await this.callAsCurrentUser('ml.info'); |
| 1027 | + const { limits } = await this.callAsCurrentUser<MlInfoResponse>('ml.info'); |
1036 | 1028 | const maxMml = limits.max_model_memory_limit; |
1037 | 1029 |
|
1038 | 1030 | if (!maxMml) { |
@@ -1077,7 +1069,11 @@ export class DataRecognizer { |
1077 | 1069 | return false; |
1078 | 1070 | } |
1079 | 1071 |
|
1080 | | - applyJobConfigOverrides(moduleConfig: Module, jobOverrides?: JobOverride[], jobPrefix = '') { |
| 1072 | + applyJobConfigOverrides( |
| 1073 | + moduleConfig: Module, |
| 1074 | + jobOverrides?: JobOverride | JobOverride[], |
| 1075 | + jobPrefix = '' |
| 1076 | + ) { |
1081 | 1077 | if (jobOverrides === undefined || jobOverrides === null) { |
1082 | 1078 | return; |
1083 | 1079 | } |
@@ -1109,9 +1105,10 @@ export class DataRecognizer { |
1109 | 1105 | if (generalOverrides.some(override => !!override.analysis_limits?.model_memory_limit)) { |
1110 | 1106 | this.jobsForModelMemoryEstimation = []; |
1111 | 1107 | } else { |
1112 | | - this.jobsForModelMemoryEstimation = jobSpecificOverrides |
1113 | | - .filter(override => !override.analysis_limits?.model_memory_limit) |
1114 | | - .map(override => override.job_id); |
| 1108 | + this.jobsForModelMemoryEstimation = moduleConfig.jobs.filter(job => { |
| 1109 | + const override = jobSpecificOverrides.find(o => o.job_id === job.id); |
| 1110 | + return override?.analysis_limits?.model_memory_limit === undefined; |
| 1111 | + }); |
1115 | 1112 | } |
1116 | 1113 |
|
1117 | 1114 | function processArrayValues(source: any, update: any) { |
|
0 commit comments