Search in sources :

Example 1 with DateRange

use of org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRange in project graylog2-server by Graylog2.

the class PivotAggregationSearch method buildDateRangeBuckets.

@VisibleForTesting
static DateRangeBucket buildDateRangeBuckets(TimeRange timeRange, long searchWithinMs, long executeEveryMs) {
    final ImmutableList.Builder<DateRange> ranges = ImmutableList.builder();
    DateTime from = timeRange.getFrom();
    DateTime to;
    do {
        // The smallest configurable unit is 1 sec.
        // By dividing it before casting we avoid a potential int overflow
        to = from.plusSeconds((int) (searchWithinMs / 1000));
        ranges.add(DateRange.builder().from(from).to(to).build());
        from = from.plusSeconds((int) executeEveryMs / 1000);
    } while (to.isBefore(timeRange.getTo()));
    return DateRangeBucket.builder().field("timestamp").ranges(ranges.build()).build();
}
Also used : DateRange(org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRange) ImmutableList(com.google.common.collect.ImmutableList) DateTime(org.joda.time.DateTime) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 DateRange (org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRange)1 DateTime (org.joda.time.DateTime)1