Skip to content

Commit

Permalink
[ML] Fix retention of categorization example limits (#182103)
Browse files Browse the repository at this point in the history
When updating a job's model memory limits via the UI, if
`categorization_examples_limit` has been set in `analysis_limits`, the
configured value is replaced by the default value of `4`.
This appears to be a
[bug](elastic/elasticsearch#108068) in
elasticsearch and so this PR is a workaround to ensure the original
`categorization_examples_limit` is sent as part of the update to ensure
it isn't reset to the default.

Also fixes an issue in the advanced job wizard where setting
`categorization_examples_limit` in the JSON is not retained when saving
the JSON.
  • Loading branch information
jgowdyelastic authored May 1, 2024
1 parent 06f3c30 commit 0842c60
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ function extractMML(job, newJobData) {
if (mml !== job.analysis_limits.model_memory_limit) {
mmlData.analysis_limits = {
model_memory_limit: mml,
// work around for issue in es where categorization_examples_limit will be reset to the default value
// if it is not included in the update request
// https://github.com/elastic/elasticsearch/issues/108068
...(job.analysis_limits.categorization_examples_limit !== undefined
? {
categorization_examples_limit: job.analysis_limits.categorization_examples_limit,
}
: {}),
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@kbn/ml-anomaly-utils';
import type { RuntimeMappings } from '@kbn/ml-runtime-field-utils';
import type { SavedSearch } from '@kbn/saved-search-plugin/public';
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
import type { IndexPatternTitle } from '../../../../../../common/types/kibana';
import { getQueryFromSavedSearchObject } from '../../../../util/index_utils';
import type {
Expand Down Expand Up @@ -327,11 +328,18 @@ export class JobCreator {

public set modelMemoryLimit(mml: string | null) {
if (mml !== null) {
this._job_config.analysis_limits = {
model_memory_limit: mml,
};
if (this._job_config.analysis_limits === undefined) {
this._job_config.analysis_limits = {};
}
this._job_config.analysis_limits.model_memory_limit = mml;
} else {
delete this._job_config.analysis_limits;
if (this._job_config.analysis_limits !== undefined) {
delete this._job_config.analysis_limits.model_memory_limit;

if (isPopulatedObject(this._job_config.analysis_limits) === false) {
delete this._job_config.analysis_limits;
}
}
}
}

Expand Down

0 comments on commit 0842c60

Please sign in to comment.