Search in sources :

Example 1 with PipelineInterpreterTracer

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());
}
Also used : Message(org.graylog2.plugin.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResultMessageSummary(org.graylog2.rest.models.messages.responses.ResultMessageSummary) PipelineInterpreterTracer(org.graylog.plugins.pipelineprocessor.simulator.PipelineInterpreterTracer) Stream(org.graylog2.plugin.streams.Stream) DecorationStats(org.graylog2.rest.models.messages.responses.DecorationStats) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 POST (javax.ws.rs.POST)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 PipelineInterpreterTracer (org.graylog.plugins.pipelineprocessor.simulator.PipelineInterpreterTracer)1 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)1 Message (org.graylog2.plugin.Message)1 Stream (org.graylog2.plugin.streams.Stream)1 DecorationStats (org.graylog2.rest.models.messages.responses.DecorationStats)1 ResultMessageSummary (org.graylog2.rest.models.messages.responses.ResultMessageSummary)1