[7.7] [Uptime] Convert anomaly Jobs name to lowercase to compl… (#62348)

* converted ml job name to lower case

* update type
This commit is contained in:
Shahzad 2020-04-03 09:19:55 +02:00 committed by GitHub
parent c0cc32a440
commit 671b444320
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 13 deletions

View file

@ -3,7 +3,7 @@
exports[`ML JobLink renders without errors 1`] = `
<a
class="euiButtonEmpty euiButtonEmpty--primary euiButtonEmpty--small"
href="/app/ml#/explorer?_g=(ml:(jobIds:!(testMonitor_high_latency_by_geo)),refreshInterval:(pause:!t,value:0),time:(from:'',to:''))&_a=(mlExplorerFilter:(filterActive:!t,filteredFields:!(monitor.id,testMonitor)),mlExplorerSwimlane:(viewByFieldName:observer.geo.name))"
href="/app/ml#/explorer?_g=(ml:(jobIds:!(testmonitor_high_latency_by_geo)),refreshInterval:(pause:!t,value:0),time:(from:'',to:''))&_a=(mlExplorerFilter:(filterActive:!t,filteredFields:!(monitor.id,testMonitor)),mlExplorerSwimlane:(viewByFieldName:observer.geo.name))"
rel="noopener noreferrer"
target="_blank"
>

View file

@ -50,13 +50,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,
});
}
};
@ -119,7 +119,7 @@ export const MachineLearningFlyout: React.FC<Props> = ({ onClose }) => {
basePath,
{ to: dateRangeEnd, from: dateRangeStart },
false,
error?.body?.message
error?.message || error?.body?.message
);
}
setIsCreatingJob(false);

View file

@ -18,7 +18,7 @@ import {
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);
@ -34,8 +34,11 @@ export const createMLJob = async ({
}: MonitorIdParam & HeartbeatIndicesParam): 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()
@ -47,7 +50,7 @@ export const createMLJob = async ({
filter: [
{
term: {
'monitor.id': monitorId,
'monitor.id': lowerCaseMonitorId,
},
},
],
@ -56,11 +59,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;
}