Search in sources :

Example 11 with Searches

use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.

the class SearchesIT method scrollReturnsMultipleChunksRespectingLimit.

@Test
public void scrollReturnsMultipleChunksRespectingLimit() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    when(indexSetRegistry.getForIndices(Collections.singleton("graylog_0"))).thenReturn(Collections.singleton(indexSet));
    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));
    final ScrollResult scrollResult = searches.scroll("*", range, 5, 0, Collections.singletonList("source"), null, 2);
    assertThat(scrollResult).isNotNull();
    assertThat(scrollResult.totalHits()).isEqualTo(10L);
    ScrollResult.ScrollChunk scrollChunk = scrollResult.nextChunk();
    assertThat(scrollChunk.isFirstChunk()).isTrue();
    final Set<ResultMessage> resultMessages = new HashSet<>(5);
    while (scrollChunk != null && !scrollChunk.getMessages().isEmpty()) {
        resultMessages.addAll(scrollChunk.getMessages());
        scrollChunk = scrollResult.nextChunk();
    }
    assertThat(resultMessages).hasSize(5);
}
Also used : AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ScrollResult(org.graylog2.indexer.results.ScrollResult) ResultMessage(org.graylog2.indexer.results.ResultMessage) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 12 with Searches

use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.

the class SearchesIT method searchReturnsCorrectTotalHits.

@Test
public void searchReturnsCorrectTotalHits() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    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));
    final SearchResult searchResult = searches.search("*", range, 5, 0, Sorting.DEFAULT);
    assertThat(searchResult).isNotNull();
    assertThat(searchResult.getResults()).hasSize(5);
    assertThat(searchResult.getTotalResults()).isEqualTo(10L);
    assertThat(searchResult.getFields()).doesNotContain("es_metadata_id", "es_metadata_version");
}
Also used : AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) SearchResult(org.graylog2.indexer.results.SearchResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 13 with Searches

use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.

the class SearchResourceTest method restrictTimeRangeReturnsGivenTimeRangeIfNoLimitHasBeenSet.

@Test
public void restrictTimeRangeReturnsGivenTimeRangeIfNoLimitHasBeenSet() {
    when(clusterConfigService.get(SearchesClusterConfig.class)).thenReturn(SearchesClusterConfig.createDefault().toBuilder().queryTimeRangeLimit(Period.ZERO).build());
    final SearchResource resource = new SearchResource(searches, clusterConfigService, decoratorProcessor, searchExecutor) {
    };
    final DateTime from = new DateTime(2015, 1, 15, 12, 0, DateTimeZone.UTC);
    final DateTime to = from.plusYears(1);
    final TimeRange timeRange = AbsoluteRange.create(from, to);
    final TimeRange restrictedTimeRange = resource.restrictTimeRange(timeRange);
    assertThat(restrictedTimeRange).isNotNull();
    assertThat(restrictedTimeRange.getFrom()).isEqualTo(from);
    assertThat(restrictedTimeRange.getTo()).isEqualTo(to);
}
Also used : TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 14 with Searches

use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.

the class SearchesIT method fieldStatsRecordsMetrics.

@Test
public void fieldStatsRecordsMetrics() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    FieldStatsResult result = searches.fieldStats("n", "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    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 : FieldStatsResult(org.graylog2.indexer.results.FieldStatsResult) Histogram(com.codahale.metrics.Histogram) Timer(com.codahale.metrics.Timer) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 15 with Searches

use of org.graylog2.indexer.searches.Searches in project graylog2-server by Graylog2.

the class SearchesIT method scrollReturnsResultWithSelectiveFields.

@Test
public void scrollReturnsResultWithSelectiveFields() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    when(indexSetRegistry.getForIndices(Collections.singleton("graylog_0"))).thenReturn(Collections.singleton(indexSet));
    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));
    final ScrollResult scrollResult = searches.scroll("*", range, 5, 0, Collections.singletonList("source"), null, NO_BATCHSIZE);
    assertThat(scrollResult).isNotNull();
    assertThat(scrollResult.getQueryHash()).isNotEmpty();
    assertThat(scrollResult.totalHits()).isEqualTo(10L);
    final ScrollResult.ScrollChunk firstChunk = scrollResult.nextChunk();
    assertThat(firstChunk).isNotNull();
    assertThat(firstChunk.getMessages()).hasSize(5);
    assertThat(firstChunk.isFirstChunk()).isTrue();
    assertThat(firstChunk.getFields()).containsExactly("source");
}
Also used : AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ScrollResult(org.graylog2.indexer.results.ScrollResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Aggregations

ZonedDateTime (java.time.ZonedDateTime)15 DateTime (org.joda.time.DateTime)15 Test (org.junit.Test)15 ElasticsearchBaseTest (org.graylog.testing.elasticsearch.ElasticsearchBaseTest)13 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)7 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 CountResult (org.graylog2.indexer.results.CountResult)4 SearchResult (org.graylog2.indexer.results.SearchResult)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Optional (java.util.Optional)3 Set (java.util.Set)3 FieldStatsResult (org.graylog2.indexer.results.FieldStatsResult)3 Maps (com.google.common.collect.Maps)2 Named (com.google.inject.name.Named)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2