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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations