Search in sources :

Example 1 with DateRangeBucket

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

the class PivotAggregationSearch method getAggregationQuery.

/**
 * Returns the query to compute the aggregation.
 *
 * @param parameters processor parameters
 * @param searchWithinMs processor search within period. Used to build the date range buckets
 * @param executeEveryMs
 * @return aggregation query
 */
private Query getAggregationQuery(AggregationEventProcessorParameters parameters, long searchWithinMs, long executeEveryMs) {
    final Pivot.Builder pivotBuilder = Pivot.builder().id(PIVOT_ID).rollup(true);
    final ImmutableList<SeriesSpec> series = config.series().stream().map(entry -> entry.function().toSeriesSpec(metricName(entry), entry.field().orElse(null))).collect(ImmutableList.toImmutableList());
    if (!series.isEmpty()) {
        pivotBuilder.series(series);
    }
    // Wrap every aggregation with date range buckets of the searchWithin time range.
    // If the aggregation is configured to be using a sliding window (searchWithin > executeEveryMs)
    // the time ranges will overlap.
    // This allows us to run aggregations over larger time ranges than the searchWithin time.
    // The results will be received in time buckets of the searchWithin time size.
    final DateRangeBucket dateRangeBucket = buildDateRangeBuckets(parameters.timerange(), searchWithinMs, executeEveryMs);
    final List<BucketSpec> groupBy = new ArrayList<>();
    // The first bucket must be the date range!
    groupBy.add(dateRangeBucket);
    if (!config.groupBy().isEmpty()) {
        // Then we add the configured groups
        groupBy.addAll(config.groupBy().stream().map(field -> Values.builder().limit(Integer.MAX_VALUE).field(field).build()).collect(Collectors.toList()));
    }
    // We always have row groups because of the date range buckets
    pivotBuilder.rowGroups(groupBy);
    final Set<SearchType> searchTypes = Collections.singleton(pivotBuilder.build());
    final Query.Builder queryBuilder = Query.builder().id(QUERY_ID).searchTypes(searchTypes).query(ElasticsearchQueryString.of(config.query())).timerange(parameters.timerange());
    final Set<String> streams = getStreams(parameters);
    if (!streams.isEmpty()) {
        queryBuilder.filter(filteringForStreamIds(streams));
    }
    return queryBuilder.build();
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Assisted(com.google.inject.assistedinject.Assisted) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) BucketSpec(org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec) SeriesSpec(org.graylog.plugins.views.search.searchtypes.pivot.SeriesSpec) Locale(java.util.Locale) EventDefinition(org.graylog.events.processor.EventDefinition) EventProcessorException(org.graylog.events.processor.EventProcessorException) Pivot(org.graylog.plugins.views.search.searchtypes.pivot.Pivot) Values(org.graylog.plugins.views.search.searchtypes.pivot.buckets.Values) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Collectors.toSet(java.util.stream.Collectors.toSet) PermittedStreams(org.graylog.plugins.views.search.rest.PermittedStreams) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Collectors(java.util.stream.Collectors) MoreSearch(org.graylog.events.search.MoreSearch) List(java.util.List) Stream(org.graylog2.plugin.streams.Stream) Filter(org.graylog.plugins.views.search.Filter) Count(org.graylog.plugins.views.search.searchtypes.pivot.series.Count) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) QueryError(org.graylog.plugins.views.search.errors.QueryError) QueryEngine(org.graylog.plugins.views.search.engine.QueryEngine) Query(org.graylog.plugins.views.search.Query) PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) SearchJobService(org.graylog.plugins.views.search.db.SearchJobService) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) DateRangeBucket(org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRangeBucket) ArrayList(java.util.ArrayList) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) Inject(javax.inject.Inject) EventsConfigurationProvider(org.graylog.events.configuration.EventsConfigurationProvider) OrFilter(org.graylog.plugins.views.search.filter.OrFilter) ImmutableList(com.google.common.collect.ImmutableList) SearchType(org.graylog.plugins.views.search.SearchType) EmptyParameterError(org.graylog.plugins.views.search.errors.EmptyParameterError) Search(org.graylog.plugins.views.search.Search) QueryResult(org.graylog.plugins.views.search.QueryResult) SearchJob(org.graylog.plugins.views.search.SearchJob) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) DateTime(org.joda.time.DateTime) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) DateRange(org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRange) SearchError(org.graylog.plugins.views.search.errors.SearchError) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) Query(org.graylog.plugins.views.search.Query) DateRangeBucket(org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRangeBucket) ArrayList(java.util.ArrayList) SeriesSpec(org.graylog.plugins.views.search.searchtypes.pivot.SeriesSpec) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) BucketSpec(org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec) Pivot(org.graylog.plugins.views.search.searchtypes.pivot.Pivot) SearchType(org.graylog.plugins.views.search.SearchType)

