use of org.kie.kogito.tracing.event.trace.TraceEvent in project kogito-runtimes by kiegroup.
the class DefaultAggregatorTest method testAggregateOnEvaluateAllWithListWithMissingLastAfterEvaluateDecisionEventReturnsNoExecutionStepHierarchy.
@Test
void testAggregateOnEvaluateAllWithListWithMissingLastAfterEvaluateDecisionEventReturnsNoExecutionStepHierarchy() throws IOException {
final DefaultAggregator aggregator = new DefaultAggregator();
final List<EvaluateEvent> events = DecisionTracingTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_ALL_JSON_RESOURCE).stream().filter(e -> !(e.getType() == EvaluateEventType.AFTER_EVALUATE_DECISION && LAST_DECISION_NODE_ID.equals(e.getNodeId()))).collect(Collectors.toList());
CloudEvent cloudEvent = aggregator.aggregate(model, EVALUATE_ALL_EXECUTION_ID, events, configBean).orElseThrow(IllegalStateException::new);
TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_ALL_EXECUTION_ID);
assertTraceEventWithNoExecutionStepsHierarchy(traceEvent, 2, 2, 5);
}
use of org.kie.kogito.tracing.event.trace.TraceEvent in project kogito-runtimes by kiegroup.
the class DefaultAggregatorTest method testAggregateOnEvaluateDecisionServiceWithNullModelReturnsDmnModelNotFound.
@Test
void testAggregateOnEvaluateDecisionServiceWithNullModelReturnsDmnModelNotFound() throws IOException {
final DefaultAggregator aggregator = new DefaultAggregator();
List<EvaluateEvent> events = DecisionTracingTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_DECISION_SERVICE_JSON_RESOURCE);
CloudEvent cloudEvent = aggregator.aggregate(null, EVALUATE_DECISION_SERVICE_EXECUTION_ID, events, configBean).orElseThrow(IllegalStateException::new);
TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_DECISION_SERVICE_EXECUTION_ID);
assertTraceEvent(traceEvent, 1, 1, 1);
assertTraceEventInternalMessage(traceEvent, InternalMessageType.DMN_MODEL_NOT_FOUND);
}
use of org.kie.kogito.tracing.event.trace.TraceEvent in project kogito-runtimes by kiegroup.
the class DefaultAggregatorTest method testAggregateOnEvaluateDecisionServiceWithListWithMissingBeforeEvaluateDecisionEventReturnsNoExecutionStepHierarchy.
@Test
void testAggregateOnEvaluateDecisionServiceWithListWithMissingBeforeEvaluateDecisionEventReturnsNoExecutionStepHierarchy() throws IOException {
final DefaultAggregator aggregator = new DefaultAggregator();
final List<EvaluateEvent> events = DecisionTracingTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_DECISION_SERVICE_JSON_RESOURCE).stream().filter(e -> !(e.getType() == EvaluateEventType.BEFORE_EVALUATE_DECISION && DECISION_SERVICE_DECISION_ID.equals(e.getNodeId()))).collect(Collectors.toList());
CloudEvent cloudEvent = aggregator.aggregate(model, EVALUATE_DECISION_SERVICE_EXECUTION_ID, events, configBean).orElseThrow(IllegalStateException::new);
TraceEvent traceEvent = assertValidCloudEventAndGetData(cloudEvent, EVALUATE_DECISION_SERVICE_EXECUTION_ID);
assertTraceEventWithNoExecutionStepsHierarchy(traceEvent, 1, 1, 3);
}
use of org.kie.kogito.tracing.event.trace.TraceEvent 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);
}
use of org.kie.kogito.tracing.event.trace.TraceEvent in project kogito-runtimes by kiegroup.
the class BaseQuarkusDecisionTracingTest method testCollector.
private void testCollector(List<EvaluateEvent> events, DecisionModel model) throws IOException {
AssertSubscriber<String> subscriber = AssertSubscriber.create(1);
final DecisionModels mockedDecisionModels = mock(DecisionModels.class);
when(mockedDecisionModels.getDecisionModel(getTestModelNameSpace(), getTestModelName())).thenReturn(model);
final Application mockedApplication = mock(Application.class);
when(mockedApplication.get(any())).thenReturn(mockedDecisionModels);
final ConfigBean configBean = new StaticConfigBean(TEST_SERVICE_URL, true, null);
final QuarkusTraceEventEmitter eventEmitter = new QuarkusTraceEventEmitter();
QuarkusDecisionTracingCollector collector = new QuarkusDecisionTracingCollector(eventEmitter, configBean, mockedApplication);
eventEmitter.getEventPublisher().subscribe(subscriber);
events.forEach(collector::onEvent);
subscriber.assertNotTerminated();
List<String> items = subscriber.getItems();
assertEquals(1, items.size());
CloudEvent cloudEvent = CloudEventUtils.decode(items.get(0)).orElseThrow(() -> new IllegalStateException("Can't decode CloudEvent"));
assertEquals(TEST_EXECUTION_ID, cloudEvent.getId());
assertNotNull(cloudEvent.getData());
TraceEvent traceEvent = MAPPER.readValue(cloudEvent.getData().toBytes(), TraceEvent.class);
assertNotNull(traceEvent);
assertEquals(TEST_SERVICE_URL, traceEvent.getHeader().getResourceId().getServiceUrl());
}
Aggregations