Search in sources :

Example 1 with IndexingRequest

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

the class MessagesAdapterES6Test method bulkIndexingParsesIndexMappingErrors.

@Test
public void bulkIndexingParsesIndexMappingErrors() throws Exception {
    final String messageId = "BOOMID";
    final BulkResult jestResult = mock(BulkResult.class);
    final BulkResult.BulkResultItem bulkResultItem = new MockedBulkResult().createResultItem("index", "someindex", "message", messageId, 400, "{\"type\":\"mapper_parsing_exception\",\"reason\":\"failed to parse [http_response_code]\",\"caused_by\":{\"type\":\"number_format_exception\",\"reason\":\"For input string: \\\"FOOBAR\\\"\"}}", null, "mapper_parsing_exception", "failed to parse [http_response_code]");
    when(jestResult.isSucceeded()).thenReturn(false);
    when(jestResult.getFailedItems()).thenReturn(ImmutableList.of(bulkResultItem));
    when(jestClient.execute(any())).thenReturn(jestResult).thenThrow(new IllegalStateException("JestResult#execute should not be called twice."));
    final List<IndexingRequest> messageList = messageListWith(messageWithId(messageId));
    final List<Messages.IndexingError> result = messagesAdapter.bulkIndex(messageList);
    assertThat(result).hasSize(1).extracting(indexingError -> indexingError.message().getId(), Messages.IndexingError::errorType, Messages.IndexingError::errorMessage).containsExactly(tuple(messageId, Messages.IndexingError.ErrorType.MappingError, "failed to parse [http_response_code]"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) INDEX_BLOCK_ERROR(org.graylog.storage.elasticsearch6.MessagesAdapterES6.INDEX_BLOCK_ERROR) JestClient(io.searchbox.client.JestClient) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Messages(org.graylog2.indexer.messages.Messages) IndexSet(org.graylog2.indexer.IndexSet) MetricRegistry(com.codahale.metrics.MetricRegistry) IndexingRequest(org.graylog2.indexer.messages.IndexingRequest) Assertions.tuple(org.assertj.core.api.Assertions.tuple) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) INDEX_BLOCK_REASON(org.graylog.storage.elasticsearch6.MessagesAdapterES6.INDEX_BLOCK_REASON) Mockito.verify(org.mockito.Mockito.verify) BulkResult(io.searchbox.core.BulkResult) Test(org.junit.jupiter.api.Test) List(java.util.List) Mockito.never(org.mockito.Mockito.never) ChunkedBulkIndexer(org.graylog2.indexer.messages.ChunkedBulkIndexer) Message(org.graylog2.plugin.Message) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) IndexingRequest(org.graylog2.indexer.messages.IndexingRequest) Messages(org.graylog2.indexer.messages.Messages) BulkResult(io.searchbox.core.BulkResult) Test(org.junit.jupiter.api.Test)

Example 2 with IndexingRequest

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

the class MessagesAdapterES6Test method bulkIndexPropagatesIOExceptions.

@Test
public void bulkIndexPropagatesIOExceptions() throws Exception {
    when(jestClient.execute(any())).thenThrow(new IOException("Boom!"));
    final List<IndexingRequest> messageList = messageListWith(mock(Message.class));
    assertThatThrownBy(() -> messagesAdapter.bulkIndex(messageList)).isInstanceOf(IOException.class);
}
Also used : IndexingRequest(org.graylog2.indexer.messages.IndexingRequest) Message(org.graylog2.plugin.Message) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 3 with IndexingRequest

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

the class MessagesAdapterES7 method bulkIndexChunked.

private List<Messages.IndexingError> bulkIndexChunked(ChunkedBulkIndexer.Chunk command) throws ChunkedBulkIndexer.EntityTooLargeException {
    final List<IndexingRequest> messageList = command.requests;
    final int offset = command.offset;
    final int chunkSize = command.size;
    if (messageList.isEmpty()) {
        return Collections.emptyList();
    }
    final Iterable<List<IndexingRequest>> chunks = Iterables.partition(messageList.subList(offset, messageList.size()), chunkSize);
    int chunkCount = 1;
    int indexedSuccessfully = 0;
    final List<Messages.IndexingError> indexFailures = new ArrayList<>();
    for (List<IndexingRequest> chunk : chunks) {
        final BulkResponse result = runBulkRequest(indexedSuccessfully, chunk);
        indexedSuccessfully += chunk.size();
        final List<BulkItemResponse> failures = extractFailures(result);
        indexFailures.addAll(indexingErrorsFrom(failures, messageList));
        logDebugInfo(messageList, offset, chunkSize, chunkCount, result, failures);
        logFailures(result, failures.size());
        chunkCount++;
    }
    return indexFailures;
}
Also used : IndexingRequest(org.graylog2.indexer.messages.IndexingRequest) ArrayList(java.util.ArrayList) BulkItemResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkItemResponse) ArrayList(java.util.ArrayList) List(java.util.List) BulkResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkResponse)

