Search in sources :

Example 1 with TraceOutputValue

use of org.kie.kogito.tracing.event.trace.TraceOutputValue in project kogito-runtimes by kiegroup.

the class DefaultAggregator method traceOutputFrom.

private static TraceOutputValue traceOutputFrom(EvaluateDecisionResult decisionResult, DMNModel model, Map<String, Object> context) {
    DMNType type = Optional.ofNullable(model).map(m -> m.getDecisionById(decisionResult.getDecisionId())).map(DecisionNode::getResultType).orElse(null);
    // cast to DMNBaseNode here is required to have access to getDependencies method
    Map<String, DMNType> decisionInputTypes = Optional.ofNullable(model).map(m -> m.getDecisionById(decisionResult.getDecisionId())).filter(DMNBaseNode.class::isInstance).map(DMNBaseNode.class::cast).map(DMNBaseNode::getDependencies).map(deps -> deps.values().stream().map(DMNNode::getId).collect(Collectors.toList())).map(ids -> ids.stream().map(id -> typeAndNameOf(id, model)).filter(Objects::nonNull).collect(Collectors.toMap(Pair::getRight, Pair::getLeft))).orElseGet(HashMap::new);
    Map<String, TypedValue> decisionInputs = decisionInputTypes.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> EventUtils.typedValueFrom(e.getValue(), context.get(e.getKey()))));
    return new TraceOutputValue(decisionResult.getDecisionId(), decisionResult.getDecisionName(), decisionResult.getEvaluationStatus().name(), EventUtils.typedValueFrom(type, decisionResult.getResult()), decisionInputs, decisionResult.getMessages());
}
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) TraceOutputValue(org.kie.kogito.tracing.event.trace.TraceOutputValue) DMNBaseNode(org.kie.dmn.core.ast.DMNBaseNode) HashMap(java.util.HashMap) DMNNode(org.kie.dmn.api.core.ast.DMNNode) HashMap(java.util.HashMap) Map(java.util.Map) DMNType(org.kie.dmn.api.core.DMNType) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue)

Example 2 with TraceOutputValue

use of org.kie.kogito.tracing.event.trace.TraceOutputValue 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)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 EvaluateEvent (org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)2 TraceEvent (org.kie.kogito.tracing.event.trace.TraceEvent)2 TraceHeader (org.kie.kogito.tracing.event.trace.TraceHeader)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 CloudEvent (io.cloudevents.CloudEvent)1 URI (java.net.URI)1 ArrayDeque (java.util.ArrayDeque)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Deque (java.util.Deque)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1