Search in sources :

Example 51 with Indices

use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.

the class IndexFieldTypePollerPeriodical method refreshFieldTypes.

private void refreshFieldTypes(Collection<IndexSetConfig> indexSetConfigs) {
    LOG.debug("Refreshing index field types for {} index sets.", indexSetConfigs.size());
    // this is the first time we run, or the index sets have changed, so we re-initialize the field types
    indexSetConfigs.forEach(indexSetConfig -> {
        final String indexSetId = indexSetConfig.id();
        final String indexSetTitle = indexSetConfig.title();
        try {
            final Set<IndexFieldTypesDTO> existingIndexTypes = ImmutableSet.copyOf(dbService.findForIndexSet(indexSetId));
            final IndexSet indexSet = mongoIndexSetFactory.create(indexSetConfig);
            // We check that we have the field types for all existing indices
            LOG.debug("Refreshing index field types for index set <{}/{}>", indexSetTitle, indexSetId);
            poller.poll(indexSet, existingIndexTypes).forEach(dbService::upsert);
            // Cleanup orphaned field type entries that haven't been removed by the event handler
            dbService.findForIndexSet(indexSetId).stream().filter(types -> !indices.exists(types.indexName())).forEach(types -> dbService.delete(types.id()));
        } finally {
            lastPoll.put(indexSetId, Instant.now());
        }
    });
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Duration(org.joda.time.Duration) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) IndicesDeletedEvent(org.graylog2.indexer.indices.events.IndicesDeletedEvent) Lifecycle(org.graylog2.plugin.lifecycles.Lifecycle) Indices(org.graylog2.indexer.indices.Indices) MongoIndexSet(org.graylog2.indexer.MongoIndexSet) IndexSetCreatedEvent(org.graylog2.indexer.indexset.events.IndexSetCreatedEvent) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Subscribe(com.google.common.eventbus.Subscribe) IndexSet(org.graylog2.indexer.IndexSet) Named(javax.inject.Named) LinkedHashSet(java.util.LinkedHashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Cluster(org.graylog2.indexer.cluster.Cluster) IndexSetDeletedEvent(org.graylog2.indexer.indexset.events.IndexSetDeletedEvent) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ServerStatus(org.graylog2.plugin.ServerStatus) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Periodical(org.graylog2.plugin.periodical.Periodical) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) MongoIndexSet(org.graylog2.indexer.MongoIndexSet) IndexSet(org.graylog2.indexer.IndexSet)

Example 52 with Indices

use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.

the class Cluster method elasticsearchStats.

public ElasticsearchStats elasticsearchStats() {
    final List<String> indices = Arrays.asList(indexSetRegistry.getIndexWildcards());
    final org.graylog2.system.stats.elasticsearch.ClusterStats clusterStats = clusterAdapter.clusterStats();
    final PendingTasksStats pendingTasksStats = clusterAdapter.pendingTasks();
    final ShardStats shardStats = clusterAdapter.shardStats(indices);
    final org.graylog2.system.stats.elasticsearch.ClusterHealth clusterHealth = org.graylog2.system.stats.elasticsearch.ClusterHealth.from(shardStats, pendingTasksStats);
    final HealthStatus healthStatus = clusterAdapter.health(indices).orElseThrow(() -> new IllegalStateException("Unable to retrieve cluster health."));
    return ElasticsearchStats.create(clusterStats.clusterName(), clusterStats.clusterVersion(), healthStatus, clusterHealth, clusterStats.nodesStats(), clusterStats.indicesStats());
}
Also used : ShardStats(org.graylog2.system.stats.elasticsearch.ShardStats) HealthStatus(org.graylog2.indexer.indices.HealthStatus)

Example 53 with Indices

use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.

the class Searches method search.

public SearchResult search(SearchesConfig config) {
    final Set<IndexRange> indexRanges = determineAffectedIndicesWithRanges(config.range(), config.filter());
    final Set<String> indices = extractIndexNamesFromIndexRanges(indexRanges);
    final SearchResult result = searchesAdapter.search(indices, indexRanges, config);
    recordEsMetrics(result.tookMs(), config.range());
    return result;
}
Also used : IndexRange(org.graylog2.indexer.ranges.IndexRange) SearchResult(org.graylog2.indexer.results.SearchResult)

Example 54 with Indices

use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.

the class RebuildIndexRangesJob method execute.

