Search in sources :

Example 21 with MetronError

use of org.apache.metron.common.error.MetronError in project metron by apache.

the class ParserBolt method handleError.

protected void handleError(String sensorType, byte[] originalMessage, Tuple tuple, Throwable ex, OutputCollector collector) {
    MetronError error = new MetronError().withErrorType(Constants.ErrorType.PARSER_ERROR).withThrowable(ex).withSensorType(Collections.singleton(sensorType)).addRawMessage(originalMessage);
    handleError(collector, error);
}
Also used : MetronError(org.apache.metron.common.error.MetronError)

Example 22 with MetronError

use of org.apache.metron.common.error.MetronError in project metron by apache.

the class AckTuplesPolicyTest method shouldProperlyHandleSuccessAndErrors.

@Test
public void shouldProperlyHandleSuccessAndErrors() throws Exception {
    String messageId1 = "messageId1";
    String messageId2 = "messageId2";
    String messageId3 = "messageId3";
    JSONObject message1 = new JSONObject();
    JSONObject message2 = new JSONObject();
    JSONObject message3 = new JSONObject();
    message1.put("value", "message1");
    message2.put("value", "message2");
    message3.put("value", "message3");
    Tuple tuple3 = mock(Tuple.class);
    Throwable e = new Exception("test exception");
    MetronError expectedError1 = new MetronError().withSensorType(Collections.singleton(sensorType)).withErrorType(Constants.ErrorType.INDEXING_ERROR).withThrowable(e).withRawMessages(Collections.singletonList(message1));
    MetronError expectedError2 = new MetronError().withSensorType(Collections.singleton(sensorType)).withErrorType(Constants.ErrorType.INDEXING_ERROR).withThrowable(e).withRawMessages(Collections.singletonList(message2));
    BulkWriterResponse response = new BulkWriterResponse();
    response.addAllErrors(e, Arrays.asList(new MessageId(messageId1), new MessageId(messageId2)));
    response.addSuccess(new MessageId(messageId3));
    when(messageGetStrategy.get(tuple1)).thenReturn(message1);
    when(messageGetStrategy.get(tuple2)).thenReturn(message2);
    ackTuplesPolicy.addTupleMessageIds(tuple1, Collections.singleton(messageId1));
    ackTuplesPolicy.addTupleMessageIds(tuple2, Collections.singleton(messageId2));
    ackTuplesPolicy.addTupleMessageIds(tuple3, Collections.singleton(messageId3));
    ackTuplesPolicy.onFlush(sensorType, response);
    assertEquals(0, ackTuplesPolicy.getTupleMessageMap().size());
    assertEquals(0, ackTuplesPolicy.getTupleErrorMap().size());
    verify(collector, times(1)).emit(eq(Constants.ERROR_STREAM), new Values(argThat(new MetronErrorJSONMatcher(expectedError1.getJSONObject()))));
    verify(collector, times(1)).emit(eq(Constants.ERROR_STREAM), new Values(argThat(new MetronErrorJSONMatcher(expectedError2.getJSONObject()))));
    verify(collector, times(1)).ack(tuple1);
    verify(collector, times(1)).ack(tuple2);
    verify(collector, times(1)).ack(tuple3);
    verify(collector, times(1)).reportError(e);
    verifyNoMoreInteractions(collector);
}
Also used : MetronErrorJSONMatcher(org.apache.metron.test.error.MetronErrorJSONMatcher) JSONObject(org.json.simple.JSONObject) MetronError(org.apache.metron.common.error.MetronError) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) BulkWriterResponse(org.apache.metron.common.writer.BulkWriterResponse) MessageId(org.apache.metron.common.writer.MessageId) Test(org.junit.jupiter.api.Test)

Example 23 with MetronError

use of org.apache.metron.common.error.MetronError in project metron by apache.

the class ErrorUtilsTest method handleErrorShouldEmitAndReportError.

@Test
public void handleErrorShouldEmitAndReportError() {
    Throwable e = new Exception("error");
    MetronError error = new MetronError().withMessage("error message").withThrowable(e);
    OutputCollector collector = mock(OutputCollector.class);
    StormErrorUtils.handleError(collector, error);
    verify(collector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject())));
    verify(collector, times(1)).reportError(any());
}
Also used : OutputCollector(org.apache.storm.task.OutputCollector) MetronErrorJSONMatcher(org.apache.metron.test.error.MetronErrorJSONMatcher) MetronError(org.apache.metron.common.error.MetronError) Test(org.junit.jupiter.api.Test)

