/** * Error a set of tuples that may not contain a valid message. * * <p>Without a valid message, the source type is unknown. * <p>Without a valid message, the JSON message cannot be added to the error. * * @param e The exception that occurred. * @param tuple The tuple to error that may not contain a valid message. */ public void error(Throwable e, Tuple tuple) { LOG.error("Failing tuple", e); MetronError error = new MetronError() .withErrorType(Constants.ErrorType.INDEXING_ERROR) .withThrowable(e); handleError(tuple, error); }
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); ErrorUtils.handleError(collector, error); }
public void error(String sensorType, Throwable e, Iterable<Tuple> tuples, MessageGetStrategy messageGetStrategy) { LOG.error(format("Failing %d tuple(s); sensorType=%s", Iterables.size(tuples), sensorType), e); tuples.forEach(t -> { MetronError error = new MetronError() .withSensorType(Collections.singleton(sensorType)) .withErrorType(Constants.ErrorType.INDEXING_ERROR) .withThrowable(e) .addRawMessage(messageGetStrategy.get(t)); collector.emit(Constants.ERROR_STREAM, new Values(error.getJSONObject())); }); if (handleCommit) { commit(tuples); } // there is only one error to report for all of the failed tuples collector.reportError(e); }
protected void handleError(String key, JSONObject rawMessage, String subGroup, JSONObject enrichedMessage, Exception e) { LOG.error("[Metron] Unable to enrich message: {}", rawMessage, e); if (key != null) { collector.emit(enrichmentType, new Values(key, enrichedMessage, subGroup)); } MetronError error = new MetronError() .withErrorType(Constants.ErrorType.ENRICHMENT_ERROR) .withThrowable(e) .addRawMessage(rawMessage); ErrorUtils.handleError(collector, error); }
.withThrowable(throwable) .withSensorType(Collections.singleton(sensorType)) .addRawMessage(rawMessage.getMessage()))); .withThrowable(entry.getValue()) .withSensorType(Collections.singleton(sensorType)) .addRawMessage(entry.getKey())).collect(Collectors.toList()));
.withErrorType(Constants.ErrorType.ENRICHMENT_ERROR) .withMessage("Joining problem: " + message) .withThrowable(e) .addRawMessage(message); ErrorUtils.handleError(collector, error);
@Test public void handleErrorShouldEmitAndReportError() throws Exception { Throwable e = new Exception("error"); MetronError error = new MetronError().withMessage("error message").withThrowable(e); OutputCollector collector = mock(OutputCollector.class); ErrorUtils.handleError(collector, error); verify(collector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject()))); verify(collector, times(1)).reportError(any()); } }
@Test public void getJSONObjectShouldHandleThrowable() { Throwable e = new Exception("test exception"); MetronError error = new MetronError().withThrowable(e); JSONObject errorJSON = error.getJSONObject(); assertEquals("java.lang.Exception: test exception", errorJSON.get(Constants.ErrorFields.EXCEPTION.getName())); assertTrue(((String) errorJSON.get(Constants.ErrorFields.STACK.getName())).startsWith("java.lang.Exception: test exception")); assertEquals(e.getMessage(), errorJSON.get(Constants.ErrorFields.MESSAGE.getName())); }
MetronError metronError = new MetronError() .withErrorType(Constants.ErrorType.ENRICHMENT_ERROR) .withThrowable(e) .withErrorFields(new HashSet() {{ add(field); }}) .addRawMessage(rawMessage);
@Test public void testNonBatchErrorPathErrorInWrite() throws Exception { ParserConfigurations configurations = getConfigurations(1); String sensorType = "test"; Tuple t = mock(Tuple.class); when(t.toString()).thenReturn("tuple"); when(t.getValueByField(eq("message"))).thenReturn(new JSONObject()); WriterBolt bolt = new WriterBolt(new WriterHandler(writer), configurations, sensorType); bolt.prepare(new HashMap(), topologyContext, outputCollector); doThrow(new Exception("write error")).when(writer).write(any(), any(), any(), any()); verify(writer, times(1)).init(); bolt.execute(t); verify(outputCollector, times(1)).ack(t); verify(writer, times(1)).write(eq(sensorType), any(), any(), any()); verify(outputCollector, times(1)).reportError(any()); verify(outputCollector, times(0)).fail(any()); MetronError error = new MetronError() .withErrorType(Constants.ErrorType.DEFAULT_ERROR) .withThrowable(new IllegalStateException("Unhandled bulk errors in response: {java.lang.Exception: write error=[tuple]}")) .withSensorType(Collections.singleton(sensorType)) .addRawMessage(new JSONObject()); verify(outputCollector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject()))); }
@SuppressWarnings("unchecked") @Test public void testExecuteShouldReportError() throws ExecutionException { joinBolt.withMaxCacheSize(100); joinBolt.withMaxTimeRetain(10000); joinBolt.prepare(new HashMap(), topologyContext, outputCollector); when(tuple.getValueByField("key")).thenReturn(key); when(tuple.getValueByField("message")).thenReturn(new JSONObject()); joinBolt.cache = mock(LoadingCache.class); when(joinBolt.cache.get(any())).thenThrow(new RuntimeException(new Exception("join exception"))); joinBolt.execute(tuple); RuntimeException expectedExecutionException = new RuntimeException(new Exception("join exception")); MetronError error = new MetronError() .withErrorType(Constants.ErrorType.ENRICHMENT_ERROR) .withMessage("Joining problem: {}") .withThrowable(expectedExecutionException) .addRawMessage(new JSONObject()); verify(outputCollector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject()))); verify(outputCollector, times(1)).reportError(any(ExecutionException.class)); verify(outputCollector, times(1)).ack(eq(tuple)); verifyNoMoreInteractions(outputCollector); } }
@Test public void shouldExecuteWithMasterThrowable() { parserRunner = spy(parserRunner); RawMessage rawMessage = new RawMessage("raw_message".getBytes(), new HashMap<>()); Throwable masterThrowable = mock(Throwable.class); MessageParserResult<JSONObject> messageParserResult = new DefaultMessageParserResult<>(masterThrowable); when(broParser.parseOptionalResult(rawMessage.getMessage())).thenReturn(Optional.of(messageParserResult)); parserRunner.setSensorToParserComponentMap(new HashMap<String, ParserComponent>() {{ put("bro", new ParserComponent(broParser, stellarFilter)); }}); ParserRunnerResults<JSONObject> parserRunnerResults = parserRunner.execute("bro", rawMessage, parserConfigurations); verify(parserRunner, times(0)) .processMessage(any(), any(), any(), any(), any()); MetronError expectedError = new MetronError() .withErrorType(Constants.ErrorType.PARSER_ERROR) .withThrowable(masterThrowable) .withSensorType(Collections.singleton("bro")) .addRawMessage(rawMessage.getMessage()); Assert.assertEquals(1, parserRunnerResults.getErrors().size()); Assert.assertTrue(parserRunnerResults.getErrors().contains(expectedError)); }
.withErrorType(strategy.getErrorType()) .withMessage(t.getValue().getMessage()) .withThrowable(t.getValue()) .addRawMessage(t.getKey()); ErrorUtils.handleError(collector, error); .withErrorType(strategy.getErrorType()) .withMessage(e.getMessage()) .withThrowable(e) .addRawMessage(message); ErrorUtils.handleError(collector, error);
@Override public void execute(Tuple tuple) { JSONObject message = null; try { message = (JSONObject) messageGetStrategy.get(tuple); handler.write(sensorType, tuple, message, configuration, messageGetStrategy); if(!handler.handleAck()) { collector.ack(tuple); } } catch (Throwable e) { MetronError error = new MetronError() .withErrorType(errorType) .withThrowable(e) .withSensorType(Collections.singleton(sensorType)) .addRawMessage(message); ErrorUtils.handleError(collector, error); collector.ack(tuple); } }
MetronError error = new MetronError() .withErrorType(Constants.ErrorType.PARSER_ERROR) .withThrowable(new IllegalStateException("parserRunner.execute failed")) .withSensorType(Collections.singleton("yaf")) .addRawMessage("originalMessage".getBytes(StandardCharsets.UTF_8));
.withThrowable(new IllegalStateException("write failed")) .withSensorType(Collections.singleton("yaf")) .addRawMessage("originalMessage".getBytes(StandardCharsets.UTF_8));
.withThrowable(throwable1) .withSensorType(Collections.singleton("bro")) .addRawMessage(rawMessage1); MetronError expectedParseError2 = new MetronError() .withErrorType(Constants.ErrorType.PARSER_ERROR) .withThrowable(throwable2) .withSensorType(Collections.singleton("bro")) .addRawMessage(rawMessage2);
MetronError error = new MetronError() .withErrorType(Constants.ErrorType.ENRICHMENT_ERROR) .withThrowable(new Exception("Could not parse binary stream to JSON")); verify(outputCollector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject()))); when(tuple.getStringByField("key")).thenReturn(key); put("source.type", "test"); }}) .withThrowable(new Exception("[Metron] Could not enrich string: value1")); verify(outputCollector, times(1)).emit(eq(Constants.ERROR_STREAM), argThat(new MetronErrorJSONMatcher(error.getJSONObject())));