Search in sources :

Example 1 with HistogramResult

use of org.graylog2.indexer.results.HistogramResult in project graylog2-server by Graylog2.

the class SearchesTest method fieldHistogramRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void fieldHistogramRecordsMetrics() throws Exception {
    final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC));
    HistogramResult h = searches.fieldHistogram("*", "n", Searches.DateHistogramInterval.MINUTE, null, range, false);
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : HistogramResult(org.graylog2.indexer.results.HistogramResult) Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 2 with HistogramResult

use of org.graylog2.indexer.results.HistogramResult in project graylog2-server by Graylog2.

the class SearchesTest method histogramRecordsMetrics.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void histogramRecordsMetrics() throws Exception {
    final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC));
    HistogramResult h = searches.histogram("*", Searches.DateHistogramInterval.MINUTE, range);
    assertThat(metricRegistry.getTimers()).containsKey(REQUEST_TIMER_NAME);
    assertThat(metricRegistry.getHistograms()).containsKey(RANGES_HISTOGRAM_NAME);
    Timer timer = metricRegistry.timer(REQUEST_TIMER_NAME);
    assertThat(timer.getCount()).isEqualTo(1L);
    Histogram histogram = metricRegistry.histogram(RANGES_HISTOGRAM_NAME);
    assertThat(histogram.getCount()).isEqualTo(1L);
    assertThat(histogram.getSnapshot().getValues()).containsExactly(86400L);
}
Also used : HistogramResult(org.graylog2.indexer.results.HistogramResult) Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 3 with HistogramResult

use of org.graylog2.indexer.results.HistogramResult in project graylog2-server by Graylog2.

the class SearchesTest method testHistogram.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
@SuppressWarnings("unchecked")
public void testHistogram() throws Exception {
    final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC).withZone(UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC).withZone(UTC));
    HistogramResult h = searches.histogram("*", Searches.DateHistogramInterval.HOUR, range);
    assertThat(h.getInterval()).isEqualTo(Searches.DateHistogramInterval.HOUR);
    assertThat(h.getHistogramBoundaries()).isEqualTo(range);
    assertThat(h.getResults()).hasSize(5).containsEntry(new DateTime(2015, 1, 1, 1, 0, UTC).getMillis() / 1000L, 2L).containsEntry(new DateTime(2015, 1, 1, 2, 0, UTC).getMillis() / 1000L, 2L).containsEntry(new DateTime(2015, 1, 1, 3, 0, UTC).getMillis() / 1000L, 2L).containsEntry(new DateTime(2015, 1, 1, 4, 0, UTC).getMillis() / 1000L, 2L).containsEntry(new DateTime(2015, 1, 1, 5, 0, UTC).getMillis() / 1000L, 2L);
}
Also used : HistogramResult(org.graylog2.indexer.results.HistogramResult) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 4 with HistogramResult

use of org.graylog2.indexer.results.HistogramResult in project graylog2-server by Graylog2.

the class Searches method fieldHistogram.

public HistogramResult fieldHistogram(String query, String field, DateHistogramInterval interval, String filter, TimeRange range, boolean includeCardinality) throws FieldTypeException {
    final DateHistogramBuilder dateHistogramBuilder = AggregationBuilders.dateHistogram(AGG_HISTOGRAM).field("timestamp").subAggregation(AggregationBuilders.stats(AGG_STATS).field(field)).interval(interval.toESInterval());
    if (includeCardinality) {
        dateHistogramBuilder.subAggregation(AggregationBuilders.cardinality(AGG_CARDINALITY).field(field));
    }
    FilterAggregationBuilder builder = AggregationBuilders.filter(AGG_FILTER).subAggregation(dateHistogramBuilder).filter(standardAggregationFilters(range, filter));
    QueryStringQueryBuilder qs = queryStringQuery(query);
    qs.allowLeadingWildcard(configuration.isAllowLeadingWildcardSearches());
    SearchRequestBuilder srb = c.prepareSearch();
    final Set<String> affectedIndices = determineAffectedIndices(range, filter);
    srb.setIndices(affectedIndices.toArray(new String[affectedIndices.size()]));
    srb.setQuery(qs);
    srb.addAggregation(builder);
    SearchResponse r;
    final SearchRequest request = srb.request();
    try {
        r = c.search(request).actionGet();
    } catch (org.elasticsearch.action.search.SearchPhaseExecutionException e) {
        throw new FieldTypeException(e);
    }
    checkForFailedShards(r);
    recordEsMetrics(r, range);
    final Filter f = r.getAggregations().get(AGG_FILTER);
    return new FieldHistogramResult(f.getAggregations().get(AGG_HISTOGRAM), query, request.source(), interval, r.getTook());
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) Filter(org.elasticsearch.search.aggregations.bucket.filter.Filter) QueryStringQueryBuilder(org.elasticsearch.index.query.QueryStringQueryBuilder) FieldHistogramResult(org.graylog2.indexer.results.FieldHistogramResult) DateHistogramBuilder(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramBuilder)

Example 5 with HistogramResult

use of org.graylog2.indexer.results.HistogramResult in project graylog2-server by Graylog2.

the class SearchResultChartWidgetStrategy method compute.

@Override
public ComputationResult compute() {
    String filter = null;
    if (!isNullOrEmpty(streamId)) {
        filter = "streams:" + streamId;
    }
    HistogramResult histogram = searches.histogram(query, interval, filter, this.timeRange);
    return new ComputationResult(histogram.getResults(), histogram.took().millis(), histogram.getHistogramBoundaries());
}
Also used : HistogramResult(org.graylog2.indexer.results.HistogramResult) ComputationResult(org.graylog2.plugin.dashboards.widgets.ComputationResult)

Aggregations

HistogramResult (org.graylog2.indexer.results.HistogramResult)7 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)6 DateTime (org.joda.time.DateTime)6 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 ZonedDateTime (java.time.ZonedDateTime)5 Test (org.junit.Test)5 Histogram (com.codahale.metrics.Histogram)2 Timer (com.codahale.metrics.Timer)2 Map (java.util.Map)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)2 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 QueryStringQueryBuilder (org.elasticsearch.index.query.QueryStringQueryBuilder)2 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)2 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)2 ComputationResult (org.graylog2.plugin.dashboards.widgets.ComputationResult)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 DateHistogramBuilder (org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramBuilder)1 IndexRange (org.graylog2.indexer.ranges.IndexRange)1