Example 24 with MetronError

use of org.apache.metron.common.error.MetronError in project metron by apache.

the class UnifiedEnrichmentBolt method execute.

/**
 * Fully enrich a message based on the strategy which was used to configure the bolt.
 * Each enrichment is done in parallel and the results are joined together.  Each enrichment
 * will use a cache so computation is avoided if the result has been computed before.
 *
 * Errors in the enrichment result in an error message being sent on the "error" stream.
 * The successful enrichments will be joined with the original message and the message will
 * be sent along the "message" stream.
 *
 * @param input The input tuple to be processed.
 */
@Override
public void execute(Tuple input) {
    JSONObject message = generateMessage(input);
    try {
        String sourceType = MessageUtils.getSensorType(message);
        SensorEnrichmentConfig config = getConfigurations().getSensorEnrichmentConfig(sourceType);
        if (config == null) {
            LOG.debug("Unable to find SensorEnrichmentConfig for sourceType: {}", sourceType);
            config = new SensorEnrichmentConfig();
        }
        // This is an existing kludge for the stellar adapter to pass information along.
        // We should figure out if this can be rearchitected a bit.  This smells.
        config.getConfiguration().putIfAbsent(STELLAR_CONTEXT_CONF, stellarContext);
        String guid = getGUID(input, message);
        // enrich the message
        ParallelEnricher.EnrichmentResult result = enricher.apply(message, strategy, config, perfLog);
        JSONObject enriched = result.getResult();
        enriched = strategy.postProcess(enriched, config, enrichmentContext);
        // we can emit the message now
        collector.emit("message", input, new Values(guid, enriched));
        // and handle each of the errors in turn.  If any adapter errored out, we will have one message per.
        for (Map.Entry<Object, Throwable> t : result.getEnrichmentErrors()) {
            LOG.error("[Metron] Unable to enrich message: {}", message, t);
            MetronError error = new MetronError().withErrorType(strategy.getErrorType()).withMessage(t.getValue().getMessage()).withThrowable(t.getValue()).addRawMessage(t.getKey());
            StormErrorUtils.handleError(collector, error);
        }
    } catch (Exception e) {
        // If something terrible and unexpected happens then we want to send an error along, but this
        // really shouldn't be happening.
        LOG.error("[Metron] Unable to enrich message: {}", message, e);
        MetronError error = new MetronError().withErrorType(strategy.getErrorType()).withMessage(e.getMessage()).withThrowable(e).addRawMessage(message);
        StormErrorUtils.handleError(collector, error);
    } finally {
        collector.ack(input);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) MetronError(org.apache.metron.common.error.MetronError) Values(org.apache.storm.tuple.Values) JSONObject(org.json.simple.JSONObject) ParallelEnricher(org.apache.metron.enrichment.parallel.ParallelEnricher) HashMap(java.util.HashMap) Map(java.util.Map) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)

Example 25 with MetronError

use of org.apache.metron.common.error.MetronError in project metron by apache.

the class AckTuplesPolicy method handleError.

private void handleError(String sensorType, Throwable e, Tuple tuple) {
    MetronError error = new MetronError().withSensorType(Collections.singleton(sensorType)).withErrorType(Constants.ErrorType.INDEXING_ERROR).withThrowable(e).addRawMessage(messageGetStrategy.get(tuple));
    collector.emit(Constants.ERROR_STREAM, new Values(error.getJSONObject()));
}
Also used : MetronError(org.apache.metron.common.error.MetronError) Values(org.apache.storm.tuple.Values)

Aggregations

MetronError (org.apache.metron.common.error.MetronError)30 JSONObject (org.json.simple.JSONObject)18 MetronErrorJSONMatcher (org.apache.metron.test.error.MetronErrorJSONMatcher)12 Test (org.junit.jupiter.api.Test)12 Values (org.apache.storm.tuple.Values)8 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)6 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)6 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)5 RawMessage (org.apache.metron.common.message.metadata.RawMessage)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 SensorEnrichmentConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)3 ProcessResult (org.apache.metron.parsers.ParserRunnerImpl.ProcessResult)3 Tuple (org.apache.storm.tuple.Tuple)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 BulkWriterResponse (org.apache.metron.common.writer.BulkWriterResponse)2 MessageId (org.apache.metron.common.writer.MessageId)2 CacheKey (org.apache.metron.enrichment.cache.CacheKey)2 BaseEnrichmentBoltTest (org.apache.metron.test.bolt.BaseEnrichmentBoltTest)2