-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] Trained models list: disables 'View training data' action if data frame analytics job no longer exists #171061
Changes from 7 commits
a407ee2
7c06abd
6d8a4e5
12f1a01
50ffcfd
8c7094d
3bc2c8d
73216d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,18 +130,19 @@ export function useModelActions({ | |
return useMemo( | ||
() => [ | ||
{ | ||
name: i18n.translate('xpack.ml.trainedModels.modelsList.viewTrainingDataActionLabel', { | ||
name: i18n.translate('xpack.ml.trainedModels.modelsList.viewTrainingDataNameActionLabel', { | ||
defaultMessage: 'View training data', | ||
}), | ||
description: i18n.translate( | ||
'xpack.ml.trainedModels.modelsList.viewTrainingDataActionLabel', | ||
{ | ||
defaultMessage: 'View training data', | ||
defaultMessage: 'Training data can be viewed when data frame analytics job exists.', | ||
} | ||
), | ||
icon: 'visTable', | ||
type: 'icon', | ||
available: (item) => !!item.metadata?.analytics_config?.id, | ||
enabled: (item) => item.origin_job_exists === true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a tooltip to show why the action is disabled. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 6d8a4e5 |
||
onClick: async (item) => { | ||
if (item.metadata?.analytics_config === undefined) return; | ||
|
||
|
@@ -164,7 +165,6 @@ export function useModelActions({ | |
|
||
await navigateToUrl(url); | ||
}, | ||
isPrimary: true, | ||
}, | ||
{ | ||
name: i18n.translate('xpack.ml.inference.modelsList.analyticsMapActionLabel', { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,20 +29,19 @@ import { | |
createIngestPipelineSchema, | ||
modelDownloadsQuery, | ||
} from './schemas/inference_schema'; | ||
import type { | ||
import { | ||
PipelineDefinition, | ||
TrainedModelConfigResponse, | ||
type TrainedModelConfigResponse, | ||
} from '../../common/types/trained_models'; | ||
import { mlLog } from '../lib/log'; | ||
import { forceQuerySchema } from './schemas/anomaly_detectors_schema'; | ||
import { modelsProvider } from '../models/model_management'; | ||
|
||
export const DEFAULT_TRAINED_MODELS_PAGE_SIZE = 10000; | ||
|
||
export function filterForEnabledFeatureModels( | ||
models: TrainedModelConfigResponse[] | estypes.MlTrainedModelConfig[], | ||
enabledFeatures: MlFeatures | ||
) { | ||
export function filterForEnabledFeatureModels< | ||
T extends TrainedModelConfigResponse | estypes.MlTrainedModelConfig | ||
>(models: T[], enabledFeatures: MlFeatures) { | ||
let filteredModels = models; | ||
if (enabledFeatures.nlp === false) { | ||
filteredModels = filteredModels.filter((m) => m.model_type === 'tree_ensemble'); | ||
|
@@ -191,10 +190,37 @@ export function trainedModelsRoutes( | |
mlLog.debug(e); | ||
} | ||
|
||
const body = filterForEnabledFeatureModels(result, getEnabledFeatures()); | ||
const filteredModels = filterForEnabledFeatureModels(result, getEnabledFeatures()); | ||
|
||
try { | ||
const jobIdsString = filteredModels.reduce((jobIdsStr, currentModel, idx) => { | ||
let id = currentModel.metadata?.analytics_config?.id ?? ''; | ||
if (id !== '') { | ||
id = `${idx > 0 ? ',' : ''}${id}*`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has a bug where if Something like const jobIds = filteredModels
.map((m) => m.metadata?.analytics_config?.id)
.filter(isDefined)
.map((id) => `${id}*`);
if (jobIds.length) {
const { data_frame_analytics: jobs } = await mlClient.getDataFrameAnalytics({
id: jobIds.join(','),
allow_no_match: true,
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree - updated in 73216d0 |
||
} | ||
return `${jobIdsStr}${id}`; | ||
}, ''); | ||
|
||
if (jobIdsString !== '') { | ||
const { data_frame_analytics: jobs } = await mlClient.getDataFrameAnalytics({ | ||
jgowdyelastic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
id: jobIdsString, | ||
allow_no_match: true, | ||
}); | ||
|
||
filteredModels.forEach((model) => { | ||
const dfaId = model?.metadata?.analytics_config?.id; | ||
if (dfaId !== undefined) { | ||
// if this is a dfa model, set origin_job_exists | ||
model.origin_job_exists = jobs.find((job) => job.id === dfaId) !== undefined; | ||
} | ||
}); | ||
} | ||
} catch (e) { | ||
// Swallow error to prevent blocking trained models result | ||
jgowdyelastic marked this conversation as resolved.
Show resolved
Hide resolved
peteharverson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return response.ok({ | ||
body, | ||
body: filteredModels, | ||
}); | ||
} catch (e) { | ||
return response.customError(wrapError(e)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to be optional route param. We should always perform this check when retrieving the models as it's useful information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 7c06abd