Search in sources :

Example 11 with RotationStrategy

use of org.graylog2.plugin.indexer.rotation.RotationStrategy 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 12 with RotationStrategy

use of org.graylog2.plugin.indexer.rotation.RotationStrategy in project graylog2-server by Graylog2.

the class TimeBasedRotationStrategyTest method shouldRotateConcurrently.

@Test
public void shouldRotateConcurrently() throws Exception {
    final DateTime initialTime = new DateTime(2014, 1, 1, 1, 59, 59, 0, DateTimeZone.UTC);
    final Period period = Period.hours(1);
    final InstantMillisProvider clock = new InstantMillisProvider(initialTime);
    DateTimeUtils.setCurrentMillisProvider(clock);
    final IndexSet indexSet1 = mock(IndexSet.class);
    final IndexSet indexSet2 = mock(IndexSet.class);
    final IndexSetConfig indexSetConfig1 = mock(IndexSetConfig.class);
    final IndexSetConfig indexSetConfig2 = mock(IndexSetConfig.class);
    when(indexSetConfig1.id()).thenReturn("id1");
    when(indexSetConfig2.id()).thenReturn("id2");
    when(indexSet1.getConfig()).thenReturn(indexSetConfig1);
    when(indexSet2.getConfig()).thenReturn(indexSetConfig2);
    when(indexSetConfig1.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period, null));
    when(indexSetConfig2.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period, null));
    when(indices.indexCreationDate(anyString())).thenReturn(Optional.of(initialTime.minus(minutes(5))));
    // Should not rotate the initial index.
    when(indexSet1.getNewestIndex()).thenReturn("index1");
    rotationStrategy.rotate(indexSet1);
    verify(indexSet1, never()).cycle();
    reset(indexSet1);
    when(indexSet2.getNewestIndex()).thenReturn("index2");
    rotationStrategy.rotate(indexSet2);
    verify(indexSet2, never()).cycle();
    reset(indexSet2);
    clock.tick(seconds(2));
    // Crossed rotation period.
    when(indexSet1.getNewestIndex()).thenReturn("index1");
    when(indexSet1.getConfig()).thenReturn(indexSetConfig1);
    when(indexSetConfig1.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period, null));
    rotationStrategy.rotate(indexSet1);
    verify(indexSet1, times(1)).cycle();
    reset(indexSet1);
    when(indexSet2.getNewestIndex()).thenReturn("index2");
    when(indexSet2.getConfig()).thenReturn(indexSetConfig2);
    when(indexSetConfig2.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period, null));
    rotationStrategy.rotate(indexSet2);
    verify(indexSet2, times(1)).cycle();
    reset(indexSet2);
    clock.tick(seconds(2));
    // Did not cross rotation period.
    when(indexSet1.getNewestIndex()).thenReturn("index1");
    when(indexSet1.getConfig()).thenReturn(indexSetConfig1);
    when(indexSetConfig1.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period, null));
    rotationStrategy.rotate(indexSet1);
    verify(indexSet1, never()).cycle();
    reset(indexSet1);
    when(indexSet2.getNewestIndex()).thenReturn("index2");
    when(indexSet2.getConfig()).thenReturn(indexSetConfig2);
    when(indexSetConfig2.rotationStrategy()).thenReturn(TimeBasedRotationStrategyConfig.create(period, null));
    rotationStrategy.rotate(indexSet2);
    verify(indexSet2, never()).cycle();
    reset(indexSet2);
}
Also used : InstantMillisProvider(org.graylog2.plugin.InstantMillisProvider) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Period(org.joda.time.Period) DateTime(org.joda.time.DateTime) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 13 with RotationStrategy

use of org.graylog2.plugin.indexer.rotation.RotationStrategy in project graylog2-server by Graylog2.

the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigrationTest method upgradeWhenOneAlreadyHasStrategiesSet.

@Test
public void upgradeWhenOneAlreadyHasStrategiesSet() throws Exception {
    final String rotationStrategyClass = MessageCountRotationStrategy.class.getCanonicalName();
    final String retentionStrategyClass = DeletionRetentionStrategy.class.getCanonicalName();
    final RotationStrategyConfig rotationStrategy = MessageCountRotationStrategyConfig.createDefault();
    final RetentionStrategyConfig retentionStrategy = DeletionRetentionStrategyConfig.createDefault();
    final IndexSetConfig config1 = IndexSetConfig.builder().id("id-1").title("title-1").indexPrefix("prefix-1").shards(1).replicas(0).rotationStrategy(rotationStrategy).retentionStrategyClass(retentionStrategyClass).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 12, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-1").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
    final IndexSetConfig config2 = IndexSetConfig.builder().id("id-2").title("title-2").indexPrefix("prefix-2").shards(1).replicas(0).rotationStrategyClass(rotationStrategyClass).rotationStrategy(rotationStrategy).retentionStrategyClass(retentionStrategyClass).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 13, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-2").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
    when(clusterConfigService.get(IndexManagementConfig.class)).thenReturn(IndexManagementConfig.create(rotationStrategyClass, retentionStrategyClass));
    when(indexSetService.findAll()).thenReturn(Lists.newArrayList(config1, config2));
    migration.upgrade();
    verify(indexSetService).save(config1.toBuilder().rotationStrategyClass(rotationStrategyClass).build());
    verify(indexSetService, never()).save(config2);
    verify(clusterConfigService).write(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.create(Collections.singleton("id-1"), Collections.singleton("id-2"), "id-1"));
}
Also used : DeletionRetentionStrategyConfig(org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig) RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) MessageCountRotationStrategyConfig(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig) RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) Test(org.junit.Test)

