Skip to content

Commit

Permalink
[ML] fix a fallback time range
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Mar 22, 2020
1 parent 35f441e commit c67dc3a
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import fs from 'fs';
import Boom from 'boom';
import numeral from '@elastic/numeral';
import { CallAPIOptions, APICaller, SavedObjectsClientContract } from 'kibana/server';
import moment from 'moment';
import { IndexPatternAttributes } from 'src/plugins/data/server';
import { merge } from 'lodash';
import { AnalysisLimits, CombinedJobWithStats } from '../../../common/types/anomaly_detection_jobs';
Expand Down Expand Up @@ -937,21 +938,22 @@ export class DataRecognizer {
}

/**
* Checks if the time range is provided and fallbacks
* to the last 3 month of data
* Provides a time range of the last 3 months of data
*/
async getFallbackTimeRange(
timeField: string,
query?: any
): Promise<{ start: number; end: number }> {
const fieldsService = fieldsServiceProvider(this.callAsCurrentUser);

const timeFieldRange = await fieldsService.getTimeFieldRange(
this.indexPatternName,
timeField,
query
);

return {
start: timeFieldRange.start.epoch,
start: timeFieldRange.end.epoch - moment.duration(3, 'months').asMilliseconds(),
end: timeFieldRange.end.epoch,
};
}
Expand Down

0 comments on commit c67dc3a

Please sign in to comment.