@Override
public void execute() {
    info("Recalculating index ranges.");
    // for each index set we know about
    final ListMultimap<IndexSet, String> indexSets = MultimapBuilder.hashKeys().arrayListValues().build();
    for (IndexSet indexSet : this.indexSets) {
        final String[] managedIndicesNames = indexSet.getManagedIndices();
        for (String name : managedIndicesNames) {
            indexSets.put(indexSet, name);
        }
    }
    if (indexSets.size() == 0) {
        info("No indices, nothing to calculate.");
        return;
    }
    indicesToCalculate = indexSets.values().size();
    Stopwatch sw = Stopwatch.createStarted();
    for (IndexSet indexSet : indexSets.keySet()) {
        LOG.info("Recalculating index ranges for index set {} ({}): {} indices affected.", indexSet.getConfig().title(), indexSet.getIndexWildcard(), indexSets.get(indexSet).size());
        for (String index : indexSets.get(indexSet)) {
            try {
                if (index.equals(indexSet.getActiveWriteIndex())) {
                    LOG.debug("{} is current write target, do not calculate index range for it", index);
                    final IndexRange emptyRange = indexRangeService.createUnknownRange(index);
                    try {
                        final IndexRange indexRange = indexRangeService.get(index);
                        if (indexRange.begin().getMillis() != 0 || indexRange.end().getMillis() != 0) {
                            LOG.info("Invalid date ranges for write index {}, resetting it.", index);
                            indexRangeService.save(emptyRange);
                        }
                    } catch (NotFoundException e) {
                        LOG.info("No index range found for write index {}, recreating it.", index);
                        indexRangeService.save(emptyRange);
                    }
                    indicesCalculated.incrementAndGet();
                    continue;
                }
            } catch (TooManyAliasesException e) {
                LOG.error("Multiple write alias targets found, this is a bug.");
                indicesCalculated.incrementAndGet();
                continue;
            }
            if (cancelRequested) {
                info("Stop requested. Not calculating next index range, not updating ranges.");
                sw.stop();
                return;
            }
            try {
                final IndexRange indexRange = indexRangeService.calculateRange(index);
                indexRangeService.save(indexRange);
                LOG.info("Created ranges for index {}: {}", index, indexRange);
            } catch (Exception e) {
                LOG.info("Could not calculate range of index [" + index + "]. Skipping.", e);
            } finally {
                indicesCalculated.incrementAndGet();
            }
        }
    }
    info("Done calculating index ranges for " + indicesToCalculate + " indices. Took " + sw.stop().elapsed(TimeUnit.MILLISECONDS) + "ms.");
}
Also used : Stopwatch(com.google.common.base.Stopwatch) NotFoundException(org.graylog2.database.NotFoundException) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) NotFoundException(org.graylog2.database.NotFoundException)

Example 55 with Indices

use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.

the class IndexSetCleanupJob method execute.

@Override
public void execute() {
    final IndexSetConfig config = indexSet.getConfig();
    final String[] managedIndices = indexSet.getManagedIndices();
    this.total = managedIndices.length;
    try {
        LOG.info("Deleting index template <{}> from Elasticsearch", config.indexTemplateName());
        indices.deleteIndexTemplate(indexSet);
    } catch (Exception e) {
        LOG.error("Unable to delete index template <{}>", config.indexTemplateName(), e);
    }
    for (String indexName : managedIndices) {
        if (cancel) {
            LOG.info("Cancel requested. Deleted <{}> of <{}> indices.", deleted, total);
            break;
        }
        try {
            LOG.info("Removing index range information for index: {}", indexName);
            indexRangeService.remove(indexName);
            LOG.info("Deleting index <{}> in index set <{}> ({})", indexName, config.id(), config.title());
            indices.delete(indexName);
            deleted.incrementAndGet();
        } catch (Exception e) {
            LOG.error("Unable to delete index <{}>", indexName, e);
        }
    }
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig)

Aggregations

IndexSet (org.graylog2.indexer.IndexSet)20 IndexRange (org.graylog2.indexer.ranges.IndexRange)19 Set (java.util.Set)18 Test (org.junit.Test)18 DateTime (org.joda.time.DateTime)17 Map (java.util.Map)16 Collectors (java.util.stream.Collectors)15 List (java.util.List)14 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)14 ZonedDateTime (java.time.ZonedDateTime)13 Inject (javax.inject.Inject)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 HashMap (java.util.HashMap)11 Indices (org.graylog2.indexer.indices.Indices)11 MongoIndexRange (org.graylog2.indexer.ranges.MongoIndexRange)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Optional (java.util.Optional)10 ImmutableSet (com.google.common.collect.ImmutableSet)9