Search in sources :

Example 26 with TimeGranularity

use of com.linkedin.thirdeye.api.TimeGranularity in project pinot by linkedin.

the class TestTimeRangeUtils method provideComputeTimeRanges.

@DataProvider(name = "computeTimeRanges")
public Object[][] provideComputeTimeRanges() {
    DateTime now = DateTime.now();
    DateTime yesterday = now.minusDays(1);
    List<Object[]> entries = new ArrayList<>();
    entries.add(new Object[] { null, yesterday, now, Collections.singletonList(Range.closedOpen(yesterday, now)) });
    entries.add(new Object[] { new TimeGranularity(1, TimeUnit.DAYS), yesterday, now, Collections.singletonList(Range.closedOpen(yesterday, now)) });
    entries.add(new Object[] { new TimeGranularity(6, TimeUnit.HOURS), yesterday, now, Arrays.asList(Range.closedOpen(yesterday, yesterday.plusHours(6)), Range.closedOpen(yesterday.plusHours(6), yesterday.plusHours(12)), Range.closedOpen(yesterday.plusHours(12), yesterday.plusHours(18)), Range.closedOpen(yesterday.plusHours(18), yesterday.plusHours(24))) });
    return entries.toArray(new Object[entries.size()][]);
}
Also used : ArrayList(java.util.ArrayList) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) DateTime(org.joda.time.DateTime) DataProvider(org.testng.annotations.DataProvider)

Example 27 with TimeGranularity

use of com.linkedin.thirdeye.api.TimeGranularity in project pinot by linkedin.

the class ThirdEyeUtils method getTimeSpecFromDatasetConfig.

public static TimeSpec getTimeSpecFromDatasetConfig(DatasetConfigDTO datasetConfig) {
    String timeFormat = datasetConfig.getTimeFormat();
    if (timeFormat.startsWith(TimeFormat.SIMPLE_DATE_FORMAT.toString())) {
        timeFormat = getSDFPatternFromTimeFormat(timeFormat);
    }
    TimeSpec timespec = new TimeSpec(datasetConfig.getTimeColumn(), new TimeGranularity(datasetConfig.getTimeDuration(), datasetConfig.getTimeUnit()), timeFormat);
    return timespec;
}
Also used : TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) TimeSpec(com.linkedin.thirdeye.api.TimeSpec)

Example 28 with TimeGranularity

use of com.linkedin.thirdeye.api.TimeGranularity in project pinot by linkedin.

the class TestDetectionJobSchedulerUtils method testGetNewEntriesForDetectionSchedulerMinuteLevel.

@Test
public void testGetNewEntriesForDetectionSchedulerMinuteLevel() throws Exception {
    DatasetConfigDTO datasetConfig = new DatasetConfigDTO();
    datasetConfig.setTimeColumn("Date");
    datasetConfig.setTimeUnit(TimeUnit.MINUTES);
    datasetConfig.setTimeDuration(5);
    DateTimeZone dateTimeZone = DateTimeZone.UTC;
    AnomalyFunctionDTO anomalyFunction = new AnomalyFunctionDTO();
    anomalyFunction.setFrequency(new TimeGranularity(15, TimeUnit.MINUTES));
    DateTimeFormatter dateTimeFormatter = DetectionJobSchedulerUtils.getDateTimeFormatterForDataset(datasetConfig, dateTimeZone);
    String currentDateTimeString = "201702140336";
    String currentDateTimeStringRounded = "201702140330";
    DateTime currentDateTime = minuteDateTimeFormatter.parseDateTime(currentDateTimeString);
    DateTime currentDateTimeRounded = dateTimeFormatter.parseDateTime(currentDateTimeStringRounded);
    DetectionStatusDTO lastEntryForFunction = null;
    // null last entry
    Map<String, Long> newEntries = DetectionJobSchedulerUtils.getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
    Assert.assertEquals(newEntries.size(), 1);
    Assert.assertEquals(newEntries.get(currentDateTimeStringRounded), new Long(currentDateTimeRounded.getMillis()));
    // last entry same as current time
    lastEntryForFunction = new DetectionStatusDTO();
    lastEntryForFunction.setDateToCheckInSDF(currentDateTimeStringRounded);
    lastEntryForFunction.setDateToCheckInMS(currentDateTimeRounded.getMillis());
    newEntries = DetectionJobSchedulerUtils.getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
    Assert.assertEquals(newEntries.size(), 0);
    // last entry 15 MINUTES before current time
    String lastEntryDateTimeString = "201702140315";
    DateTime lastEntryDateTime = dateTimeFormatter.parseDateTime(lastEntryDateTimeString);
    lastEntryForFunction = new DetectionStatusDTO();
    lastEntryForFunction.setDateToCheckInSDF(lastEntryDateTimeString);
    lastEntryForFunction.setDateToCheckInMS(lastEntryDateTime.getMillis());
    newEntries = DetectionJobSchedulerUtils.getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
    Assert.assertEquals(newEntries.size(), 1);
    Assert.assertEquals(newEntries.get(currentDateTimeStringRounded), new Long(currentDateTimeRounded.getMillis()));
    // last entry 45 MINUTES  before current time
    lastEntryDateTimeString = "201702140245";
    lastEntryDateTime = dateTimeFormatter.parseDateTime(lastEntryDateTimeString);
    lastEntryForFunction = new DetectionStatusDTO();
    lastEntryForFunction.setDateToCheckInSDF(lastEntryDateTimeString);
    lastEntryForFunction.setDateToCheckInMS(lastEntryDateTime.getMillis());
    newEntries = DetectionJobSchedulerUtils.getNewEntries(currentDateTime, lastEntryForFunction, anomalyFunction, datasetConfig, dateTimeZone);
    Assert.assertEquals(newEntries.size(), 3);
    Assert.assertNotNull(newEntries.get("201702140300"));
    Assert.assertNotNull(newEntries.get("201702140315"));
    Assert.assertNotNull(newEntries.get("201702140330"));
    Assert.assertEquals(newEntries.get(currentDateTimeStringRounded), new Long(currentDateTimeRounded.getMillis()));
}
Also used : DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) AnomalyFunctionDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO) DetectionStatusDTO(com.linkedin.thirdeye.datalayer.dto.DetectionStatusDTO) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 29 with TimeGranularity