Example 14 with RotationStrategy

use of org.graylog2.plugin.indexer.rotation.RotationStrategy in project graylog2-server by Graylog2.

the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigrationTest method upgradeDoeNotRunWhenAlreadyComplete.

@Test
public void upgradeDoeNotRunWhenAlreadyComplete() throws Exception {
    final String rotationStrategyClass = MessageCountRotationStrategy.class.getCanonicalName();
    final String retentionStrategyClass = DeletionRetentionStrategy.class.getCanonicalName();
    final RotationStrategyConfig rotationStrategy = MessageCountRotationStrategyConfig.createDefault();
    final RetentionStrategyConfig retentionStrategy = DeletionRetentionStrategyConfig.createDefault();
    final IndexSetConfig config1 = IndexSetConfig.builder().id("id-1").title("title-1").indexPrefix("prefix-1").shards(1).replicas(0).rotationStrategy(rotationStrategy).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 12, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-1").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
    final IndexSetConfig config2 = IndexSetConfig.builder().id("id-2").title("title-2").indexPrefix("prefix-2").shards(1).replicas(0).rotationStrategy(rotationStrategy).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 13, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-2").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
    when(clusterConfigService.get(IndexManagementConfig.class)).thenReturn(IndexManagementConfig.create(rotationStrategyClass, retentionStrategyClass));
    when(indexSetService.findAll()).thenReturn(Lists.newArrayList(config1, config2));
    when(clusterConfigService.get(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.class)).thenReturn(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.create(Collections.emptySet(), Collections.emptySet(), "id-1"));
    migration.upgrade();
    verify(indexSetService, never()).save(any(IndexSetConfig.class));
    verify(clusterConfigService, never()).write(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.class);
}
Also used : DeletionRetentionStrategyConfig(org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig) RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) MessageCountRotationStrategyConfig(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig) RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) Test(org.junit.Test)

Example 15 with RotationStrategy

use of org.graylog2.plugin.indexer.rotation.RotationStrategy in project graylog2-server by Graylog2.

the class V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigrationTest method upgrade.

@Test
public void upgrade() throws Exception {
    final String rotationStrategyClass = MessageCountRotationStrategy.class.getCanonicalName();
    final String retentionStrategyClass = DeletionRetentionStrategy.class.getCanonicalName();
    final RotationStrategyConfig rotationStrategy = MessageCountRotationStrategyConfig.createDefault();
    final RetentionStrategyConfig retentionStrategy = DeletionRetentionStrategyConfig.createDefault();
    final IndexSetConfig config1 = IndexSetConfig.builder().id("id-1").title("title-1").indexPrefix("prefix-1").shards(1).replicas(0).rotationStrategy(rotationStrategy).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 12, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-1").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
    final IndexSetConfig config2 = IndexSetConfig.builder().id("id-2").title("title-2").indexPrefix("prefix-2").shards(1).replicas(0).rotationStrategy(rotationStrategy).retentionStrategy(retentionStrategy).creationDate(ZonedDateTime.of(2016, 10, 10, 0, 0, 0, 0, ZoneOffset.UTC)).indexAnalyzer("standard").indexTemplateName("template-2").indexOptimizationMaxNumSegments(1).indexOptimizationDisabled(false).build();
    when(clusterConfigService.get(IndexManagementConfig.class)).thenReturn(IndexManagementConfig.create(rotationStrategyClass, retentionStrategyClass));
    when(indexSetService.findAll()).thenReturn(Lists.newArrayList(config1, config2));
    migration.upgrade();
    verify(indexSetService).save(config1.toBuilder().rotationStrategyClass(rotationStrategyClass).retentionStrategyClass(retentionStrategyClass).build());
    verify(indexSetService).save(config2.toBuilder().rotationStrategyClass(rotationStrategyClass).retentionStrategyClass(retentionStrategyClass).build());
    verify(clusterConfigService).write(V20161124104700_AddRetentionRotationAndDefaultFlagToIndexSetMigration.MigrationCompleted.create(ImmutableSet.of("id-1", "id-2"), Collections.emptySet(), "id-2"));
}
Also used : DeletionRetentionStrategyConfig(org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig) RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) MessageCountRotationStrategyConfig(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig) RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) Test(org.junit.Test)

Aggregations

IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)12 Test (org.junit.Test)12 RotationStrategyConfig (org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)9 RotationStrategy (org.graylog2.plugin.indexer.rotation.RotationStrategy)8 DeletionRetentionStrategyConfig (org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig)6 MessageCountRotationStrategyConfig (org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategyConfig)6 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)6 IndexSet (org.graylog2.indexer.IndexSet)3 IndexManagementConfig (org.graylog2.indexer.management.IndexManagementConfig)3 NullActivityWriter (org.graylog2.shared.system.activities.NullActivityWriter)3 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NotFoundException (javax.ws.rs.NotFoundException)2 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)2 DeletionRetentionStrategy (org.graylog2.indexer.retention.strategies.DeletionRetentionStrategy)2 DateTime (org.joda.time.DateTime)2 Timed (com.codahale.metrics.annotation.Timed)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 SchemaFactoryWrapper (com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper)1 DuplicateKeyException (com.mongodb.DuplicateKeyException)1 ApiOperation (io.swagger.annotations.ApiOperation)1