Skip to content

Commit f0611f8

Browse files
darnautovCAWilson94
authored andcommitted
[ML] Trained Models: Fixes spaces sync to retrieve 10000 models (elastic#202712)
## Summary The default page size for the /trained_models API is 100. As a result, the spaces sync task only fetched the first 100 models, leaving the rest unassigned to spaces and therefore invisible in the ML UI. This PR increases the page size to 10,000 to ensure all models are properly assigned to Kibana spaces. ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
1 parent 404cbee commit f0611f8

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
/**
9+
* Default page for the trained_models endpoint is 100,
10+
* which is too small for the most cases, so we set it to 10000.
11+
*/
12+
export const DEFAULT_TRAINED_MODELS_PAGE_SIZE = 10000;

x-pack/plugins/ml/server/models/data_frame_analytics/analytics_manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from '@kbn/ml-data-frame-analytics-utils';
2121
import { isPopulatedObject } from '@kbn/ml-is-populated-object';
2222
import type { CloudSetup } from '@kbn/cloud-plugin/server';
23+
import { DEFAULT_TRAINED_MODELS_PAGE_SIZE } from '../../../common/constants/trained_models';
2324
import type { MlFeatures } from '../../../common/constants/app';
2425
import type { ModelService } from '../model_management/models_provider';
2526
import { modelsProvider } from '../model_management';
@@ -38,7 +39,6 @@ import {
3839
isTransformLinkReturnType,
3940
} from './types';
4041
import type { MlClient } from '../../lib/ml_client';
41-
import { DEFAULT_TRAINED_MODELS_PAGE_SIZE } from '../../routes/trained_models';
4242

4343
export class AnalyticsManager {
4444
private _trainedModels: estypes.MlTrainedModelConfig[] = [];

x-pack/plugins/ml/server/routes/trained_models.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
} from '@kbn/ml-trained-models-utils';
1818
import { isDefined } from '@kbn/ml-is-defined';
1919
import type { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
20+
import { DEFAULT_TRAINED_MODELS_PAGE_SIZE } from '../../common/constants/trained_models';
2021
import { type MlFeatures, ML_INTERNAL_BASE_PATH } from '../../common/constants/app';
2122
import type { RouteInitialization } from '../types';
2223
import { wrapError } from '../client/error_wrapper';
@@ -44,8 +45,6 @@ import { mlLog } from '../lib/log';
4445
import { forceQuerySchema } from './schemas/anomaly_detectors_schema';
4546
import { modelsProvider } from '../models/model_management';
4647

47-
export const DEFAULT_TRAINED_MODELS_PAGE_SIZE = 10000;
48-
4948
export function filterForEnabledFeatureModels<
5049
T extends TrainedModelConfigResponse | estypes.MlTrainedModelConfig
5150
>(models: T[], enabledFeatures: MlFeatures) {

x-pack/plugins/ml/server/saved_objects/util.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type IScopedClusterClient,
1313
SavedObjectsClient,
1414
} from '@kbn/core/server';
15+
import { DEFAULT_TRAINED_MODELS_PAGE_SIZE } from '../../common/constants/trained_models';
1516
import type { TrainedModelJob, MLSavedObjectService } from './service';
1617
import { ML_JOB_SAVED_OBJECT_TYPE } from '../../common/types/saved_objects';
1718

@@ -86,7 +87,9 @@ export function mlFunctionsFactory(client: IScopedClusterClient) {
8687
},
8788
async getTrainedModels() {
8889
try {
89-
return await client.asInternalUser.ml.getTrainedModels();
90+
return await client.asInternalUser.ml.getTrainedModels({
91+
size: DEFAULT_TRAINED_MODELS_PAGE_SIZE,
92+
});
9093
} catch (error) {
9194
return null;
9295
}

0 commit comments

Comments
 (0)