Search in sources :

Example 11 with EvaluateEvent

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

the class DefaultAggregatorTest method testAggregateOnEvaluateDecisionServiceWithValidListReturnsWorking.

@Test
void testAggregateOnEvaluateDecisionServiceWithValidListReturnsWorking() throws IOException {
    final DefaultAggregator aggregator = new DefaultAggregator();
    List<EvaluateEvent> events = DecisionTracingTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_DECISION_SERVICE_JSON_RESOURCE);
    CloudEvent cloudEvent = aggregator.aggregate(model, EVALUATE_DECISION_SERVICE_EXECUTION_ID, events, configBean).orElseThrow(IllegalStateException::new);
    TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_DECISION_SERVICE_EXECUTION_ID);
    assertTraceEvent(traceEvent, 1, 1, 1);
}
Also used : CloudEvent(io.cloudevents.CloudEvent) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) TraceEvent(org.kie.kogito.tracing.event.trace.TraceEvent) Test(org.junit.jupiter.api.Test)

Example 12 with EvaluateEvent

use of org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent 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);
}
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) HashMap(java.util.HashMap) TraceExecutionStep(org.kie.kogito.tracing.event.trace.TraceExecutionStep) JsonNode(com.fasterxml.jackson.databind.JsonNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode)

Example 13 with EvaluateEvent

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

the class BaseQuarkusDecisionTracingTest method testAsyncListenerAndCollectorWithRealEventsIsWorking.

@Test
void testAsyncListenerAndCollectorWithRealEventsIsWorking() throws IOException {
    final DMNRuntime runtime = buildDMNRuntime();
    final DecisionModel model = buildDecisionModel(runtime);
    final List<EvaluateEvent> events = testListener(true, runtime, model);
    assertEquals(getEvaluationEventCount(), events.size());
    testCollector(events, model);
}
Also used : DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) Test(org.junit.jupiter.api.Test)

Example 14 with EvaluateEvent

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

the class BaseQuarkusDecisionTracingTest method testSyncListenerAndCollectorWithRealEventsIsWorking.

@Test
void testSyncListenerAndCollectorWithRealEventsIsWorking() throws IOException {
    final DMNRuntime runtime = buildDMNRuntime();
    final DecisionModel model = buildDecisionModel(runtime);
    final List<EvaluateEvent> events = testListener(false, runtime, model);
    assertEquals(getEvaluationEventCount(), events.size());
    testCollector(events, model);
}
Also used : DecisionModel(org.kie.kogito.decision.DecisionModel) DmnDecisionModel(org.kie.kogito.dmn.DmnDecisionModel) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent) Test(org.junit.jupiter.api.Test)

Example 15 with EvaluateEvent

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

the class BaseQuarkusDecisionTracingTest method testListener.

private List<EvaluateEvent> testListener(boolean asyncEnabled, DMNRuntime runtime, DecisionModel model) {
    final EventBus mockedEventBus = mock(EventBus.class);
    final QuarkusDecisionTracingCollector mockedCollector = mock(QuarkusDecisionTracingCollector.class);
    QuarkusDecisionTracingListener listener = new QuarkusDecisionTracingListener(mockedEventBus, mockedCollector, asyncEnabled);
    runtime.addListener(listener);
    final DMNContext context = model.newContext(getContextVariables());
    model.evaluateAll(context);
    ArgumentCaptor<EvaluateEvent> eventCaptor = ArgumentCaptor.forClass(EvaluateEvent.class);
    if (asyncEnabled) {
        verify(mockedEventBus, times(getEvaluationEventCount())).send(eq("kogito-tracing-decision_EvaluateEvent"), eventCaptor.capture());
        verify(mockedCollector, never()).onEvent(any());
    } else {
        verify(mockedEventBus, never()).send(eq("kogito-tracing-decision_EvaluateEvent"), any());
        verify(mockedCollector, times(getEvaluationEventCount())).onEvent(eventCaptor.capture());
    }
    return eventCaptor.getAllValues();
}
Also used : DMNContext(org.kie.dmn.api.core.DMNContext) EventBus(io.vertx.core.eventbus.EventBus) EvaluateEvent(org.kie.kogito.tracing.decision.event.evaluate.EvaluateEvent)

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