Example 2 with DateRangeBucket

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

the class PivotAggregationSearchTest method testDateRangeBucketWithCatchUpTumblingWindows.

@Test
public void testDateRangeBucketWithCatchUpTumblingWindows() {
    final long processingWindowSize = Duration.standardSeconds(60).getMillis();
    final long processingHopSize = Duration.standardSeconds(60).getMillis();
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final DateTime from = now;
    // We are 3 full processingWindows behind
    final DateTime to = now.plusMillis((int) processingWindowSize * 3);
    TimeRange timeRange = AbsoluteRange.create(from, to);
    final DateRangeBucket rangeBucket = PivotAggregationSearch.buildDateRangeBuckets(timeRange, processingWindowSize, processingHopSize);
    assertThat(rangeBucket.ranges()).containsExactly(DateRange.create(from.plusMillis((int) (processingWindowSize * 0)), from.plusMillis((int) (processingWindowSize * 1))), DateRange.create(from.plusMillis((int) (processingWindowSize * 1)), from.plusMillis((int) (processingWindowSize * 2))), DateRange.create(from.plusMillis((int) (processingWindowSize * 2)), from.plusMillis((int) (processingWindowSize * 3))));
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DateRangeBucket(org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRangeBucket) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with DateRangeBucket

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

the class PivotAggregationSearchTest method testDateRangeBucketWithOneTumblingWindow.

@Test
public void testDateRangeBucketWithOneTumblingWindow() {
    final long processingWindowSize = Duration.standardSeconds(60).getMillis();
    final long processingHopSize = Duration.standardSeconds(60).getMillis();
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final DateTime from = now;
    final DateTime to = now.plusMillis((int) processingWindowSize);
    TimeRange timeRange = AbsoluteRange.create(from, to);
    final DateRangeBucket rangeBucket = PivotAggregationSearch.buildDateRangeBuckets(timeRange, processingWindowSize, processingHopSize);
    assertThat(rangeBucket.ranges()).containsExactly(DateRange.create(from, to));
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DateRangeBucket(org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRangeBucket) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 4 with DateRangeBucket

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

the class PivotAggregationSearchTest method testDateRangeBucketWithCatchUpSlidingWindows.

@Test
public void testDateRangeBucketWithCatchUpSlidingWindows() {
    final int processingWindowSizeSec = 120;
    final int processingHopSizeSec = 60;
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final DateTime from = now;
    // We are 3 full processingWindows behind
    final DateTime to = now.plusSeconds(processingWindowSizeSec * 3);
    TimeRange timeRange = AbsoluteRange.create(from, to);
    final DateRangeBucket rangeBucket = PivotAggregationSearch.buildDateRangeBuckets(timeRange, processingWindowSizeSec * 1000, processingHopSizeSec * 1000);
    assertThat(rangeBucket.ranges()).containsExactly(DateRange.create(from.plusSeconds(processingHopSizeSec * 0), from.plusSeconds(processingWindowSizeSec)), DateRange.create(from.plusSeconds(processingHopSizeSec * 1), from.plusSeconds(processingHopSizeSec * 1).plusSeconds(processingWindowSizeSec)), DateRange.create(from.plusSeconds(processingHopSizeSec * 2), from.plusSeconds(processingHopSizeSec * 2).plusSeconds(processingWindowSizeSec)), DateRange.create(from.plusSeconds(processingHopSizeSec * 3), from.plusSeconds(processingHopSizeSec * 3).plusSeconds(processingWindowSizeSec)), DateRange.create(from.plusSeconds(processingHopSizeSec * 4), to));
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DateRangeBucket(org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRangeBucket) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 5 with DateRangeBucket

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

the class PivotAggregationSearchTest method testDateRangeBucketWithSlidingWindow.

@Test
public void testDateRangeBucketWithSlidingWindow() {
    final long processingWindowSize = Duration.standardSeconds(3600).getMillis();
    final long processingHopSize = Duration.standardSeconds(60).getMillis();
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final DateTime from = now;
    final DateTime to = now.plusMillis((int) processingWindowSize);
    TimeRange timeRange = AbsoluteRange.create(from, to);
    final DateRangeBucket rangeBucket = PivotAggregationSearch.buildDateRangeBuckets(timeRange, processingWindowSize, processingHopSize);
    assertThat(rangeBucket.ranges()).containsExactly(DateRange.create(from, to));
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DateRangeBucket(org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRangeBucket) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DateRangeBucket (org.graylog.plugins.views.search.searchtypes.pivot.buckets.DateRangeBucket)5 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)5 DateTime (org.joda.time.DateTime)5 Test (org.junit.Test)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 Assisted (com.google.inject.assistedinject.Assisted)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Locale (java.util.Locale)1 Set (java.util.Set)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors (java.util.stream.Collectors)1