Search in sources :

Example 6 with Searches

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

the class SearchesIT method testCountWithFilter.

@Test
public void testCountWithFilter() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    final IndexSetConfig indexSetConfig = IndexSetConfig.builder().id("id").title("title").indexPrefix("prefix").shards(1).replicas(0).rotationStrategy(MessageCountRotationStrategyConfig.createDefault()).retentionStrategyClass(DeletionRetentionStrategy.class.getCanonicalName()).retentionStrategy(DeletionRetentionStrategyConfig.createDefault()).creationDate(ZonedDateTime.of(2017, 5, 24, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
    final IndexSet indexSet = new TestIndexSet(indexSetConfig);
    final Stream stream = new FakeStream("test") {

        @Override
        public IndexSet getIndexSet() {
            return indexSet;
        }
    };
    when(streamService.load(STREAM_ID)).thenReturn(stream);
    CountResult result = searches.count("*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)), "streams:" + STREAM_ID);
    assertThat(result.count()).isEqualTo(5L);
}
Also used : TestIndexSet(org.graylog2.indexer.TestIndexSet) FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) FakeStream(org.graylog2.buffers.processors.fakestreams.FakeStream) Stream(org.graylog2.plugin.streams.Stream) CountResult(org.graylog2.indexer.results.CountResult) IndexSet(org.graylog2.indexer.IndexSet) TestIndexSet(org.graylog2.indexer.TestIndexSet) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 7 with Searches

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

the class SearchesIT method testCountWithInvalidFilter.

@Test
public void testCountWithInvalidFilter() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    CountResult result = searches.count("*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)), "foobar-not-a-filter");
    assertThat(result.count()).isEqualTo(0L);
}
Also used : CountResult(org.graylog2.indexer.results.CountResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 8 with Searches

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

the class SearchesIT method testCountWithoutFilter.

@Test
public void testCountWithoutFilter() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    CountResult result = searches.count("*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(result.count()).isEqualTo(10L);
}
Also used : CountResult(org.graylog2.indexer.results.CountResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 9 with Searches

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

the class SearchesIT method scrollReturnsMultipleChunksRespectingBatchSize.

@Test
public void scrollReturnsMultipleChunksRespectingBatchSize() 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, -1, 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()) {
        assertThat(scrollChunk.getMessages()).hasSize(2);
        assertThat(scrollChunk.getFields()).containsExactly("source");
        resultMessages.addAll(scrollChunk.getMessages());
        scrollChunk = scrollResult.nextChunk();
    }
    assertThat(resultMessages).hasSize(10);
}
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 10 with Searches

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

the class SearchesIT method countRecordsMetrics.

@Test
public void countRecordsMetrics() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    CountResult result = searches.count("*", 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);
}
Also used : Timer(com.codahale.metrics.Timer) CountResult(org.graylog2.indexer.results.CountResult) 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