use of org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange 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.plugin.indexer.searches.timeranges.AbsoluteRange in project graylog2-server by Graylog2.
the class SearchesTest method determineAffectedIndicesWithRangesDoesNotIncludesDeflectorTargetIfMissing.
@Test
public void determineAffectedIndicesWithRangesDoesNotIncludesDeflectorTargetIfMissing() throws Exception {
final DateTime now = DateTime.now(DateTimeZone.UTC);
final MongoIndexRange indexRange0 = MongoIndexRange.create("graylog_0", now, now.plusDays(1), now, 0);
final MongoIndexRange indexRange1 = MongoIndexRange.create("graylog_1", now.plusDays(1), now.plusDays(2), now, 0);
final SortedSet<IndexRange> indices = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR).add(indexRange0).add(indexRange1).build();
when(indexRangeService.find(any(DateTime.class), any(DateTime.class))).thenReturn(indices);
final TimeRange absoluteRange = AbsoluteRange.create(now.minusDays(1), now.plusDays(1));
final TimeRange keywordRange = KeywordRange.create("1 day ago");
final TimeRange relativeRange = RelativeRange.create(3600);
assertThat(searches.determineAffectedIndicesWithRanges(absoluteRange, null)).containsExactly(indexRange0, indexRange1);
assertThat(searches.determineAffectedIndicesWithRanges(keywordRange, null)).containsExactly(indexRange0, indexRange1);
assertThat(searches.determineAffectedIndicesWithRanges(relativeRange, null)).containsExactly(indexRange0, indexRange1);
}
use of org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange 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.plugin.indexer.searches.timeranges.AbsoluteRange in project graylog2-server by Graylog2.
the class SearchesTest method determineAffectedIndicesFilterIndexPrefix.
@Test
public void determineAffectedIndicesFilterIndexPrefix() throws Exception {
final DateTime now = DateTime.now(DateTimeZone.UTC);
final MongoIndexRange indexRange0 = MongoIndexRange.create("graylog_0", now, now.plusDays(1), now, 0);
final MongoIndexRange indexRange1 = MongoIndexRange.create("graylog_1", now.plusDays(1), now.plusDays(2), now, 0);
final MongoIndexRange b0 = MongoIndexRange.create("b_0", now.plusDays(1), now.plusDays(2), now, 0);
final MongoIndexRange b1 = MongoIndexRange.create("b_1", now.plusDays(1), now.plusDays(2), now, 0);
final SortedSet<IndexRange> indices = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR).add(indexRange0).add(indexRange1).add(b0).add(b1).build();
final Stream bStream = mock(Stream.class);
when(indexRangeService.find(any(DateTime.class), any(DateTime.class))).thenReturn(indices);
when(streamService.load(eq("123456789ABCDEF"))).thenReturn(bStream);
final IndexSet indexSet = mock(IndexSet.class);
when(indexSet.isManagedIndex(startsWith("b_"))).thenReturn(true);
when(bStream.getIndexSet()).thenReturn(indexSet);
final TimeRange absoluteRange = AbsoluteRange.create(now.minusDays(1), now.plusDays(1));
assertThat(searches.determineAffectedIndices(absoluteRange, "streams:123456789ABCDEF")).containsOnly(b0.indexName(), b1.indexName());
}
use of org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange 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);
}
Aggregations