Search in sources :

Example 1 with IndexFailure

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

the class Messages method propagateFailure.

private void propagateFailure(BulkItemResponse[] items, List<Map.Entry<IndexSet, Message>> messageList, String errorMessage) {
    final List<IndexFailure> indexFailures = new LinkedList<>();
    for (BulkItemResponse item : items) {
        if (item.isFailed()) {
            LOG.trace("Failed to index message: {}", item.getFailureMessage());
            // Write failure to index_failures.
            final BulkItemResponse.Failure f = item.getFailure();
            final Map.Entry<IndexSet, Message> messageEntry = messageList.get(item.getItemId());
            final Map<String, Object> doc = ImmutableMap.<String, Object>builder().put("letter_id", item.getId()).put("index", f.getIndex()).put("type", f.getType()).put("message", f.getMessage()).put("timestamp", messageEntry.getValue().getTimestamp()).build();
            indexFailures.add(new IndexFailureImpl(doc));
        }
    }
    LOG.error("Failed to index [{}] messages. Please check the index error log in your web interface for the reason. Error: {}", indexFailures.size(), errorMessage);
    try {
        // TODO: Magic number
        indexFailureQueue.offer(indexFailures, 25, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        LOG.warn("Couldn't save index failures.", e);
    }
}
Also used : IndexFailureImpl(org.graylog2.indexer.IndexFailureImpl) ResultMessage(org.graylog2.indexer.results.ResultMessage) Message(org.graylog2.plugin.Message) IndexFailure(org.graylog2.indexer.IndexFailure) BulkItemResponse(org.elasticsearch.action.bulk.BulkItemResponse) LinkedList(java.util.LinkedList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) IndexSet(org.graylog2.indexer.IndexSet)

Example 2 with IndexFailure

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

the class FailuresResource method single.

@GET
@Timed
@ApiOperation(value = "Get a list of failed index operations.")
@RequiresPermissions(RestPermissions.INDICES_FAILURES)
@Produces(MediaType.APPLICATION_JSON)
public Map<String, Object> single(@ApiParam(name = "limit", value = "Limit", required = true) @QueryParam("limit") @Min(0) int limit, @ApiParam(name = "offset", value = "Offset", required = true) @QueryParam("offset") @Min(0) int offset) {
    final List<IndexFailure> indexFailures = indexFailureService.all(limit, offset);
    final List<Map<String, Object>> failures = new ArrayList<>(indexFailures.size());
    for (IndexFailure failure : indexFailures) {
        failures.add(failure.asMap());
    }
    return ImmutableMap.of("failures", failures, "total", indexFailureService.totalCount());
}
Also used : IndexFailure(org.graylog2.indexer.IndexFailure) ArrayList(java.util.ArrayList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 IndexFailure (org.graylog2.indexer.IndexFailure)2 Timed (com.codahale.metrics.annotation.Timed)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)1 IndexFailureImpl (org.graylog2.indexer.IndexFailureImpl)1 IndexSet (org.graylog2.indexer.IndexSet)1 ResultMessage (org.graylog2.indexer.results.ResultMessage)1 Message (org.graylog2.plugin.Message)1