Skip to content

Commit

Permalink
[ML] Adding cloud specific ML node warning (elastic#50139)
Browse files Browse the repository at this point in the history
* [ML] Adding cloud specific ML node warning

* fixing include

* adding callout and cloud checks

* fixing translations

* removing positive look behind in regex
  • Loading branch information
jgowdyelastic committed Nov 12, 2019
1 parent bdfe2df commit 659ae71
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 78 deletions.
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
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -7438,10 +7438,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
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 @@ -7440,10 +7440,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 @@ -13008,4 +13006,4 @@
"xpack.lens.xyVisualization.stackedBarLabel": "堆叠条形图",
"xpack.lens.xyVisualization.xyLabel": "XY"
}
}
}

0 comments on commit 659ae71

Please sign in to comment.