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

[7.x] [ML] Adding cloud specific ML node warning (#50139) #50281

Merged
merged 1 commit into from
Nov 12, 2019
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
Expand Up @@ -4,5 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/


export { NodeAvailableWarning } from './node_available_warning';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Fragment, FC } from 'react';

import { EuiCallOut, EuiLink, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { mlNodesAvailable, permissionToViewMlNodeCount } from '../../../../ml_nodes_check';
import { cloudDeploymentId, isCloud } from '../../../../jobs/new_job_new/utils/new_job_defaults';

export const NodeAvailableWarning: FC = () => {
if (mlNodesAvailable() === true || permissionToViewMlNodeCount() === false) {
return null;
} else {
const id = cloudDeploymentId();
return (
<Fragment>
<EuiCallOut
title={
<FormattedMessage
id="xpack.ml.jobsList.nodeAvailableWarning.noMLNodesAvailableTitle"
defaultMessage="No ML nodes available"
/>
}
color="warning"
iconType="alert"
>
<p>
<FormattedMessage
id="xpack.ml.jobsList.nodeAvailableWarning.noMLNodesAvailableDescription"
defaultMessage="There are no ML nodes available."
/>
<br />
<FormattedMessage
id="xpack.ml.jobsList.nodeAvailableWarning.unavailableCreateOrRunJobsDescription"
defaultMessage="You will not be able to create or run jobs."
/>
{isCloud && id !== null && (
<Fragment>
<br />
<FormattedMessage
id="xpack.ml.jobsList.nodeAvailableWarning.linkToCloudDescription"
defaultMessage="Please edit your {link}. You may enable a free 1GB machine learning node or expand your existing ML configuration."
values={{
link: (
<EuiLink href={`https://cloud.elastic.co/deployments?q=${id}`}>
<FormattedMessage
id="xpack.ml.jobsList.nodeAvailableWarning.linkToCloud.hereLinkText"
defaultMessage="Elastic Cloud deployment"
/>
</EuiLink>
),
}}
/>
</Fragment>
)}
</p>
</EuiCallOut>
<EuiSpacer size="m" />
</Fragment>
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,32 @@ export interface MlServerLimits {
max_model_memory_limit?: string;
}

export interface CloudInfo {
cloudId: string | null;
isCloud: boolean;
}

let defaults: MlServerDefaults = {
anomaly_detectors: {},
datafeeds: {},
};
let limits: MlServerLimits = {};

const cloudInfo: CloudInfo = {
cloudId: null,
isCloud: false,
};

export async function loadNewJobDefaults() {
try {
const resp = await ml.mlInfo();
defaults = resp.defaults;
limits = resp.limits;
return { defaults, limits };
cloudInfo.cloudId = resp.cloudId || null;
cloudInfo.isCloud = resp.cloudId !== undefined;
return { defaults, limits, cloudId: cloudInfo };
} catch (error) {
return { defaults, limits };
return { defaults, limits, cloudId: cloudInfo };
}
}

Expand All @@ -43,3 +55,24 @@ export function newJobDefaults(): MlServerDefaults {
export function newJobLimits(): MlServerLimits {
return limits;
}

export function cloudId(): string | null {
return cloudInfo.cloudId;
}

export function isCloud(): boolean {
return cloudInfo.isCloud;
}

export function cloudDeploymentId(): string | null {
if (cloudInfo.cloudId === null) {
return null;
}
const tempCloudId = cloudInfo.cloudId.replace(/^.+:/, '');
try {
const matches = atob(tempCloudId).match(/^.+\$(.+)(?=\$)/);
return matches !== null && matches.length === 2 ? matches[1] : null;
} catch (error) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface MlInfoResponse {
version: string;
};
upgrade_mode: boolean;
cloudId?: string;
}

declare interface Ml {
Expand Down
14 changes: 11 additions & 3 deletions x-pack/legacy/plugins/ml/server/routes/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { isSecurityDisabled } from '../lib/security_utils';
export function systemRoutes({
commonRouteConfig,
elasticsearchPlugin,
config,
route,
xpackMainPlugin,
spacesPlugin
Expand Down Expand Up @@ -168,10 +169,17 @@ export function systemRoutes({
route({
method: 'GET',
path: '/api/ml/info',
handler(request) {
async handler(request) {
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
return callWithRequest('ml.info')
.catch(resp => wrapError(resp));

try {
const info = await callWithRequest('ml.info');
const cloudIdKey = 'xpack.cloud.id';
const cloudId = config.has(cloudIdKey) && config.get(cloudIdKey);
return { ...info, cloudId };
} catch (error) {
return wrapError(error);
}
},
config: {
...commonRouteConfig
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -6198,10 +6198,8 @@
"xpack.ml.jobsList.multiJobsActions.startDatafeedsLabel": "{jobsCount, plural, one {データフィード} other {データフィード}}を開始",
"xpack.ml.jobsList.multiJobsActions.stopDatafeedsLabel": "{jobsCount, plural, one {データフィード} other {データフィード}}を停止",
"xpack.ml.jobsList.nodeAvailableWarning.linkToCloud.hereLinkText": "こちら",
"xpack.ml.jobsList.nodeAvailableWarning.linkToCloudDescription": "これはクラウド {hereCloudLink} で構成できます。",
"xpack.ml.jobsList.nodeAvailableWarning.noMLNodesAvailableDescription": "利用可能な ML ノードがありません。",
"xpack.ml.jobsList.nodeAvailableWarning.noMLNodesAvailableTitle": "利用可能な ML ノードがありません",
"xpack.ml.jobsList.nodeAvailableWarning.unavailableCreateOrRunJobsDescription": "ジョブの作成または実行はできません. {cloudConfigLink}",
"xpack.ml.jobsList.noJobsFoundLabel": "ジョブが見つかりません",
"xpack.ml.jobsList.processedRecordsLabel": "処理済みレコード",
"xpack.ml.jobsList.refreshButtonLabel": "更新",
Expand Down Expand Up @@ -10314,4 +10312,4 @@
"xpack.fileUpload.fileParser.errorReadingFile": "ファイルの読み込み中にエラーが発生しました",
"xpack.fileUpload.fileParser.noFileProvided": "エラー、ファイルが提供されていません"
}
}
}
4 changes: 1 addition & 3 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -6199,10 +6199,8 @@
"xpack.ml.jobsList.multiJobsActions.startDatafeedsLabel": "开始 {jobsCount, plural, one { 个数据馈送} other { 个数据馈送}}",
"xpack.ml.jobsList.multiJobsActions.stopDatafeedsLabel": "停止 {jobsCount, plural, one { 个数据馈送} other { 个数据馈送}}",
"xpack.ml.jobsList.nodeAvailableWarning.linkToCloud.hereLinkText": "此处",
"xpack.ml.jobsList.nodeAvailableWarning.linkToCloudDescription": "这可以在云 {hereCloudLink} 中进行配置。",
"xpack.ml.jobsList.nodeAvailableWarning.noMLNodesAvailableDescription": "没有可用的 ML 节点。",
"xpack.ml.jobsList.nodeAvailableWarning.noMLNodesAvailableTitle": "没有可用的 ML 节点",
"xpack.ml.jobsList.nodeAvailableWarning.unavailableCreateOrRunJobsDescription": "您将无法创建或运行作业。{cloudConfigLink}",
"xpack.ml.jobsList.noJobsFoundLabel": "找不到作业",
"xpack.ml.jobsList.processedRecordsLabel": "已处理记录",
"xpack.ml.jobsList.refreshButtonLabel": "刷新",
Expand Down Expand Up @@ -10469,4 +10467,4 @@
"xpack.fileUpload.fileParser.errorReadingFile": "读取文件时出错",
"xpack.fileUpload.fileParser.noFileProvided": "错误,未提供任何文件"
}
}
}