[ML] Fixing issue with incorrect timezones in jobs list (#22714)

* [ML] Fixing issue with incorrect timezones in jobs list

* refactoring min and max calculation

* changes based on review

* changing TimeStamp to Timestamp
This commit is contained in:
James Gowdy 2018-09-05 17:16:13 +01:00 committed by GitHub
parent b7918690f4
commit 23ed2135bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 31 deletions

View file

@ -14,6 +14,8 @@ import {
} from '@elastic/eui';
import chrome from 'ui/chrome';
import moment from 'moment';
const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
import { mlJobService } from 'plugins/ml/services/job_service';
@ -21,22 +23,18 @@ function getLink(location, jobs) {
let from = 0;
let to = 0;
if (jobs.length === 1) {
from = jobs[0].earliestTimeStamp.string;
to = jobs[0].latestTimeStamp.string;
from = jobs[0].earliestTimestampMs;
to = jobs[0].latestTimestampMs;
} else {
const froms = jobs.map(j => j.earliestTimeStamp).sort((a, b) => a.unix > b.unix);
const tos = jobs.map(j => j.latestTimeStamp).sort((a, b) => a.unix < b.unix);
from = froms[0].string;
to = tos[0].string;
from = Math.min(...jobs.map(j => j.earliestTimestampMs));
to = Math.max(...jobs.map(j => j.latestTimestampMs));
}
// if either of the dates are empty, set them to undefined
// moment will convert undefined to now.
from = (from === '') ? undefined : from;
to = (to === '') ? undefined : to;
const fromString = moment(from).format(TIME_FORMAT);
const toString = moment(to).format(TIME_FORMAT);
const jobIds = jobs.map(j => j.id);
const url = mlJobService.createResultsUrl(jobIds, from, to, location);
const url = mlJobService.createResultsUrl(jobIds, fromString, toString, location);
return `${chrome.getBasePath()}/app/${url}`;
}

View file

@ -11,6 +11,7 @@ import React, {
} from 'react';
import { sortBy } from 'lodash';
import moment from 'moment';
import { toLocaleString } from '../../../../util/string_utils';
import { ResultLinks, actionsMenuContent } from '../job_actions';
@ -25,6 +26,7 @@ import {
const PAGE_SIZE = 10;
const PAGE_SIZE_OPTIONS = [10, 25, 50];
const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
export class JobsList extends Component {
constructor(props) {
@ -157,11 +159,13 @@ export class JobsList extends Component {
}, {
name: 'Latest timestamp',
truncateText: false,
field: 'latestTimeStampUnix',
field: 'latestTimeStampSortValue',
sortable: true,
render: (time, item) => (
<span className="euiTableCellContent__text">
{ item.latestTimeStamp.string }
{
(item.latestTimestampMs === undefined) ? '' : moment(item.latestTimestampMs).format(TIME_FORMAT)
}
</span>
)
}, {

View file

@ -240,7 +240,7 @@ export class JobsListView extends Component {
fullJobsList[job.id] = job.fullJob;
delete job.fullJob;
}
job.latestTimeStampUnix = job.latestTimeStamp.unix;
job.latestTimeStampSortValue = (job.latestTimeStampMs || 0);
return job;
});
const filteredJobsSummaryList = filterJobs(jobsSummaryList, this.state.filterClauses);

View file

@ -196,6 +196,6 @@ StartDatafeedModal.propTypes = {
};
function getLowestLatestTime(jobs) {
const times = jobs.map(j => j.latestTimeStamp.unix.valueOf());
const times = jobs.map(j => j.latestTimeStampSortValue);
return moment(Math.min(...times));
}

View file

@ -13,8 +13,6 @@ import { fillResultsWithTimeouts, isRequestTimeout } from './error_utils';
import moment from 'moment';
import { uniq } from 'lodash';
const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
export function jobsProvider(callWithRequest) {
const { forceDeleteDatafeed, getDatafeedIdsByJobId } = datafeedsProvider(callWithRequest);
@ -99,8 +97,8 @@ export function jobsProvider(callWithRequest) {
const jobs = fullJobsList.map((job) => {
const hasDatafeed = (typeof job.datafeed_config === 'object' && Object.keys(job.datafeed_config).length);
const {
earliest: earliestTimeStamp,
latest: latestTimeStamp } = earliestAndLatestTimeStamps(job.data_counts);
earliest: earliestTimestampMs,
latest: latestTimestampMs } = earliestAndLatestTimeStamps(job.data_counts);
const tempJob = {
id: job.job_id,
@ -112,8 +110,8 @@ export function jobsProvider(callWithRequest) {
hasDatafeed,
datafeedId: (hasDatafeed && job.datafeed_config.datafeed_id) ? job.datafeed_config.datafeed_id : '',
datafeedState: (hasDatafeed && job.datafeed_config.state) ? job.datafeed_config.state : '',
latestTimeStamp,
earliestTimeStamp,
latestTimestampMs,
earliestTimestampMs,
nodeName: (job.node) ? job.node.name : undefined,
};
if (jobIds.find(j => (j === tempJob.id))) {
@ -243,22 +241,16 @@ export function jobsProvider(callWithRequest) {
function earliestAndLatestTimeStamps(dataCounts) {
const obj = {
earliest: { string: '', unix: 0 },
latest: { string: '', unix: 0 },
earliest: undefined,
latest: undefined,
};
if (dataCounts.earliest_record_timestamp) {
const ts = moment(dataCounts.earliest_record_timestamp);
obj.earliest.string = ts.format(TIME_FORMAT);
obj.earliest.unix = ts.valueOf();
obj.earliest.moment = ts;
obj.earliest = moment(dataCounts.earliest_record_timestamp).valueOf();
}
if (dataCounts.latest_record_timestamp) {
const ts = moment(dataCounts.latest_record_timestamp);
obj.latest.string = ts.format(TIME_FORMAT);
obj.latest.unix = ts.valueOf();
obj.latest.moment = ts;
obj.latest = moment(dataCounts.latest_record_timestamp).valueOf();
}
return obj;