Example 4 with IndexingRequest

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

the class MessagesAdapterES7 method runBulkRequest.

private BulkResponse runBulkRequest(int indexedSuccessfully, List<IndexingRequest> chunk) throws ChunkedBulkIndexer.EntityTooLargeException {
    final BulkRequest bulkRequest = createBulkRequest(chunk);
    final BulkResponse result;
    try {
        result = this.client.execute((c, requestOptions) -> c.bulk(bulkRequest, requestOptions));
    } catch (ElasticsearchException e) {
        for (ElasticsearchException cause : e.guessRootCauses()) {
            if (cause.status().equals(RestStatus.REQUEST_ENTITY_TOO_LARGE)) {
                throw new ChunkedBulkIndexer.EntityTooLargeException(indexedSuccessfully, indexingErrorsFrom(chunk));
            }
        }
        throw new org.graylog2.indexer.ElasticsearchException(e);
    }
    return result;
}
Also used : Iterables(com.google.common.collect.Iterables) Arrays(java.util.Arrays) IndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest) MessagesAdapter(org.graylog2.indexer.messages.MessagesAdapter) ElasticsearchException(org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException) LoggerFactory(org.slf4j.LoggerFactory) XContentType(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.XContentType) GetResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Meter(com.codahale.metrics.Meter) Indexable(org.graylog2.indexer.messages.Indexable) ResultMessage(org.graylog2.indexer.results.ResultMessage) Locale(java.util.Locale) Map(java.util.Map) Messages(org.graylog2.indexer.messages.Messages) AnalyzeResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.AnalyzeResponse) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) IndexingRequest(org.graylog2.indexer.messages.IndexingRequest) BulkItemResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkItemResponse) AnalyzeRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.AnalyzeRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GetRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetRequest) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RestStatus(org.graylog.shaded.elasticsearch7.org.elasticsearch.rest.RestStatus) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) List(java.util.List) BulkResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkResponse) BulkRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest) ChunkedBulkIndexer(org.graylog2.indexer.messages.ChunkedBulkIndexer) Collections(java.util.Collections) MetricRegistry.name(com.codahale.metrics.MetricRegistry.name) DocumentNotFoundException(org.graylog2.indexer.messages.DocumentNotFoundException) BulkRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest) BulkResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkResponse) ElasticsearchException(org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException) ChunkedBulkIndexer(org.graylog2.indexer.messages.ChunkedBulkIndexer)

Example 5 with IndexingRequest

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

the class MessagesAdapterES6 method indexingErrorsFrom.

private List<Messages.IndexingError> indexingErrorsFrom(List<BulkResult.BulkResultItem> failedItems, List<IndexingRequest> messageList) {
    if (failedItems.isEmpty()) {
        return Collections.emptyList();
    }
    final Map<String, Indexable> messageMap = messageList.stream().map(IndexingRequest::message).distinct().collect(Collectors.toMap(Indexable::getId, Function.identity()));
    final List<Messages.IndexingError> indexFailures = new ArrayList<>(failedItems.size());
    for (BulkResult.BulkResultItem item : failedItems) {
        LOG.warn("Failed to index message: index=<{}> id=<{}> error=<{}>", item.index, item.id, item.error);
        final Indexable messageEntry = messageMap.get(item.id);
        final Messages.IndexingError indexFailure = indexingErrorFromResultItem(item, messageEntry);
        indexFailures.add(indexFailure);
    }
    return indexFailures;
}
Also used : IndexingRequest(org.graylog2.indexer.messages.IndexingRequest) Messages(org.graylog2.indexer.messages.Messages) ArrayList(java.util.ArrayList) Indexable(org.graylog2.indexer.messages.Indexable) BulkResult(io.searchbox.core.BulkResult)

Aggregations

IndexingRequest (org.graylog2.indexer.messages.IndexingRequest)9 BulkResult (io.searchbox.core.BulkResult)5 List (java.util.List)5 Message (org.graylog2.plugin.Message)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 IndexSet (org.graylog2.indexer.IndexSet)4 Messages (org.graylog2.indexer.messages.Messages)4 DateTime (org.joda.time.DateTime)4 Test (org.junit.jupiter.api.Test)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 ChunkedBulkIndexer (org.graylog2.indexer.messages.ChunkedBulkIndexer)3 Indexable (org.graylog2.indexer.messages.Indexable)3 ImmutableList (com.google.common.collect.ImmutableList)2 JestClient (io.searchbox.client.JestClient)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2