Search in sources :

Example 1 with IndexRangeStats

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

the class IndicesTest method testTimestampStatsOfIndexWithEmptyIndex.

@Test
@UsingDataSet(locations = "IndicesTest-EmptyIndex.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testTimestampStatsOfIndexWithEmptyIndex() throws Exception {
    IndexRangeStats stats = indices.indexRangeStatsOfIndex(INDEX_NAME);
    assertThat(stats.min()).isEqualTo(new DateTime(0L, DateTimeZone.UTC));
    assertThat(stats.max()).isEqualTo(new DateTime(0L, DateTimeZone.UTC));
}
Also used : IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 2 with IndexRangeStats

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

the class IndicesTest method testTimestampStatsOfIndex.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testTimestampStatsOfIndex() throws Exception {
    IndexRangeStats stats = indices.indexRangeStatsOfIndex(INDEX_NAME);
    assertThat(stats.min()).isEqualTo(new DateTime(2015, 1, 1, 1, 0, DateTimeZone.UTC));
    assertThat(stats.max()).isEqualTo(new DateTime(2015, 1, 1, 5, 0, DateTimeZone.UTC));
}
Also used : IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 3 with IndexRangeStats

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

the class IndicesIT method indexRangeStatsOfIndexReturnsMinMaxTimestampsForGivenIndex.

@ContainerMatrixTest
public void indexRangeStatsOfIndexReturnsMinMaxTimestampsForGivenIndex() {
    importFixture("org/graylog2/indexer/indices/IndicesIT.json");
    IndexRangeStats stats = indices.indexRangeStatsOfIndex(INDEX_NAME);
    assertThat(stats.min()).isEqualTo(new DateTime(2015, 1, 1, 1, 0, DateTimeZone.UTC));
    assertThat(stats.max()).isEqualTo(new DateTime(2015, 1, 1, 5, 0, DateTimeZone.UTC));
}
Also used : IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ContainerMatrixTest(org.graylog.testing.containermatrix.annotations.ContainerMatrixTest)

Example 4 with IndexRangeStats

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

the class IndicesIT method indexRangeStatsWorksForEmptyIndex.

@ContainerMatrixTest
public void indexRangeStatsWorksForEmptyIndex() {
    final String indexName = createRandomIndex("indices_it_");
    IndexRangeStats stats = indices.indexRangeStatsOfIndex(indexName);
    assertThat(stats.min()).isEqualTo(new DateTime(0L, DateTimeZone.UTC));
    assertThat(stats.max()).isEqualTo(new DateTime(0L, DateTimeZone.UTC));
}
Also used : IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ContainerMatrixTest(org.graylog.testing.containermatrix.annotations.ContainerMatrixTest)

Example 5 with IndexRangeStats

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

the class MongoIndexRangeService method calculateRange.

@Override
public IndexRange calculateRange(String index) {
    checkIfHealthy(indices.waitForRecovery(index), (status) -> new RuntimeException("Unable to calculate range for index <" + index + ">, index is unhealthy: " + status));
    final DateTime now = DateTime.now(DateTimeZone.UTC);
    final Stopwatch sw = Stopwatch.createStarted();
    final IndexRangeStats stats = indices.indexRangeStatsOfIndex(index);
    final int duration = Ints.saturatedCast(sw.stop().elapsed(TimeUnit.MILLISECONDS));
    LOG.info("Calculated range of [{}] in [{}ms].", index, duration);
    return MongoIndexRange.create(index, stats.min(), stats.max(), now, duration, stats.streamIds());
}
Also used : Stopwatch(com.google.common.base.Stopwatch) IndexRangeStats(org.graylog2.indexer.searches.IndexRangeStats) DateTime(org.joda.time.DateTime)

Aggregations

DateTime (org.joda.time.DateTime)7 IndexRangeStats (org.graylog2.indexer.searches.IndexRangeStats)5 ZonedDateTime (java.time.ZonedDateTime)4 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 ContainerMatrixTest (org.graylog.testing.containermatrix.annotations.ContainerMatrixTest)2 IndexNotFoundException (org.graylog2.indexer.IndexNotFoundException)2 Test (org.junit.Test)2 Stopwatch (com.google.common.base.Stopwatch)1 Search (io.searchbox.core.Search)1 SearchResult (io.searchbox.core.SearchResult)1 FilterAggregation (io.searchbox.core.search.aggregation.FilterAggregation)1 MaxAggregation (io.searchbox.core.search.aggregation.MaxAggregation)1 MinAggregation (io.searchbox.core.search.aggregation.MinAggregation)1 TermsAggregation (io.searchbox.core.search.aggregation.TermsAggregation)1 IOException (java.io.IOException)1 FilterAggregationBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)1 SearchSourceBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder)1 FieldSortBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.sort.FieldSortBuilder)1 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)1 SearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse)1