Skip to content

Commit

Permalink
Merge pull request #77 from rgdoliveira/sync_main
Browse files Browse the repository at this point in the history
Sync main branch with Apache main branch
  • Loading branch information
rgdoliveira authored Sep 5, 2024
2 parents 4291186 + ee6a195 commit 5bb3d4f
Show file tree
Hide file tree
Showing 45 changed files with 776 additions and 736 deletions.
12 changes: 6 additions & 6 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
<version.commons-logging>1.1.1</version.commons-logging>
<version.commons-io>2.15.1</version.commons-io>
<version.common-text>1.11.0</version.common-text>
<version.com.fasterxml.jackson>2.16.1</version.com.fasterxml.jackson>
<version.com.fasterxml.jackson.databind>2.16.1</version.com.fasterxml.jackson.databind>
<version.com.fasterxml.jackson.annotations>2.16.1</version.com.fasterxml.jackson.annotations>
<version.com.fasterxml.jackson>2.17.2</version.com.fasterxml.jackson>
<version.com.fasterxml.jackson.databind>2.17.2</version.com.fasterxml.jackson.databind>
<version.com.fasterxml.jackson.annotations>2.17.2</version.com.fasterxml.jackson.annotations>
<version.com.github.victools>4.31.0</version.com.github.victools> <!-- victools should align with Jackson if possible -->
<version.com.miglayout>3.7.4</version.com.miglayout>
<version.domino-slf4j-logger>1.0.1</version.domino-slf4j-logger>
Expand All @@ -74,7 +74,7 @@
<version.guru.nidi>0.18.0</version.guru.nidi>
<version.info.picocli>4.7.5</version.info.picocli>
<version.io.micrometer>1.12.2</version.io.micrometer>
<version.io.quarkus>3.8.4</version.io.quarkus>
<version.io.quarkus>3.8.6</version.io.quarkus>
<version.io.smallrye.openapi.core>3.10.0</version.io.smallrye.openapi.core>
<version.it.unimi.dsi.fastutil>8.5.11</version.it.unimi.dsi.fastutil>
<version.junit>4.13.1</version.junit>
Expand All @@ -101,11 +101,11 @@
<version.org.hsqldb>2.3.0</version.org.hsqldb>
<version.org.infinispan>14.0.25.Final</version.org.infinispan>
<version.org.javassist>3.26.0-GA</version.org.javassist>
<version.org.jboss.narayana.tomcat>7.0.1.Final</version.org.jboss.narayana.tomcat>
<version.org.jboss.narayana.tomcat>7.0.2.Final</version.org.jboss.narayana.tomcat>
<version.org.jboss.logging>3.5.3.Final</version.org.jboss.logging>
<version.org.jboss.transaction.spi>8.0.0.Final</version.org.jboss.transaction.spi>
<version.org.jboss.weld.weld>3.1.6.Final</version.org.jboss.weld.weld>
<version.org.eclipse.microprofile.config>3.0.3</version.org.eclipse.microprofile.config>
<version.org.eclipse.microprofile.config>3.1</version.org.eclipse.microprofile.config>
<version.jakarta.enterprise.cdi-api>4.0.1</version.jakarta.enterprise.cdi-api>
<version.jakarta.activation>2.0.1</version.jakarta.activation>
<version.jakarta.activation-api>2.1.2</version.jakarta.activation-api>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ Alternatively, you can use `drools-metric` to expose the data using https://asci
Metrics.addRegitry(new JmxMeterRegistry(s -> null, Clock.SYSTEM));
----
+
If you want to use logging instead of Micrometer even though Micrometer is available in classpath, you can disable it by setting the system property `drools.metric.micrometer.disabled` to `true`.
+
Regardless of whether you want to use logging or Micrometer, you need to enable `MetricLogUtils` by setting the system property `drools.metric.logger.enabled` to `true`. Optionally, you can change the microseconds threshold of metric reporting by setting the `drools.metric.logger.threshold` system property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ public class MetricLogUtils {

public static final String METRIC_LOGGER_ENABLED = "drools.metric.logger.enabled";
private boolean enabled = Boolean.parseBoolean(getConfig(METRIC_LOGGER_ENABLED, "false"));

// Set true when you want to disable Micrometer even if it is available.
public static final String METRIC_MICROMETER_DISABLED = "drools.metric.micrometer.disabled";
private boolean micrometerDisabled = Boolean.parseBoolean(getConfig(METRIC_MICROMETER_DISABLED, "false"));

private boolean micrometerAvailable = isMicrometerAvailable();

public static final String METRIC_LOGGER_THRESHOLD = "drools.metric.logger.threshold";
private int threshold = Integer.parseInt(getConfig(METRIC_LOGGER_THRESHOLD, "500")); // microseconds

private final ThreadLocal<NodeStats> nodeStats = new ThreadLocal<>();

private static final MetricLogUtils INSTANCE = new MetricLogUtils();
private static MetricLogUtils INSTANCE = new MetricLogUtils();

private static boolean isMicrometerAvailable() {
try {
Expand Down Expand Up @@ -92,7 +97,7 @@ public void logAndEndMetrics() {
long elapsedTimeInNanos = (System.nanoTime() - stats.getStartTime());
long elapsedTimeInMicro = elapsedTimeInNanos / 1000;
if (evalCount > 0 && elapsedTimeInMicro > threshold) {
if (micrometerAvailable) {
if (micrometerAvailable && !micrometerDisabled) {
MicrometerUtils.INSTANCE.triggerMicrometer(stats.getNode(), evalCount, elapsedTimeInNanos);
} else { // Only log when Micrometer is not enabled.
logger.trace("{}, evalCount:{}, elapsedMicro:{}", stats.getNode(), evalCount, elapsedTimeInMicro);
Expand All @@ -105,4 +110,10 @@ public void logAndEndMetrics() {
}
}

/*
* This method is only used for testing purposes.
*/
public static void recreateInstance() {
MetricLogUtils.INSTANCE = new MetricLogUtils();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,4 @@ public void clearMeters() { // Remove meters we inserted without affecting those
MicrometerUtils.INSTANCE.clear();
registry = null;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.search.Search;
import org.drools.metric.util.MetricLogUtils;
import org.drools.mvel.compiler.Address;
import org.drools.mvel.compiler.Person;
import org.junit.Test;
Expand All @@ -39,6 +40,24 @@ public class MetricLogUtilsTest extends AbstractMetricTest {
@Test
public void testJoin() {

runJoinRules();

// 2 nodes expected
Collection<Timer> timers = Search.in(registry)
.name("org.drools.metric.elapsed.time.per.evaluation")
.timers();
assertThat(timers).hasSize(2);
Collection<Timer> timers2 = Search.in(registry)
.name("org.drools.metric.elapsed.time")
.timers();
assertThat(timers2).hasSize(2);
Collection<Counter> counters = Search.in(registry)
.name("org.drools.metric.evaluation.count")
.counters();
assertThat(counters).hasSize(2);
}

private void runJoinRules() {
String str =
"import " + Address.class.getCanonicalName() + "\n" +
"import " + Person.class.getCanonicalName() + "\n" +
Expand Down Expand Up @@ -67,20 +86,26 @@ public void testJoin() {
int fired = ksession.fireAllRules();
ksession.dispose();
assertThat(fired).isEqualTo(36);
}

// 2 nodes expected
Collection<Timer> timers = Search.in(registry)
.name("org.drools.metric.elapsed.time.per.evaluation")
.timers();
assertThat(timers).hasSize(2);
Collection<Timer> timers2 = Search.in(registry)
.name("org.drools.metric.elapsed.time")
.timers();
assertThat(timers2).hasSize(2);
Collection<Counter> counters = Search.in(registry)
.name("org.drools.metric.evaluation.count")
.counters();
assertThat(counters).hasSize(2);
@Test
public void micrometerDisabled() {

try {
System.setProperty(MetricLogUtils.METRIC_MICROMETER_DISABLED, "true");
MetricLogUtils.recreateInstance();

runJoinRules();

// Micrometer is disabled
Collection<Timer> timers = Search.in(registry)
.name("org.drools.metric.elapsed.time.per.evaluation")
.timers();
assertThat(timers).isEmpty();
} finally {
System.clearProperty(MetricLogUtils.METRIC_MICROMETER_DISABLED); // default is false
MetricLogUtils.recreateInstance();
}
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion drools-metric/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<logger name="org.kie" level="warn"/>
<logger name="org.drools" level="warn"/>

<!-- <logger name="org.drools.metric.util.MetricLogUtils" level="trace"/> -->
<logger name="org.drools.metric.util.MetricLogUtils" level="trace"/>

<root level="warn">
<appender-ref ref="consoleAppender" />
Expand Down
12 changes: 12 additions & 0 deletions kie-dmn/kie-dmn-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.societegenerale.commons</groupId>
<artifactId>arch-unit-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>sonarcloud-analysis</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ void testNestedImports(VariantTestConf conf) {
LOG.debug("{}", message);
}
LOG.debug("{}", evaluateModelCDecision);
assertThat(evaluateModelCDecision.getDecisionResults()).size().isEqualTo(3);
evaluateModelCDecision.getDecisionResults().forEach(dmnDecisionResult -> assertThat(dmnDecisionResult.getEvaluationStatus()).isEqualTo(SUCCEEDED));
assertThat(evaluateModelCDecision.getDecisionResults()).hasSize(3);
assertThat(evaluateModelCDecision.getDecisionResults()).allMatch(dmnDecisionResult -> dmnDecisionResult.getEvaluationStatus().equals(SUCCEEDED));
}

@ParameterizedTest
Expand Down Expand Up @@ -415,13 +415,11 @@ void wrongComparisonOps(VariantTestConf conf) {
assertThat(dmnModel.hasErrors()).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages())).isFalse();
assertThat(dmnModel.getMessages()).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages())).hasSize(4);
assertThat(dmnModel.getMessages(DMNMessage.Severity.WARN)).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages())).hasSize(4);
assertThat(dmnModel.getMessages(DMNMessage.Severity.WARN)
.stream()
.filter(m -> m.getSourceId().equals("_d72d6fab-1e67-4fe7-9c12-54800d6fe294") ||
assertThat(dmnModel.getMessages(DMNMessage.Severity.WARN)).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()))
.filteredOn(m -> m.getSourceId().equals("_d72d6fab-1e67-4fe7-9c12-54800d6fe294") ||
m.getSourceId().equals("_2390dd99-094d-4f97-aecc-9cccb697ce05") ||
m.getSourceId().equals("_0c292d34-498e-4b08-ae99-3c694197b69f") ||
m.getSourceId().equals("_21c7d800-b806-4b2e-9a10-00828de7f2d2"))
.count()).as(DMNRuntimeUtil.formatMessages(dmnModel.getMessages())).isEqualTo(4L);
m.getSourceId().equals("_21c7d800-b806-4b2e-9a10-00828de7f2d2")).hasSize(4);
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.slf4j.LoggerFactory;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;

public class DMNMessagesAPITest {

Expand Down Expand Up @@ -72,7 +72,7 @@ void apiUsage() {

@Test
void apiUsageSnippetForDocumentation() {
assertThrows(IllegalStateException.class, () -> {
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
KieServices ks = KieServices.Factory.get();

ReleaseId releaseId = ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
import org.slf4j.LoggerFactory;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
import static org.kie.dmn.core.util.DMNTestUtil.getAndAssertModelNoErrors;
import static org.kie.dmn.core.util.DynamicTypeUtils.entry;
import static org.kie.dmn.core.util.DynamicTypeUtils.mapOf;
Expand Down Expand Up @@ -3136,7 +3136,7 @@ void functionDefinitionParameterTrailingSpace(boolean useExecModelCompiler) {
@MethodSource("params")
void evaluateByNameWithEmptyParam(boolean useExecModelCompiler) {
init(useExecModelCompiler);
assertThrows(IllegalArgumentException.class, () -> {
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("simple-item-def.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn/itemdef", "simple-item-def");
assertThat(dmnModel).isNotNull();
Expand All @@ -3154,7 +3154,7 @@ void evaluateByNameWithEmptyParam(boolean useExecModelCompiler) {
@MethodSource("params")
void evaluateByIdWithEmptyParam(boolean useExecModelCompiler) {
init(useExecModelCompiler);
assertThrows(IllegalArgumentException.class, () -> {
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("simple-item-def.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn/itemdef", "simple-item-def");
assertThat(dmnModel).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
import org.kie.dmn.core.util.DMNRuntimeUtil;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class DMNContextEvaluatorTest {

Expand Down Expand Up @@ -74,8 +72,8 @@ void dateToDateTime() {
DMNResultImpl result = createResult(dmnModel, context );
DMNExpressionEvaluator evaluator = ed.getEvaluator();
EvaluatorResult evaluated = evaluator.evaluate(runtime, result);
assertNotNull(evaluated);
assertEquals(EvaluatorResult.ResultType.SUCCESS, evaluated.getResultType());
assertThat(evaluated).isNotNull();
assertThat(evaluated.getResultType()).isEqualTo(EvaluatorResult.ResultType.SUCCESS);
}

private DMNResultImpl createResult(DMNModel model, DMNContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.kie.dmn.model.v1_5.TInformationRequirement;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;

class DMNCompilerImplTest {

Expand Down Expand Up @@ -70,7 +70,7 @@ void getRootElement() {

InformationRequirement informationRequirement = new TInformationRequirement();
elementReference.setParent(informationRequirement);
assertThrows(RuntimeException.class, () -> DMNCompilerImpl.getRootElement(elementReference));
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> DMNCompilerImpl.getRootElement(elementReference));

informationRequirement.setParent(parent);
retrieved = DMNCompilerImpl.getRootElement(elementReference);
Expand Down
Loading

0 comments on commit 5bb3d4f

Please sign in to comment.