[8.14] [ML] Fix retention of categorization example limits (#182103) (#182248)

# Backport

This will backport the following commits from `main` to `8.14`:
- [[ML] Fix retention of categorization example limits
(#182103)](https://github.com/elastic/kibana/pull/182103)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"James
Gowdy","email":"jgowdy@elastic.co"},"sourceCommit":{"committedDate":"2024-05-01T14:11:25Z","message":"[ML]
Fix retention of categorization example limits (#182103)\n\nWhen
updating a job's model memory limits via the UI,
if\r\n`categorization_examples_limit` has been set in `analysis_limits`,
the\r\nconfigured value is replaced by the default value of `4`.\r\nThis
appears to be
a\r\n[bug](https://github.com/elastic/elasticsearch/issues/108068)
in\r\nelasticsearch and so this PR is a workaround to ensure the
original\r\n`categorization_examples_limit` is sent as part of the
update to ensure\r\nit isn't reset to the default.\r\n\r\nAlso fixes an
issue in the advanced job wizard where
setting\r\n`categorization_examples_limit` in the JSON is not retained
when saving\r\nthe
JSON.","sha":"0842c608452d4b7f9a746f9a51395116e325272a","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Feature:Anomaly
Detection","v8.14.0","v8.15.0"],"title":"[ML] Fix retention of
categorization example
limits","number":182103,"url":"https://github.com/elastic/kibana/pull/182103","mergeCommit":{"message":"[ML]
Fix retention of categorization example limits (#182103)\n\nWhen
updating a job's model memory limits via the UI,
if\r\n`categorization_examples_limit` has been set in `analysis_limits`,
the\r\nconfigured value is replaced by the default value of `4`.\r\nThis
appears to be
a\r\n[bug](https://github.com/elastic/elasticsearch/issues/108068)
in\r\nelasticsearch and so this PR is a workaround to ensure the
original\r\n`categorization_examples_limit` is sent as part of the
update to ensure\r\nit isn't reset to the default.\r\n\r\nAlso fixes an
issue in the advanced job wizard where
setting\r\n`categorization_examples_limit` in the JSON is not retained
when saving\r\nthe
JSON.","sha":"0842c608452d4b7f9a746f9a51395116e325272a"}},"sourceBranch":"main","suggestedTargetBranches":["8.14"],"targetPullRequestStates":[{"branch":"8.14","label":"v8.14.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.15.0","branchLabelMappingKey":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/182103","number":182103,"mergeCommit":{"message":"[ML]
Fix retention of categorization example limits (#182103)\n\nWhen
updating a job's model memory limits via the UI,
if\r\n`categorization_examples_limit` has been set in `analysis_limits`,
the\r\nconfigured value is replaced by the default value of `4`.\r\nThis
appears to be
a\r\n[bug](https://github.com/elastic/elasticsearch/issues/108068)
in\r\nelasticsearch and so this PR is a workaround to ensure the
original\r\n`categorization_examples_limit` is sent as part of the
update to ensure\r\nit isn't reset to the default.\r\n\r\nAlso fixes an
issue in the advanced job wizard where
setting\r\n`categorization_examples_limit` in the JSON is not retained
when saving\r\nthe
JSON.","sha":"0842c608452d4b7f9a746f9a51395116e325272a"}}]}] BACKPORT-->

Co-authored-by: James Gowdy <jgowdy@elastic.co>
This commit is contained in:
Kibana Machine 2024-05-01 11:33:29 -04:00 committed by GitHub
parent 95e97f1324
commit eb58ab6f5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View file

@ -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,
}
: {}),
};
}
}

View file

@ -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 {
@ -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;
}
}
}
}