use of com.linkedin.thirdeye.api.TimeGranularity in project pinot by linkedin.

the class TimeSeriesHandler method handle.

public TimeSeriesResponse handle(TimeSeriesRequest timeSeriesRequest) throws Exception {
    List<Range<DateTime>> timeranges = new ArrayList<>();
    TimeGranularity aggregationTimeGranularity = timeSeriesRequest.getAggregationTimeGranularity();
    // time ranges
    DateTime start = timeSeriesRequest.getStart();
    DateTime end = timeSeriesRequest.getEnd();
    if (timeSeriesRequest.isEndDateInclusive()) {
        // ThirdEyeRequest is exclusive endpoint, so increment by one bucket
        end = end.plus(aggregationTimeGranularity.toMillis());
    }
    timeranges = TimeRangeUtils.computeTimeRanges(aggregationTimeGranularity, start, end);
    // create request
    ThirdEyeRequest request = createThirdEyeRequest("timeseries", timeSeriesRequest, start, end);
    Future<ThirdEyeResponse> responseFuture = queryCache.getQueryResultAsync(request);
    // 5 minutes timeout
    ThirdEyeResponse response = responseFuture.get(5, TimeUnit.MINUTES);
    TimeSeriesResponseParser timeSeriesResponseParser = new TimeSeriesResponseParser(response, timeranges, timeSeriesRequest.getAggregationTimeGranularity(), timeSeriesRequest.getGroupByDimensions());
    List<TimeSeriesRow> rows = timeSeriesResponseParser.parseResponse();
    // compute the derived metrics
    computeDerivedMetrics(timeSeriesRequest, rows);
    return new TimeSeriesResponse(rows);
}
Also used : ArrayList(java.util.ArrayList) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) ThirdEyeResponse(com.linkedin.thirdeye.client.ThirdEyeResponse) Range(com.google.common.collect.Range) DateTime(org.joda.time.DateTime) ThirdEyeRequest(com.linkedin.thirdeye.client.ThirdEyeRequest)

Example 30 with TimeGranularity

use of com.linkedin.thirdeye.api.TimeGranularity in project pinot by linkedin.

the class Utils method resizeTimeGranularity.

/**
   * Given a duration (in millis), a time granularity, and the target number of chunk to divide the
   * duration, this method returns the time granularity that is able to divide the duration to a
   * number of chunks that is fewer than or equals to the target number.
   *
   * For example, if the duration is 25 hours, time granularity is HOURS, and target number is 12,
   * then the resized time granularity is 3_HOURS, which divide the duration to 9 chunks.
   *
   * @param duration the duration in milliseconds.
   * @param timeGranularityString time granularity in String format.
   * @param targetChunkNum the target number of chunks.
   * @return the resized time granularity in order to divide the duration to the number of chunks
   * that is smaller than or equals to the target chunk number.
   */
public static String resizeTimeGranularity(long duration, String timeGranularityString, int targetChunkNum) {
    TimeGranularity timeGranularity = Utils.getTimeGranularityFromString(timeGranularityString);
    long timeGranularityMillis = timeGranularity.toMillis();
    long chunkNum = duration / timeGranularityMillis;
    if (duration % timeGranularityMillis != 0) {
        ++chunkNum;
    }
    if (chunkNum > targetChunkNum) {
        long targetIntervalDuration = (long) Math.ceil((double) duration / (double) targetChunkNum);
        long unitTimeGranularityMillis = timeGranularity.getUnit().toMillis(1);
        int size = (int) Math.ceil((double) targetIntervalDuration / (double) unitTimeGranularityMillis);
        String newTimeGranularityString = size + "_" + timeGranularity.getUnit();
        return newTimeGranularityString;
    } else {
        return timeGranularityString;
    }
}
Also used : TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity)

Aggregations

TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)38 DateTime (org.joda.time.DateTime)19 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)13 ArrayList (java.util.ArrayList)13 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)9 DateTimeZone (org.joda.time.DateTimeZone)9 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)8 AnomalyFunctionDTO (com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO)7 Path (javax.ws.rs.Path)7 MetricTimeSeries (com.linkedin.thirdeye.api.MetricTimeSeries)6 ExecutionException (java.util.concurrent.ExecutionException)6 GET (javax.ws.rs.GET)5 MetricFunction (com.linkedin.thirdeye.client.MetricFunction)4 QueryCache (com.linkedin.thirdeye.client.cache.QueryCache)4 MergedAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO)4 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)4 HashMap (java.util.HashMap)4 TimeUnit (java.util.concurrent.TimeUnit)4 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)4 Test (org.testng.annotations.Test)4