use of org.graylog2.rest.models.messages.responses.DecorationStats in project graylog2-server by Graylog2.
the class DecoratorProcessorImpl method decorate.
@Override
public SearchResponse decorate(SearchResponse searchResponse, Optional<String> streamId) {
try {
final List<SearchResponseDecorator> searchResponseDecorators = streamId.isPresent() ? decoratorResolver.searchResponseDecoratorsForStream(streamId.get()) : decoratorResolver.searchResponseDecoratorsForGlobal();
final Optional<SearchResponseDecorator> metaDecorator = searchResponseDecorators.stream().reduce((f, g) -> (v) -> g.apply(f.apply(v)));
if (metaDecorator.isPresent()) {
final Map<String, ResultMessageSummary> originalMessages = searchResponse.messages().stream().collect(Collectors.toMap(this::getMessageKey, Function.identity()));
final SearchResponse newSearchResponse = metaDecorator.get().apply(searchResponse);
final Set<String> newFields = extractFields(newSearchResponse.messages());
final List<ResultMessageSummary> decoratedMessages = newSearchResponse.messages().stream().map(resultMessage -> {
final ResultMessageSummary originalMessage = originalMessages.get(getMessageKey(resultMessage));
if (originalMessage != null) {
return resultMessage.toBuilder().decorationStats(DecorationStats.create(originalMessage.message(), resultMessage.message())).build();
}
return resultMessage;
}).collect(Collectors.toList());
return newSearchResponse.toBuilder().messages(decoratedMessages).fields(newFields).decorationStats(this.getSearchDecoratorStats(decoratedMessages)).build();
}
} catch (Exception e) {
LOG.error("Error decorating search response", e);
}
return searchResponse;
}
use of org.graylog2.rest.models.messages.responses.DecorationStats 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());
}
use of org.graylog2.rest.models.messages.responses.DecorationStats in project graylog2-server by Graylog2.
the class DecoratorProcessorImpl method getSearchDecoratorStats.
private SearchDecorationStats getSearchDecoratorStats(List<ResultMessageSummary> decoratedMessages) {
final Set<String> addedFields = new HashSet<>();
final Set<String> changedFields = new HashSet<>();
final Set<String> removedFields = new HashSet<>();
decoratedMessages.forEach(message -> {
final DecorationStats decorationStats = message.decorationStats();
if (decorationStats != null) {
addedFields.addAll(decorationStats.addedFields().keySet());
changedFields.addAll(decorationStats.changedFields().keySet());
removedFields.addAll(decorationStats.removedFields().keySet());
}
});
return SearchDecorationStats.create(addedFields, changedFields, removedFields);
}
use of org.graylog2.rest.models.messages.responses.DecorationStats in project graylog2-server by Graylog2.
the class DecoratorProcessorImpl method decorate.
@Override
public SearchResponse decorate(SearchResponse searchResponse, List<SearchResponseDecorator> searchResponseDecorators) {
try {
final Optional<SearchResponseDecorator> metaDecorator = searchResponseDecorators.stream().reduce((f, g) -> (v) -> g.apply(f.apply(v)));
if (metaDecorator.isPresent()) {
final Map<String, ResultMessageSummary> originalMessages = searchResponse.messages().stream().collect(Collectors.toMap(this::getMessageKey, Function.identity()));
final SearchResponse newSearchResponse = metaDecorator.get().apply(searchResponse);
final Set<String> newFields = extractFields(newSearchResponse.messages());
final List<ResultMessageSummary> decoratedMessages = newSearchResponse.messages().stream().map(resultMessage -> {
final ResultMessageSummary originalMessage = originalMessages.get(getMessageKey(resultMessage));
if (originalMessage != null) {
return resultMessage.toBuilder().decorationStats(DecorationStats.create(originalMessage.message(), resultMessage.message())).build();
}
return resultMessage;
}).collect(Collectors.toList());
return newSearchResponse.toBuilder().messages(decoratedMessages).fields(newFields).decorationStats(this.getSearchDecoratorStats(decoratedMessages)).build();
}
} catch (Exception e) {
LOG.error("Error decorating search response", e);
}
return searchResponse;
}
Aggregations