Skip to content

Commit

Permalink
[Uptime] Convert anomaly Jobs name to lowercase to comply with… (#62293)
Browse files Browse the repository at this point in the history
* converted ml job name to lower case

* update type
  • Loading branch information
shahzad31 committed Apr 2, 2020
1 parent a025f59 commit 8265ebc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ const showMLJobNotification = (
</MLJobLink>
</p>
),
toastLifeTimeMs: 5000,
toastLifeTimeMs: 10000,
});
} else {
notifications.toasts.warning({
notifications.toasts.danger({
title: <p>{labels.JOB_CREATION_FAILED}</p>,
body: message ?? <p>{labels.JOB_CREATION_FAILED_MESSAGE}</p>,
toastLifeTimeMs: 5000,
toastLifeTimeMs: 10000,
});
}
};
Expand Down Expand Up @@ -108,7 +108,7 @@ export const MachineLearningFlyout: React.FC<Props> = ({ onClose }) => {
basePath,
{ to: dateRangeEnd, from: dateRangeStart },
false,
error?.body?.message
error?.message || error?.body?.message
);
}
setIsCreatingJob(false);
Expand Down
25 changes: 17 additions & 8 deletions x-pack/legacy/plugins/uptime/public/state/api/ml_anomaly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CreateMLJobSuccess, DeleteJobResults, MonitorIdParam } from '../actions
import { DataRecognizerConfigResponse } from '../../../../../../plugins/ml/common/types/modules';
import { JobExistResult } from '../../../../../../plugins/ml/common/types/data_recognizer';

export const getMLJobId = (monitorId: string) => `${monitorId}_${ML_JOB_ID}`;
export const getMLJobId = (monitorId: string) => `${monitorId}_${ML_JOB_ID}`.toLowerCase();

export const getMLCapabilities = async (): Promise<PrivilegesResponse> => {
return await apiService.get(API_URLS.ML_CAPABILITIES);
Expand All @@ -28,8 +28,11 @@ export const createMLJob = async ({
}: MonitorIdParam): Promise<CreateMLJobSuccess | null> => {
const url = API_URLS.ML_SETUP_MODULE + ML_MODULE_ID;

// ML App doesn't support upper case characters in job name
const lowerCaseMonitorId = monitorId.toLowerCase();

const data = {
prefix: `${monitorId}_`,
prefix: `${lowerCaseMonitorId}_`,
useDedicatedIndex: false,
startDatafeed: true,
start: moment()
Expand All @@ -41,7 +44,7 @@ export const createMLJob = async ({
filter: [
{
term: {
'monitor.id': monitorId,
'monitor.id': lowerCaseMonitorId,
},
},
],
Expand All @@ -50,11 +53,17 @@ export const createMLJob = async ({
};

const response: DataRecognizerConfigResponse = await apiService.post(url, data);
if (response?.jobs?.[0]?.id === getMLJobId(monitorId) && response?.jobs?.[0]?.success) {
return {
count: 1,
jobId: response?.jobs?.[0]?.id,
};
if (response?.jobs?.[0]?.id === getMLJobId(monitorId)) {
const jobResponse = response.jobs[0];
if (jobResponse.success) {
return {
count: 1,
jobId: jobResponse.id,
};
} else {
const { error } = jobResponse;
throw new Error(error?.msg);
}
} else {
return null;
}
Expand Down

0 comments on commit 8265ebc

Please sign in to comment.