Search in sources :

Example 26 with EvaluateEvent

use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent in project kogito-runtimes by kiegroup.

the class DefaultAggregator method buildDefaultCloudEvent.

private static Optional<CloudEvent> buildDefaultCloudEvent(DMNModel model, String executionId, List<EvaluateEvent> events, ConfigBean configBean) {
    EvaluateEvent firstEvent = events.get(0);
    EvaluateEvent lastEvent = events.get(events.size() - 1);
    List<TraceInputValue> inputs = buildTraceInputValues(model, firstEvent);
    List<TraceOutputValue> outputs = buildTraceOutputValues(model, lastEvent);
    Pair<List<TraceExecutionStep>, List<Message>> executionStepsPair = buildTraceExecutionSteps(model, executionId, events);
    TraceHeader header = new TraceHeader(TraceEventType.DMN, executionId, firstEvent.getTimestamp(), lastEvent.getTimestamp(), computeDurationMillis(firstEvent, lastEvent), firstEvent.toTraceResourceId(configBean.getServiceUrl()), Stream.of(model == null ? Stream.of(EventUtils.messageFrom(InternalMessageType.DMN_MODEL_NOT_FOUND)) : Stream.<Message>empty(), executionStepsPair.getRight().stream(), lastEvent.getResult().getMessages().stream().filter(m -> m.getSourceId() == null || m.getSourceId().isEmpty())).flatMap(Function.identity()).collect(Collectors.toList()));
    // complete event
    TraceEvent event = new TraceEvent(header, inputs, outputs, executionStepsPair.getLeft());
    return CloudEventUtils.build(executionId, buildSource(configBean.getServiceUrl(), firstEvent), event, TraceEvent.class);
}
Also used : TraceOutputValue(org.kie.kogito.tracing.event.trace.TraceOutputValue) TraceHeader(org.kie.kogito.tracing.event.trace.TraceHeader) ArrayList(java.util.ArrayList) List(java.util.List) TraceInputValue(org.kie.kogito.tracing.event.trace.TraceInputValue) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) TraceEvent(org.kie.kogito.tracing.event.trace.TraceEvent)

Example 27 with EvaluateEvent

use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent 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;
    }
}
Also used : TraceEventType(org.kie.kogito.tracing.event.trace.TraceEventType) TraceExecutionStepType(org.kie.kogito.tracing.event.trace.TraceExecutionStepType) Arrays(java.util.Arrays) DMNType(org.kie.dmn.api.core.DMNType) CloudEvent(io.cloudevents.CloudEvent) AFTER_EVALUATE_DECISION_SERVICE(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType.AFTER_EVALUATE_DECISION_SERVICE) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Deque(java.util.Deque) Function(java.util.function.Function) TraceExecutionStep(org.kie.kogito.tracing.event.trace.TraceExecutionStep) ArrayList(java.util.ArrayList) DecisionServiceNodeImpl(org.kie.dmn.core.ast.DecisionServiceNodeImpl) DMNModel(org.kie.dmn.api.core.DMNModel) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNBaseNode(org.kie.dmn.core.ast.DMNBaseNode) Map(java.util.Map) EvaluateDecisionResult(org.kie.kogito.tracing.decision.event.evaluate.EvaluateDecisionResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) InternalMessageType(org.kie.kogito.tracing.decision.message.InternalMessageType) Message(org.kie.kogito.tracing.event.message.Message) EvaluateEventType(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType) TraceEvent(org.kie.kogito.tracing.event.trace.TraceEvent) ConfigBean(org.kie.kogito.conf.ConfigBean) Logger(org.slf4j.Logger) DMNNode(org.kie.dmn.api.core.ast.DMNNode) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) TraceInputValue(org.kie.kogito.tracing.event.trace.TraceInputValue) TraceOutputValue(org.kie.kogito.tracing.event.trace.TraceOutputValue) Collection(java.util.Collection) EventUtils(org.kie.kogito.tracing.decision.event.EventUtils) Collectors(java.util.stream.Collectors) Pair(org.kie.dmn.feel.util.Pair) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue) Objects(java.util.Objects) List(java.util.List) TraceHeader(org.kie.kogito.tracing.event.trace.TraceHeader) Stream(java.util.stream.Stream) CloudEventUtils(org.kie.kogito.event.cloudevents.utils.CloudEventUtils) BEFORE_EVALUATE_DECISION_SERVICE(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType.BEFORE_EVALUATE_DECISION_SERVICE) Optional(java.util.Optional) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) TraceExecutionStepType(org.kie.kogito.tracing.event.trace.TraceExecutionStepType) TraceExecutionStep(org.kie.kogito.tracing.event.trace.TraceExecutionStep)

