use of org.kie.kogito.tracing.event.trace.TraceEvent in project kogito-runtimes by kiegroup.
the class DefaultAggregatorTest method testAggregateOnEvaluateAllWithListWithMissingFirstAfterEvaluateDecisionEventReturnsNoExecutionStepHierarchy.
@Test
void testAggregateOnEvaluateAllWithListWithMissingFirstAfterEvaluateDecisionEventReturnsNoExecutionStepHierarchy() 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 && FIRST_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 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);
}
use of org.kie.kogito.tracing.event.trace.TraceEvent in project kogito-runtimes by kiegroup.
the class DefaultAggregator method buildNotEnoughDataCloudEvent.
private static Optional<CloudEvent> buildNotEnoughDataCloudEvent(DMNModel model, String executionId, ConfigBean configBean) {
TraceHeader header = new TraceHeader(TraceEventType.DMN, executionId, null, null, null, EventUtils.traceResourceIdFrom(configBean.getServiceUrl(), model), Stream.of(EventUtils.messageFrom(InternalMessageType.NOT_ENOUGH_DATA), model == null ? EventUtils.messageFrom(InternalMessageType.DMN_MODEL_NOT_FOUND) : null).filter(Objects::nonNull).collect(Collectors.toList()));
TraceEvent event = new TraceEvent(header, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
return CloudEventUtils.build(executionId, buildSource(configBean.getServiceUrl(), null), event, TraceEvent.class);
}
use of org.kie.kogito.tracing.event.trace.TraceEvent in project kogito-runtimes by kiegroup.
the class BaseSpringBootDecisionTracingTest method testCollector.
@SuppressWarnings("unchecked")
private void testCollector(List<EvaluateEvent> events, DecisionModel model) throws IOException {
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 KafkaTemplate<String, String> mockedTemplate = mock(KafkaTemplate.class);
final SpringBootTraceEventEmitter eventEmitter = new SpringBootTraceEventEmitter(mockedTemplate, TEST_KAFKA_TOPIC);
SpringBootDecisionTracingCollector collector = new SpringBootDecisionTracingCollector(eventEmitter, configBean, mockedApplication);
events.forEach(collector::onApplicationEvent);
ArgumentCaptor<String> payloadCaptor = ArgumentCaptor.forClass(String.class);
verify(mockedTemplate).send(eq(TEST_KAFKA_TOPIC), payloadCaptor.capture());
CloudEvent cloudEvent = CloudEventUtils.decode(payloadCaptor.getValue()).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());
}
use of org.kie.kogito.tracing.event.trace.TraceEvent in project kogito-runtimes by kiegroup.
the class DefaultAggregatorTest method testAggregateOnEvaluateAllWithListWithOnlyFirstEventReturnsNoExecutionSteps.
@Test
void testAggregateOnEvaluateAllWithListWithOnlyFirstEventReturnsNoExecutionSteps() throws IOException {
final DefaultAggregator aggregator = new DefaultAggregator();
final List<EvaluateEvent> events = DecisionTracingTestUtils.readEvaluateEventsFromJsonResource(EVALUATE_ALL_JSON_RESOURCE).stream().limit(1).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);
assertTraceEvent(traceEvent, 2, 2, 0);
}
Aggregations