Skip to content
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] Display link to create data view from error cases in data frame analytics results pages #143596

Merged
merged 5 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { DataFrameAnalyticsConfig } from '../../../../common/types/data_frame_analytics';

export const getDestinationIndex = (jobConfig: DataFrameAnalyticsConfig | undefined) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion to add if (!jobConfig) return ''; in the beginning so we don't have to check for it three times.

(Array.isArray(jobConfig?.dest.index) ? jobConfig?.dest.index[0] : jobConfig?.dest.index) ?? '';
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export { getDefaultFieldsFromJobCaps, sortExplorationResultsFields, MAX_COLUMNS

export { getIndexData } from './get_index_data';
export { getIndexFields } from './get_index_fields';
export { getDestinationIndex } from './get_destination_index';
export { getScatterplotMatrixLegendType } from './get_scatterplot_matrix_legend_type';

export { useResultsViewConfig } from './use_results_view_config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
isClassificationAnalysis,
isRegressionAnalysis,
} from '../../../../common/util/analytics_utils';
import { getDestinationIndex } from './get_destination_index';

export const useResultsViewConfig = (jobId: string) => {
const mlContext = useMlContext();
Expand Down Expand Up @@ -95,9 +96,7 @@ export const useResultsViewConfig = (jobId: string) => {
}

try {
const destIndex = Array.isArray(jobConfigUpdate.dest.index)
? jobConfigUpdate.dest.index[0]
: jobConfigUpdate.dest.index;
const destIndex = getDestinationIndex(jobConfigUpdate);
const destDataViewId = (await getDataViewIdFromName(destIndex)) ?? destIndex;
let dataView: DataView | undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getScatterplotMatrixLegendType,
useResultsViewConfig,
DataFrameAnalyticsConfig,
getDestinationIndex,
} from '../../../../common';
import { ResultsSearchQuery, ANALYSIS_CONFIG_TYPE } from '../../../../common/analytics';

Expand All @@ -32,6 +33,7 @@ import { LoadingPanel } from '../loading_panel';
import { FeatureImportanceSummaryPanelProps } from '../total_feature_importance_summary/feature_importance_summary';
import { useExplorationUrlState } from '../../hooks/use_exploration_url_state';
import { ExplorationQueryBarProps } from '../exploration_query_bar/exploration_query_bar';
import { IndexPatternPrompt } from '../index_pattern_prompt';

function getFilters(resultsField: string) {
return {
Expand Down Expand Up @@ -114,6 +116,8 @@ export const ExplorationPageWrapper: FC<Props> = ({
};

const resultsField = jobConfig?.dest.results_field ?? '';
const destIndex = getDestinationIndex(jobConfig);

const scatterplotFieldOptions = useScatterplotFieldOptions(
indexPattern,
jobConfig?.analyzed_fields?.includes,
Expand All @@ -131,7 +135,12 @@ export const ExplorationPageWrapper: FC<Props> = ({
color="danger"
iconType="cross"
>
<p>{indexPatternErrorMessage}</p>
<p>
{indexPatternErrorMessage}
{needsDestIndexPattern ? (
<IndexPatternPrompt destIndex={destIndex} color="text" />
) : null}
</p>
</EuiCallOut>
</EuiPanel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { EuiLink, EuiText } from '@elastic/eui';
import { useMlKibana } from '../../../../../contexts/kibana';

interface Props {
destIndex: string;
color?: string;
destIndex?: string;
}

export const IndexPatternPrompt: FC<Props> = ({ destIndex }) => {
export const IndexPatternPrompt: FC<Props> = ({ destIndex, color }) => {
const {
services: {
http: { basePath },
Expand All @@ -30,20 +31,20 @@ export const IndexPatternPrompt: FC<Props> = ({ destIndex }) => {

return (
<>
<EuiText size="xs" color="warning">
<EuiText size="xs" color={color ?? 'warning'}>
<FormattedMessage
id="xpack.ml.dataframe.analytics.dataViewPromptMessage"
defaultMessage="No data view exists for index {destIndex}. "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will leave an extra space before the period if the destIndex is undefined. "No data view exists for index ."

values={{
destIndex,
destIndex: destIndex ?? '',
}}
/>
{canCreateDataView === true ? (
<FormattedMessage
id="xpack.ml.dataframe.analytics.dataViewPromptLink"
defaultMessage="{linkToDataViewManagement} for {destIndex}."
defaultMessage="{linkToDataViewManagement}{destIndex}."
values={{
destIndex,
destIndex: destIndex ? ` for ${destIndex}` : '',
linkToDataViewManagement: (
<EuiLink
href={`${basePath.get()}/app/management/kibana/dataViews/create`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
import { useScatterplotFieldOptions } from '../../../../../components/scatterplot_matrix';
import { SavedSearchQuery } from '../../../../../contexts/ml';

import { defaultSearchQuery, isOutlierAnalysis, useResultsViewConfig } from '../../../../common';
import {
defaultSearchQuery,
isOutlierAnalysis,
useResultsViewConfig,
getDestinationIndex,
} from '../../../../common';
import { FEATURE_INFLUENCE } from '../../../../common/constants';

import {
Expand All @@ -33,6 +38,7 @@ import { getFeatureCount } from './common';
import { useOutlierData } from './use_outlier_data';
import { useExplorationUrlState } from '../../hooks/use_exploration_url_state';
import { ExplorationQueryBarProps } from '../exploration_query_bar/exploration_query_bar';
import { IndexPatternPrompt } from '../index_pattern_prompt';

export type TableItem = Record<string, any>;

Expand Down Expand Up @@ -90,6 +96,7 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) =
jobConfig?.analyzed_fields?.excludes,
resultsField
);
const destIndex = getDestinationIndex(jobConfig);

if (indexPatternErrorMessage !== undefined) {
return (
Expand All @@ -101,7 +108,12 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) =
color="danger"
iconType="cross"
>
<p>{indexPatternErrorMessage}</p>
<p>
{indexPatternErrorMessage}
{needsDestIndexPattern ? (
<IndexPatternPrompt destIndex={destIndex} color="text" />
) : null}
</p>
</EuiCallOut>
</EuiPanel>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* 2.0.
*/

import { EuiToolTip } from '@elastic/eui';
import { EuiToolTip, EuiLink, EuiText } from '@elastic/eui';
import React, { FC } from 'react';
import { cloneDeep, isEqual } from 'lodash';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { toMountPoint, wrapWithTheme } from '@kbn/kibana-react-plugin/public';
import { DeepReadonly } from '../../../../../../../common/types/common';
import { DataFrameAnalyticsConfig, isOutlierAnalysis } from '../../../../common';
import { isClassificationAnalysis, isRegressionAnalysis } from '../../../../common/analytics';
Expand Down Expand Up @@ -401,9 +403,15 @@ export const useNavigateToWizardWithClonedJob = () => {
services: {
notifications: { toasts },
data: { dataViews },
http: { basePath },
application: { capabilities },
theme,
},
} = useMlKibana();
const theme$ = theme.theme$;
const navigateToPath = useNavigateToPath();
const canCreateDataView =
capabilities.savedObjectsManagement.edit === true || capabilities.indexPatterns.save === true;

return async (item: Pick<DataFrameAnalyticsListRow, 'config' | 'stats'>) => {
const sourceIndex = Array.isArray(item.config.source.index)
Expand All @@ -416,13 +424,42 @@ export const useNavigateToWizardWithClonedJob = () => {
if (dv !== undefined) {
sourceIndexId = dv.id;
} else {
toasts.addDanger(
i18n.translate('xpack.ml.dataframe.analyticsList.noSourceDataViewForClone', {
defaultMessage:
'Unable to clone the analytics job. No data view exists for index {dataView}.',
values: { dataView: sourceIndex },
})
);
toasts.addDanger({
title: toMountPoint(
wrapWithTheme(
<>
<FormattedMessage
id="xpack.ml.dataframe.analyticsList.noSourceDataViewForClone"
defaultMessage="Unable to clone the analytics job. No data view exists for index {sourceIndex}."
values={{ sourceIndex }}
/>
{canCreateDataView ? (
<EuiText size="xs" color="text">
<FormattedMessage
id="xpack.ml.dataframe.analytics.cloneAction.dataViewPromptLink"
defaultMessage="{linkToDataViewManagement}"
values={{
linkToDataViewManagement: (
<EuiLink
href={`${basePath.get()}/app/management/kibana/dataViews/create`}
target="_blank"
>
<FormattedMessage
id="xpack.ml.dataframe.analytics.cloneAction.dataViewPromptLinkText"
defaultMessage="Create a data view for {sourceIndex}"
values={{ sourceIndex }}
/>
</EuiLink>
),
}}
/>
</EuiText>
) : null}
</>,
theme$
)
),
});
}
} catch (e) {
const error = extractErrorMessage(e);
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -19188,7 +19188,6 @@
"xpack.ml.dataframe.analyticsList.errorWithCheckingIfUserCanDeleteIndexNotificationErrorMessage": "Une erreur s'est produite lors de la vérification de la possibilité pour un utilisateur de supprimer {destinationIndex} : {error}",
"xpack.ml.dataframe.analyticsList.fetchSourceDataViewForCloneErrorMessage": "Une erreur s’est produite lors de la vérification de l’existence de la vue de données {dataView} : {error}",
"xpack.ml.dataframe.analyticsList.forceStopModalBody": "{analyticsId} est en état d'échec. Vous devez arrêter la tâche et corriger la défaillance.",
"xpack.ml.dataframe.analyticsList.noSourceDataViewForClone": "Impossible de cloner la tâche d'analyse. Il n’existe aucune vue de données pour l’index {dataView}.",
"xpack.ml.dataframe.analyticsList.progressOfPhase": "Progression de la phase {currentPhase} : {progress}%",
"xpack.ml.dataframe.analyticsList.rowCollapse": "Masquer les détails pour {analyticsId}",
"xpack.ml.dataframe.analyticsList.rowExpand": "Afficher les détails pour {analyticsId}",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -19169,7 +19169,6 @@
"xpack.ml.dataframe.analyticsList.errorWithCheckingIfUserCanDeleteIndexNotificationErrorMessage": "ユーザーが{destinationIndex}を削除できるかどうかを確認するときにエラーが発生しました。{error}",
"xpack.ml.dataframe.analyticsList.fetchSourceDataViewForCloneErrorMessage": "データビュー{dataView}が存在するかどうかを確認しているときにエラーが発生しました:{error}",
"xpack.ml.dataframe.analyticsList.forceStopModalBody": "{analyticsId}は失敗状態です。ジョブを停止して、エラーを修正する必要があります。",
"xpack.ml.dataframe.analyticsList.noSourceDataViewForClone": "分析ジョブを複製できません。インデックス{dataView}のデータビューは存在しません。",
"xpack.ml.dataframe.analyticsList.progressOfPhase": "フェーズ{currentPhase}の進捗:{progress}%",
"xpack.ml.dataframe.analyticsList.rowCollapse": "{analyticsId}の詳細を非表示",
"xpack.ml.dataframe.analyticsList.rowExpand": "{analyticsId}の詳細を表示",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -19195,7 +19195,6 @@
"xpack.ml.dataframe.analyticsList.errorWithCheckingIfUserCanDeleteIndexNotificationErrorMessage": "检查用户是否能够删除 {destinationIndex} 时发生错误:{error}",
"xpack.ml.dataframe.analyticsList.fetchSourceDataViewForCloneErrorMessage": "检查数据视图 {dataView} 是否存在时发生错误:{error}",
"xpack.ml.dataframe.analyticsList.forceStopModalBody": "{analyticsId} 处于失败状态。您必须停止该作业并修复失败问题。",
"xpack.ml.dataframe.analyticsList.noSourceDataViewForClone": "无法克隆分析作业。对于索引 {dataView},不存在数据视图。",
"xpack.ml.dataframe.analyticsList.progressOfPhase": "阶段 {currentPhase} 的进度:{progress}%",
"xpack.ml.dataframe.analyticsList.rowCollapse": "隐藏 {analyticsId} 的详情",
"xpack.ml.dataframe.analyticsList.rowExpand": "显示 {analyticsId} 的详情",
Expand Down