use of org.graylog2.indexer.EventIndexTemplateProvider.EVENT_TEMPLATE_TYPE in project graylog2-server by Graylog2.
the class V20190705071400_AddEventIndexSetsMigration method setupEventsIndexSet.
private IndexSet setupEventsIndexSet(String indexSetTitle, String indexSetDescription, String indexPrefix) {
final Optional<IndexSetConfig> optionalIndexSetConfig = getEventsIndexSetConfig(indexPrefix);
if (optionalIndexSetConfig.isPresent()) {
return mongoIndexSetFactory.create(optionalIndexSetConfig.get());
}
final IndexSetConfig indexSetConfig = IndexSetConfig.builder().title(indexSetTitle).description(indexSetDescription).indexTemplateType(EVENT_TEMPLATE_TYPE).isWritable(true).isRegular(false).indexPrefix(indexPrefix).shards(elasticsearchConfiguration.getShards()).replicas(elasticsearchConfiguration.getReplicas()).rotationStrategyClass(TimeBasedRotationStrategy.class.getCanonicalName()).rotationStrategy(TimeBasedRotationStrategyConfig.create(Period.months(1), null)).retentionStrategyClass(DeletionRetentionStrategy.class.getCanonicalName()).retentionStrategy(DeletionRetentionStrategyConfig.create(12)).creationDate(ZonedDateTime.now(ZoneOffset.UTC)).indexAnalyzer(elasticsearchConfiguration.getAnalyzer()).indexTemplateName(indexPrefix + "-template").indexOptimizationMaxNumSegments(elasticsearchConfiguration.getIndexOptimizationMaxNumSegments()).indexOptimizationDisabled(elasticsearchConfiguration.isDisableIndexOptimization()).fieldTypeRefreshInterval(Duration.standardMinutes(1)).build();
try {
final Optional<IndexSetValidator.Violation> violation = indexSetValidator.validate(indexSetConfig);
if (violation.isPresent()) {
throw new RuntimeException(violation.get().message());
}
final IndexSetConfig savedIndexSet = indexSetService.save(indexSetConfig);
LOG.info("Successfully created events index-set <{}/{}>", savedIndexSet.id(), savedIndexSet.title());
return mongoIndexSetFactory.create(savedIndexSet);
} catch (DuplicateKeyException e) {
LOG.error("Couldn't create index-set <{}/{}>", indexSetTitle, indexPrefix);
throw new RuntimeException(e.getMessage());
}
}
use of org.graylog2.indexer.EventIndexTemplateProvider.EVENT_TEMPLATE_TYPE in project graylog2-server by Graylog2.
the class SearchesIT method determineAffectedIndicesWithRangesExcludeEvents.
@Test
public void determineAffectedIndicesWithRangesExcludeEvents() throws Exception {
final Set<IndexSet> eventIndexSets = Arrays.asList("gl-events", "gl-system-events").stream().map(prefix -> new TestIndexSet(indexSet.getConfig().toBuilder().indexPrefix(prefix).indexTemplateType(EVENT_TEMPLATE_TYPE).build())).collect(Collectors.toSet());
when(indexSetRegistry.getForIndices(anyCollection())).thenReturn(eventIndexSets);
final DateTime now = DateTime.now(DateTimeZone.UTC);
final MongoIndexRange indexRange0 = MongoIndexRange.create("gl-events_0", now, now.plusDays(1), now, 0);
final MongoIndexRange indexRange1 = MongoIndexRange.create("gl-system-events_2", now.plusDays(1), now.plusDays(2), now, 0);
final MongoIndexRange indexRange2 = MongoIndexRange.create("graylog_0", now, now.plusDays(1), now, 0);
final SortedSet<IndexRange> indices = ImmutableSortedSet.orderedBy(IndexRange.COMPARATOR).add(indexRange0).add(indexRange1).add(indexRange2).build();
when(indexRangeService.find(any(DateTime.class), any(DateTime.class))).thenReturn(indices);
final TimeRange absoluteRange = AbsoluteRange.create(now.minusDays(1), now.plusDays(1));
assertThat(searches.determineAffectedIndicesWithRanges(absoluteRange, null)).containsExactly(indexRange2);
}
Aggregations