@Test public void test_that_a_signalfx_signal_flow_response_can_be_parsed() throws Exception { InputStream response = getClass().getClassLoader().getResourceAsStream("signalfx-signalflow-response.text"); SignalFxConverter converter = new SignalFxConverter(); TypedInput typedInput = new TypedByteArray("text/plain", ByteStreams.toByteArray(response)); SignalFlowExecutionResult signalFlowExecutionResult = (SignalFlowExecutionResult) converter.fromBody(typedInput, SignalFlowExecutionResult.class); assertNotNull(signalFlowExecutionResult); assertThat("The signalFlowExecutionResult contains the channel messages", signalFlowExecutionResult.getChannelMessages().size(), greaterThan(1)); } }
private SignalFlowExecutionResult getSignalFlowExecutionResultFromBody(TypedInput body) throws ConversionException { List<ChannelMessage> messages = new LinkedList<>(); try (ServerSentEventsTransport.TransportEventStreamParser parser = new ServerSentEventsTransport.TransportEventStreamParser(body.in())) { while (parser.hasNext()) { StreamMessage streamMessage = parser.next(); ChannelMessage channelMessage = ChannelMessage.decodeStreamMessage(streamMessage); messages.add(channelMessage); } } catch (Exception e) { throw new ConversionException("There was an issue parsing the SignalFlow response", e); } return new SignalFlowExecutionResult(messages); }
.endTimeIso(Instant.ofEpochMilli(endEpochMilli).toString()) .stepMillis(stepMilli) .values(getTimeSeriesDataFromChannelMessages(signalFlowExecutionResult.getChannelMessages())) .tags(queryPairs.stream().collect(Collectors.toMap(QueryPair::getKey, QueryPair::getValue))) .attribute("signal-flow-program", program)
private SignalFlowExecutionResult getSignalFlowExecutionResultFromBody(TypedInput body) throws ConversionException { List<ChannelMessage> messages = new LinkedList<>(); try (ServerSentEventsTransport.TransportEventStreamParser parser = new ServerSentEventsTransport.TransportEventStreamParser(body.in())) { while (parser.hasNext()) { StreamMessage streamMessage = parser.next(); ChannelMessage channelMessage = ChannelMessage.decodeStreamMessage(streamMessage); messages.add(channelMessage); } } catch (Exception e) { throw new ConversionException("There was an issue parsing the SignalFlow response", e); } return new SignalFlowExecutionResult(messages); }
.endTimeIso(Instant.ofEpochMilli(endEpochMilli).toString()) .stepMillis(stepMilli) .values(getTimeSeriesDataFromChannelMessages(signalFlowExecutionResult.getChannelMessages())) .tags(queryPairs.stream().collect(Collectors.toMap(QueryPair::getKey, QueryPair::getValue))) .attribute("signal-flow-program", program)