Skip to content

Commit

Permalink
[ML] Rename latestRecordTimestamp to adjustedBucketStartTime
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Jul 16, 2020
1 parent 7479cb8 commit dcce6b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 20 additions & 0 deletions x-pack/plugins/ml/common/util/job_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ import {
prefixDatafeedId,
getSafeAggregationName,
getLatestDataOrBucketTimestamp,
getEarliestDatafeedStartTime,
} from './job_utils';
import { CombinedJob, Job } from '../types/anomaly_detection_jobs';
import moment from 'moment';

describe('ML - job utils', () => {
describe('calculateDatafeedFrequencyDefaultSeconds', () => {
Expand Down Expand Up @@ -581,4 +583,22 @@ describe('ML - job utils', () => {
expect(getLatestDataOrBucketTimestamp(undefined, undefined)).toBe(undefined);
});
});

describe('getEarliestDatafeedStartTime', () => {
test('returns expected value when no gap in data at end of bucket processing', () => {
expect(getEarliestDatafeedStartTime(1549929594000, 1549928700000)).toBe(1549929594000);
});
test('returns expected value when there is a gap in data at end of bucket processing', () => {
expect(getEarliestDatafeedStartTime(1549929594000, 1562256600000)).toBe(1562256600000);
});
test('returns expected value when bucket span is provided', () => {
expect(
getEarliestDatafeedStartTime(1549929594000, 1562256600000, moment.duration(1, 'h'))
).toBe(1562260200000);
});

test('returns expected value when job has not run', () => {
expect(getLatestDataOrBucketTimestamp(undefined, undefined)).toBe(undefined);
});
});
});
6 changes: 3 additions & 3 deletions x-pack/plugins/ml/common/util/job_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,11 @@ export function getEarliestDatafeedStartTime(
bucketSpan?: Duration | null | undefined
): number | undefined {
if (latestRecordTimestamp !== undefined && latestBucketTimestamp !== undefined) {
// if bucket span is availble (e.g. 15m) add it to the latest bucket timestamp in ms
const latestBucketStartTime = bucketSpan
// if bucket span is available (e.g. 15m) add it to the latest bucket timestamp in ms
const adjustedBucketStartTime = bucketSpan
? moment(latestBucketTimestamp).add(bucketSpan).valueOf()
: latestBucketTimestamp;
return Math.max(latestRecordTimestamp, latestBucketStartTime);
return Math.max(latestRecordTimestamp, adjustedBucketStartTime);
} else {
return latestRecordTimestamp !== undefined ? latestRecordTimestamp : latestBucketTimestamp;
}
Expand Down

0 comments on commit dcce6b6

Please sign in to comment.