use of org.kie.kogito.tracing.event.trace.TraceExecutionStep in project kogito-runtimes by kiegroup.
the class DefaultAggregator method buildDmnContextEntryTraceExecutionStep.
private static TraceExecutionStep buildDmnContextEntryTraceExecutionStep(long duration, EvaluateEvent afterEvent, List<TraceExecutionStep> children, DMNModel model) {
JsonNode result = EventUtils.jsonNodeFrom(afterEvent.getContextEntryResult().getExpressionResult());
Map<String, String> additionalData = new HashMap<>();
additionalData.put(EXPRESSION_ID_KEY, afterEvent.getContextEntryResult().getExpressionId());
additionalData.put(VARIABLE_ID_KEY, afterEvent.getContextEntryResult().getVariableId());
Optional<String> optDecisionNodeId = Optional.ofNullable(model).map(m -> m.getDecisionByName(afterEvent.getNodeName())).map(DecisionNode::getId);
if (optDecisionNodeId.isPresent()) {
additionalData.put(NODE_ID_KEY, optDecisionNodeId.get());
} else {
additionalData.put(NODE_NAME_KEY, afterEvent.getNodeName());
}
return new TraceExecutionStep(TraceExecutionStepType.DMN_CONTEXT_ENTRY, duration, afterEvent.getContextEntryResult().getVariableName(), result, Collections.emptyList(), additionalData, children);
}
use of org.kie.kogito.tracing.event.trace.TraceExecutionStep in project kogito-runtimes by kiegroup.
the class DefaultAggregator method buildTraceExecutionStep.
private static TraceExecutionStep buildTraceExecutionStep(DMNModel model, DefaultAggregatorStackEntry stackEntry, EvaluateEvent afterEvent) {
TraceExecutionStepType type = Optional.ofNullable(afterEvent.getType()).map(EvaluateEventType::toTraceExecutionStepType).orElse(null);
if (type == null) {
return null;
}
long duration = Optional.ofNullable(stackEntry).map(DefaultAggregatorStackEntry::getBeforeEvent).map(beforeEvent -> computeDurationMillis(beforeEvent, afterEvent)).orElse(0L);
List<TraceExecutionStep> children = Optional.ofNullable(stackEntry).map(DefaultAggregatorStackEntry::getChildren).orElse(Collections.emptyList());
switch(type) {
case DMN_BKM_EVALUATION:
case DMN_DECISION_SERVICE:
case DMN_BKM_INVOCATION:
return buildDefaultTraceExecutionStep(duration, afterEvent, children, type);
case DMN_CONTEXT_ENTRY:
return buildDmnContextEntryTraceExecutionStep(duration, afterEvent, children, model);
case DMN_DECISION:
return buildDmnDecisionTraceExecutionStep(duration, afterEvent, children);
case DMN_DECISION_TABLE:
return buildDmnDecisionTableTraceExecutionStep(duration, afterEvent, children, model);
default:
return null;
}
}
use of org.kie.kogito.tracing.event.trace.TraceExecutionStep in project kogito-runtimes by kiegroup.
the class DefaultAggregator method buildDmnDecisionTraceExecutionStep.
private static TraceExecutionStep buildDmnDecisionTraceExecutionStep(long duration, EvaluateEvent afterEvent, List<TraceExecutionStep> children) {
List<Message> messages = afterEvent.getResult().getMessages().stream().filter(m -> afterEvent.getNodeId().equals(m.getSourceId())).collect(Collectors.toList());
JsonNode result = afterEvent.getResult().getDecisionResults().stream().filter(dr -> dr.getDecisionId().equals(afterEvent.getNodeId())).findFirst().map(EvaluateDecisionResult::getResult).<JsonNode>map(EventUtils::jsonNodeFrom).orElse(null);
Map<String, String> additionalData = new HashMap<>();
additionalData.put(NODE_ID_KEY, afterEvent.getNodeId());
return new TraceExecutionStep(TraceExecutionStepType.DMN_DECISION, duration, afterEvent.getNodeName(), result, messages, additionalData, children);
}
use of org.kie.kogito.tracing.event.trace.TraceExecutionStep in project kogito-runtimes by kiegroup.
the class DefaultAggregator method processEvaluateEventInHierarchy.
private static void processEvaluateEventInHierarchy(DMNModel model, Deque<DefaultAggregatorStackEntry> stack, List<TraceExecutionStep> executionSteps, EvaluateEvent event) {
LOG.trace("Started aggregating event {} (execution steps: {}, stack size: {})", event.getType(), executionSteps.size(), stack.size());
if (event.getType().isBefore()) {
stack.push(new DefaultAggregatorStackEntry(event));
} else {
if (stack.isEmpty() || !stack.peek().isValidAfterEvent(event)) {
throw new IllegalStateException(String.format("Can't match %s after event with corresponding before event", event.getType()));
}
DefaultAggregatorStackEntry stackEntry = stack.pop();
TraceExecutionStep step = buildTraceExecutionStep(model, stackEntry, event);
if (step == null) {
throw new IllegalStateException(String.format("Can't build TraceExecutionStep for a %s event", event.getType()));
}
if (stack.isEmpty()) {
executionSteps.add(step);
} else {
stack.peek().addChild(step);
}
}
LOG.trace("Finished aggregating event {} (execution steps: {}, stack size: {})", event.getType(), executionSteps.size(), stack.size());
}
Aggregations