Example 28 with EvaluateEvent

use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent 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);
}
Also used : TraceEventType(org.kie.kogito.tracing.event.trace.TraceEventType) TraceExecutionStepType(org.kie.kogito.tracing.event.trace.TraceExecutionStepType) Arrays(java.util.Arrays) DMNType(org.kie.dmn.api.core.DMNType) CloudEvent(io.cloudevents.CloudEvent) AFTER_EVALUATE_DECISION_SERVICE(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType.AFTER_EVALUATE_DECISION_SERVICE) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Deque(java.util.Deque) Function(java.util.function.Function) TraceExecutionStep(org.kie.kogito.tracing.event.trace.TraceExecutionStep) ArrayList(java.util.ArrayList) DecisionServiceNodeImpl(org.kie.dmn.core.ast.DecisionServiceNodeImpl) DMNModel(org.kie.dmn.api.core.DMNModel) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNBaseNode(org.kie.dmn.core.ast.DMNBaseNode) Map(java.util.Map) EvaluateDecisionResult(org.kie.kogito.tracing.decision.event.evaluate.EvaluateDecisionResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) InternalMessageType(org.kie.kogito.tracing.decision.message.InternalMessageType) Message(org.kie.kogito.tracing.event.message.Message) EvaluateEventType(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType) TraceEvent(org.kie.kogito.tracing.event.trace.TraceEvent) ConfigBean(org.kie.kogito.conf.ConfigBean) Logger(org.slf4j.Logger) DMNNode(org.kie.dmn.api.core.ast.DMNNode) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) TraceInputValue(org.kie.kogito.tracing.event.trace.TraceInputValue) TraceOutputValue(org.kie.kogito.tracing.event.trace.TraceOutputValue) Collection(java.util.Collection) EventUtils(org.kie.kogito.tracing.decision.event.EventUtils) Collectors(java.util.stream.Collectors) Pair(org.kie.dmn.feel.util.Pair) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue) Objects(java.util.Objects) List(java.util.List) TraceHeader(org.kie.kogito.tracing.event.trace.TraceHeader) Stream(java.util.stream.Stream) CloudEventUtils(org.kie.kogito.event.cloudevents.utils.CloudEventUtils) BEFORE_EVALUATE_DECISION_SERVICE(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType.BEFORE_EVALUATE_DECISION_SERVICE) Optional(java.util.Optional) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) EvaluateDecisionResult(org.kie.kogito.tracing.decision.event.evaluate.EvaluateDecisionResult) Message(org.kie.kogito.tracing.event.message.Message) HashMap(java.util.HashMap) TraceExecutionStep(org.kie.kogito.tracing.event.trace.TraceExecutionStep) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

EvaluateEvent (org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)28 Test (org.junit.jupiter.api.Test)17 TraceEvent (org.kie.kogito.tracing.event.trace.TraceEvent)16 CloudEvent (io.cloudevents.CloudEvent)15 List (java.util.List)10 Collections (java.util.Collections)9 Collectors (java.util.stream.Collectors)9 DMNModel (org.kie.dmn.api.core.DMNModel)9 EvaluateEventType (org.kie.kogito.tracing.decision.event.evaluate.EvaluateEventType)9 InternalMessageType (org.kie.kogito.tracing.decision.message.InternalMessageType)9 TraceEventType (org.kie.kogito.tracing.event.trace.TraceEventType)9 IOException (java.io.IOException)6 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)6 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)6 Assertions.assertSame (org.junit.jupiter.api.Assertions.assertSame)6 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)6 Assertions.fail (org.junit.jupiter.api.Assertions.fail)6 BeforeAll (org.junit.jupiter.api.BeforeAll)6 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)6 ArrayList (java.util.ArrayList)4