use of org.graylog.plugins.pipelineprocessor.simulator.PipelineInterpreterTracer in project graylog2-server by Graylog2.
the class SimulatorResource method simulate.
@ApiOperation(value = "Simulate the execution of the pipeline message processor")
@POST
@RequiresPermissions(PipelineRestPermissions.PIPELINE_RULE_READ)
@NoAuditEvent("only used to test pipelines, no changes made in the system")
public SimulationResponse simulate(@ApiParam(name = "simulation", required = true) @NotNull SimulationRequest request) throws NotFoundException {
checkPermission(RestPermissions.STREAMS_READ, request.streamId());
final Message message = new Message(request.message());
// Save off the original message fields to compare post pipeline processing
Map<String, Object> originalFields = new HashMap<>(message.getFields());
final Stream stream = streamService.load(request.streamId());
message.addStream(stream);
if (!Strings.isNullOrEmpty(request.inputId())) {
message.setSourceInputId(request.inputId());
}
final List<ResultMessageSummary> simulationResults = new ArrayList<>();
final PipelineInterpreterTracer pipelineInterpreterTracer = new PipelineInterpreterTracer();
org.graylog2.plugin.Messages processedMessages = pipelineInterpreter.process(message, pipelineInterpreterTracer.getSimulatorInterpreterListener(), pipelineStateUpdater.getLatestState());
for (Message processedMessage : processedMessages) {
ResultMessageSummary summary = ResultMessageSummary.create(null, processedMessage.getFields(), "");
// generate the DecorationStats and add it to the summary
DecorationStats decorationStats = DecorationStats.create(originalFields, processedMessage.getFields());
simulationResults.add(summary.toBuilder().decorationStats(decorationStats).build());
}
return SimulationResponse.create(simulationResults, pipelineInterpreterTracer.getExecutionTrace(), pipelineInterpreterTracer.took());
}
Aggregations