Search in sources :

Example 1 with Indexable

use of org.graylog2.indexer.messages.Indexable 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)

Example 2 with Indexable

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

the class DefaultFailureHandlerTest method handle_allFailuresHandedOverToIndexFailureService.

@Test
public void handle_allFailuresHandedOverToIndexFailureService() {
    // given
    final DateTime ts = DateTime.now(DateTimeZone.UTC);
    final Indexable indexable1 = mock(Indexable.class);
    when(indexable1.getId()).thenReturn("msg-1");
    when(indexable1.getTimestamp()).thenReturn(ts);
    final Indexable indexable2 = mock(Indexable.class);
    when(indexable2.getId()).thenReturn("msg-2");
    when(indexable2.getTimestamp()).thenReturn(ts);
    final IndexingFailure indexingFailure1 = new IndexingFailure(IndexingFailureCause.MappingError, "indexingFailureMessage1", "indexingFailureDetails1", Tools.nowUTC(), indexable1, "index1");
    final IndexingFailure indexingFailure2 = new IndexingFailure(IndexingFailureCause.MappingError, "indexingFailureMessage2", "indexingFailureDetails2", Tools.nowUTC(), indexable2, "index2");
    final FailureBatch indexingFailureBatch = FailureBatch.indexingFailureBatch(ImmutableList.of(indexingFailure1, indexingFailure2));
    // when
    underTest.handle(indexingFailureBatch);
    // then
    verify(indexFailureService, times(2)).saveWithoutValidation(any());
    verify(indexFailureService, times(1)).saveWithoutValidation(argThat(arg -> arg.asMap().get("letter_id").equals("msg-1") && arg.asMap().get("index").equals("index1") && arg.asMap().get("type").equals("indexing") && arg.asMap().get("message").equals("indexingFailureDetails1") && arg.asMap().get("timestamp") != null));
    verify(indexFailureService, times(1)).saveWithoutValidation(argThat(arg -> arg.asMap().get("letter_id").equals("msg-2") && arg.asMap().get("index").equals("index2") && arg.asMap().get("type").equals("indexing") && arg.asMap().get("message").equals("indexingFailureDetails2") && arg.asMap().get("timestamp") != null));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DateTimeZone(org.joda.time.DateTimeZone) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Tools(org.graylog2.plugin.Tools) DateTime(org.joda.time.DateTime) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) IndexFailureService(org.graylog2.indexer.IndexFailureService) ImmutableList(com.google.common.collect.ImmutableList) Indexable(org.graylog2.indexer.messages.Indexable) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) Mockito.mock(org.mockito.Mockito.mock) Indexable(org.graylog2.indexer.messages.Indexable) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 3 with Indexable

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

the class MessagesAdapterES6 method bulkIndexChunk.

private BulkResult bulkIndexChunk(List<IndexingRequest> chunk) throws IOException {
    final Bulk.Builder bulk = new Bulk.Builder();
    for (IndexingRequest entry : chunk) {
        final Indexable message = entry.message();
        bulk.addAction(new Index.Builder(message.toElasticSearchObject(objectMapper, invalidTimestampMeter)).index(entry.indexSet().getWriteIndexAlias()).type(IndexMapping.TYPE_MESSAGE).id(message.getId()).build());
    }
    return runBulkRequest(bulk.build(), chunk.size());
}
Also used : IndexingRequest(org.graylog2.indexer.messages.IndexingRequest) Indexable(org.graylog2.indexer.messages.Indexable) Index(io.searchbox.core.Index) Bulk(io.searchbox.core.Bulk)

Aggregations

Indexable (org.graylog2.indexer.messages.Indexable)3 ArrayList (java.util.ArrayList)2 IndexingRequest (org.graylog2.indexer.messages.IndexingRequest)2 ImmutableList (com.google.common.collect.ImmutableList)1 Bulk (io.searchbox.core.Bulk)1 BulkResult (io.searchbox.core.BulkResult)1 Index (io.searchbox.core.Index)1 AssertionsForClassTypes.assertThat (org.assertj.core.api.AssertionsForClassTypes.assertThat)1 IndexFailureService (org.graylog2.indexer.IndexFailureService)1 Messages (org.graylog2.indexer.messages.Messages)1 Tools (org.graylog2.plugin.Tools)1 DateTime (org.joda.time.DateTime)1 DateTimeZone (org.joda.time.DateTimeZone)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.times (org.mockito.Mockito.times)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1