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

[Uptime] Convert anomaly Jobs name to lowercase to comply with API restriction #62293

Merged
merged 2 commits into from
Apr 2, 2020
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

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