Skip to content

Commit

Permalink
[ML] Edits following review
Browse files Browse the repository at this point in the history
  • Loading branch information
peteharverson committed Mar 4, 2020
1 parent 7bec588 commit 00ce82f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/models/job_validation/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ export const getMessages = () => {
time_field_invalid: {
status: 'ERROR',
text: i18n.translate('xpack.ml.models.jobValidation.messages.timeFieldInvalidMessage', {
defaultMessage: `{timeField} cannot be used as the time field because it's not a valid field of type 'date'.`,
defaultMessage: `{timeField} cannot be used as the time field because it is not a field of type 'date' or 'date_nanos'.`,
values: {
timeField: `'{{timeField}}'`,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { APICaller } from 'src/core/server';
import { ES_FIELD_TYPES } from '../../../../../../src/plugins/data/server';
import { parseInterval } from '../../../../../legacy/plugins/ml/common/util/parse_interval';
import { CombinedJob } from '../../../../../legacy/plugins/ml/public/application/jobs/new_job/common/job_creator/configs';
import { callWithRequestType } from '../../../../../legacy/plugins/ml/common/types/kibana';
// @ts-ignore
import { validateJobObject } from './validate_job_object';

Expand All @@ -27,12 +27,12 @@ const BUCKET_SPAN_COMPARE_FACTOR = 25;
const MIN_TIME_SPAN_MS = 7200000;
const MIN_TIME_SPAN_READABLE = '2 hours';

export async function isValidTimeField(callWithRequest: callWithRequestType, job: CombinedJob) {
export async function isValidTimeField(callAsCurrentUser: APICaller, job: CombinedJob) {
const index = job.datafeed_config.indices.join(',');
const timeField = job.data_description.time_field;

// check if time_field is of type 'date' or 'date_nanos'
const fieldCaps = await callWithRequest('fieldCaps', {
const fieldCaps = await callAsCurrentUser('fieldCaps', {
index,
fields: [timeField],
});
Expand All @@ -45,7 +45,7 @@ export async function isValidTimeField(callWithRequest: callWithRequestType, job
}

export async function validateTimeRange(
callWithRequest: callWithRequestType,
callAsCurrentUser: APICaller,
job: CombinedJob,
timeRange: TimeRange | undefined
) {
Expand All @@ -54,13 +54,13 @@ export async function validateTimeRange(
validateJobObject(job);

// check if time_field is a date type
if (!(await isValidTimeField(callWithRequest, job))) {
if (!(await isValidTimeField(callAsCurrentUser, job))) {
messages.push({
id: 'time_field_invalid',
timeField: job.data_description.time_field,
});
// if the time field is invalid, skip all other checks
return Promise.resolve(messages);
return messages;
}

// if there is no duration, do not run the estimate test
Expand All @@ -69,7 +69,7 @@ export async function validateTimeRange(
typeof timeRange.start === 'undefined' ||
typeof timeRange.end === 'undefined'
) {
return Promise.resolve(messages);
return messages;
}

// check if time range is after the Unix epoch start
Expand Down

0 comments on commit 00ce82f

Please sign in to comment.