From ef4671f2b4c78b70cf6342de964664a27e28b7e0 Mon Sep 17 00:00:00 2001 From: Gabriele Cardosi Date: Mon, 27 May 2024 09:16:06 +0200 Subject: [PATCH] [incubator-kie-issues#1263] Enable conditional debug logging for jitexecutor-bpmn. (#2063) Co-authored-by: Gabriele-Cardosi --- jitexecutor/README.md | 13 +++++++++ jitexecutor/jitexecutor-bpmn/README.md | 29 +++++++++++++++++++ jitexecutor/jitexecutor-bpmn/pom.xml | 27 +++++++++++++++++ .../application.properties | 2 ++ .../bpmn/api/BPMNValidationResource.java | 10 +++++++ .../kogito/jitexecutor/common/Constants.java | 27 +++++++++++++++++ jitexecutor/jitexecutor-dmn/README.md | 4 +-- jitexecutor/jitexecutor-dmn/pom.xml | 2 +- .../filtered-resources/application.properties | 2 +- .../dmn/api/DMNValidationResource.java | 4 +-- .../jitexecutor/dmn/api/JITDMNResource.java | 2 +- .../jitexecutor/dmn/api/SchemaResource.java | 10 +++++++ .../kie/kogito/jitexecutor/dmn/DMN15Test.java | 12 ++++---- 13 files changed, 131 insertions(+), 13 deletions(-) create mode 100644 jitexecutor/jitexecutor-bpmn/README.md rename jitexecutor/jitexecutor-bpmn/src/main/{resources => filtered-resources}/application.properties (94%) create mode 100644 jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/Constants.java diff --git a/jitexecutor/README.md b/jitexecutor/README.md index bcb41dce29..a5fbcde119 100644 --- a/jitexecutor/README.md +++ b/jitexecutor/README.md @@ -34,6 +34,19 @@ run the generated application under `jitexecutor-runner/target/quarkus-app/` wit java -jar jitexecutor-runner/target/quarkus-app/quarkus-run.jar ``` +Log configuration +================= + +Rest endpoints have log configuration to eventually print out received payload, if log is set to DEBUG level (default is INFO). +This is managed in the application.properties, that is under filtered-resources. +The `quarkus.log.category."org.kie.kogito".level` is set from `${jitexecutor.log.level}`, that by default is "INFO" in the pom.xml. + +It can be overridden with commandline parameter, e.g. + +```bash +mvn clean package -Djitexecutor.log.level=DEBUG +``` + DMN === diff --git a/jitexecutor/jitexecutor-bpmn/README.md b/jitexecutor/jitexecutor-bpmn/README.md new file mode 100644 index 0000000000..09ae6c871d --- /dev/null +++ b/jitexecutor/jitexecutor-bpmn/README.md @@ -0,0 +1,29 @@ + +# Kogito JIT BPMN Executor + +## Log configuration + +Rest endpoints have log configuration to eventually print out received payload, if log is set to DEBUG level (default is INFO). +This is managed in the application.properties, that is under filtered-resources. +The `quarkus.log.category."org.kie.kogito".level` is set from `${jitexecutor.log.level}`, that by default is "INFO" in the pom.xml. + +It can be overridden with commandline parameter, e.g. + +`mvn clean package -Djitexecutor.log.level=DEBUG` diff --git a/jitexecutor/jitexecutor-bpmn/pom.xml b/jitexecutor/jitexecutor-bpmn/pom.xml index ba267ce747..21b1482580 100644 --- a/jitexecutor/jitexecutor-bpmn/pom.xml +++ b/jitexecutor/jitexecutor-bpmn/pom.xml @@ -34,6 +34,7 @@ org.kie.kogito.jitexecutor.bpmn + INFO @@ -88,4 +89,30 @@ + + + + maven-resources-plugin + + + copy-filtered-resources + process-resources + + copy-resources + + + ${project.build.directory}/classes + + + ${project.basedir}/src/main/filtered-resources + true + + + + + + + + + \ No newline at end of file diff --git a/jitexecutor/jitexecutor-bpmn/src/main/resources/application.properties b/jitexecutor/jitexecutor-bpmn/src/main/filtered-resources/application.properties similarity index 94% rename from jitexecutor/jitexecutor-bpmn/src/main/resources/application.properties rename to jitexecutor/jitexecutor-bpmn/src/main/filtered-resources/application.properties index f43a8a1a7d..a04127cb86 100644 --- a/jitexecutor/jitexecutor-bpmn/src/main/resources/application.properties +++ b/jitexecutor/jitexecutor-bpmn/src/main/filtered-resources/application.properties @@ -24,5 +24,7 @@ # quarkus.log.category."org".level=INFO +quarkus.log.category."org.kie.kogito".level=${jitexecutor.log.level} + # To avoid errors such as: # Error: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved type during parsing: (full_name_of_the_class). To diagnose the issue you can use the --allow-incomplete-classpath option. The missing type is then reported at run time when it is accessed the first time. \ No newline at end of file diff --git a/jitexecutor/jitexecutor-bpmn/src/main/java/org/kie/kogito/jitexecutor/bpmn/api/BPMNValidationResource.java b/jitexecutor/jitexecutor-bpmn/src/main/java/org/kie/kogito/jitexecutor/bpmn/api/BPMNValidationResource.java index aa28edef93..96e8ec7d31 100644 --- a/jitexecutor/jitexecutor-bpmn/src/main/java/org/kie/kogito/jitexecutor/bpmn/api/BPMNValidationResource.java +++ b/jitexecutor/jitexecutor-bpmn/src/main/java/org/kie/kogito/jitexecutor/bpmn/api/BPMNValidationResource.java @@ -21,6 +21,8 @@ import org.kie.kogito.jitexecutor.bpmn.JITBPMNService; import org.kie.kogito.jitexecutor.bpmn.responses.JITBPMNValidationResult; import org.kie.kogito.jitexecutor.common.requests.MultipleResourcesPayload; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import jakarta.inject.Inject; import jakarta.ws.rs.Consumes; @@ -30,9 +32,13 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; +import static org.kie.kogito.jitexecutor.common.Constants.LINEBREAK; + @Path("jitbpmn/validate") public class BPMNValidationResource { + private static final Logger LOGGER = LoggerFactory.getLogger(BPMNValidationResource.class); + @Inject JITBPMNService jitbpmnService; @@ -40,6 +46,10 @@ public class BPMNValidationResource { @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response schema(MultipleResourcesPayload payload) { + LOGGER.debug(LINEBREAK); + LOGGER.debug("jitbpmn/validate"); + LOGGER.debug(payload.toString()); + LOGGER.debug(LINEBREAK); JITBPMNValidationResult result = jitbpmnService.validatePayload(payload); return Response.ok(result.getErrors()).build(); } diff --git a/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/Constants.java b/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/Constants.java new file mode 100644 index 0000000000..ed8079006b --- /dev/null +++ b/jitexecutor/jitexecutor-common/src/main/java/org/kie/kogito/jitexecutor/common/Constants.java @@ -0,0 +1,27 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.kie.kogito.jitexecutor.common; + +public class Constants { + + public static final String LINEBREAK = "******\n"; + + private Constants() { + } +} \ No newline at end of file diff --git a/jitexecutor/jitexecutor-dmn/README.md b/jitexecutor/jitexecutor-dmn/README.md index d766a0da4a..a814beedc6 100644 --- a/jitexecutor/jitexecutor-dmn/README.md +++ b/jitexecutor/jitexecutor-dmn/README.md @@ -22,8 +22,8 @@ Rest endpoints have log configuration to eventually print out received payload, if log is set to DEBUG level (default is INFO). This is managed in the application.properties, that is under filtered-resources. -The `quarkus.log.category."org.kie.kogito".level` is set from `${jitexecutor.dmn.log.level}`, that by default is "INFO" in the pom.xml. +The `quarkus.log.category."org.kie.kogito".level` is set from `${jitexecutor.log.level}`, that by default is "INFO" in the pom.xml. It can be overridden with commandline parameter, e.g. -`mvn clean package -Djitexecutor.dmn.log.level=DEBUG` +`mvn clean package -Djitexecutor.log.level=DEBUG` diff --git a/jitexecutor/jitexecutor-dmn/pom.xml b/jitexecutor/jitexecutor-dmn/pom.xml index daffe13ebb..f38b164c83 100644 --- a/jitexecutor/jitexecutor-dmn/pom.xml +++ b/jitexecutor/jitexecutor-dmn/pom.xml @@ -32,7 +32,7 @@ org.kie.kogito.jitexecutor.dmn - INFO + INFO diff --git a/jitexecutor/jitexecutor-dmn/src/main/filtered-resources/application.properties b/jitexecutor/jitexecutor-dmn/src/main/filtered-resources/application.properties index ea64431551..cf51111ccf 100644 --- a/jitexecutor/jitexecutor-dmn/src/main/filtered-resources/application.properties +++ b/jitexecutor/jitexecutor-dmn/src/main/filtered-resources/application.properties @@ -24,7 +24,7 @@ # quarkus.log.category."org".level=INFO -quarkus.log.category."org.kie.kogito".level=${jitexecutor.dmn.log.level} +quarkus.log.category."org.kie.kogito".level=${jitexecutor.log.level} # To avoid errors such as: # Error: com.oracle.graal.pointsto.constraints.UnresolvedElementException: Discovered unresolved type during parsing: org.kie.pmml.pmml_4_2.PMMLRequestDataBuilder. To diagnose the issue you can use the --allow-incomplete-classpath option. The missing type is then reported at run time when it is accessed the first time. diff --git a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidationResource.java b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidationResource.java index fd2a31e0b8..daa5208ff2 100644 --- a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidationResource.java +++ b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/DMNValidationResource.java @@ -45,13 +45,13 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; +import static org.kie.kogito.jitexecutor.common.Constants.LINEBREAK; + @Path("jitdmn/validate") public class DMNValidationResource { private static final Logger LOGGER = LoggerFactory.getLogger(DMNValidationResource.class); - static final String LINEBREAK = "******\n"; - // trick for resolver/implementation for NI static final DMNValidator validator = DMNValidatorFactory.newValidator(List.of(new ExtendedDMNProfile())); diff --git a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/JITDMNResource.java b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/JITDMNResource.java index b99739c54d..69d4eb8b87 100644 --- a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/JITDMNResource.java +++ b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/JITDMNResource.java @@ -38,7 +38,7 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; -import static org.kie.kogito.jitexecutor.dmn.api.DMNValidationResource.LINEBREAK; +import static org.kie.kogito.jitexecutor.common.Constants.LINEBREAK; @Path("/jitdmn") public class JITDMNResource { diff --git a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/SchemaResource.java b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/SchemaResource.java index b769aaa387..b1ce72029c 100644 --- a/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/SchemaResource.java +++ b/jitexecutor/jitexecutor-dmn/src/main/java/org/kie/kogito/jitexecutor/dmn/api/SchemaResource.java @@ -33,6 +33,8 @@ import org.kie.dmn.openapi.model.DMNOASResult; import org.kie.kogito.jitexecutor.common.requests.MultipleResourcesPayload; import org.kie.kogito.jitexecutor.dmn.DMNEvaluator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -46,9 +48,13 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; +import static org.kie.kogito.jitexecutor.common.Constants.LINEBREAK; + @Path("jitdmn/schema") public class SchemaResource { + private static final Logger LOGGER = LoggerFactory.getLogger(SchemaResource.class); + // trick for resolver/implementation for NI static final OpenAPI x; static Schema resourceWithURI; @@ -65,6 +71,10 @@ public class SchemaResource { @Consumes(MediaType.APPLICATION_XML) @Produces(MediaType.APPLICATION_JSON) public Response schema(String payload) { + LOGGER.debug(LINEBREAK); + LOGGER.debug("jitdmn/validate"); + LOGGER.debug(payload); + LOGGER.debug(LINEBREAK); DMNModel dmnModel = DMNEvaluator.fromXML(payload).getDmnModel(); DMNOASResult oasResult = DMNOASGeneratorFactory.generator(Collections.singletonList(dmnModel)).build(); return fullSchema(dmnModel, oasResult, true); diff --git a/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMN15Test.java b/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMN15Test.java index 8c017a0289..de57938129 100644 --- a/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMN15Test.java +++ b/jitexecutor/jitexecutor-dmn/src/test/java/org/kie/kogito/jitexecutor/dmn/DMN15Test.java @@ -80,7 +80,7 @@ void collectionTypeConstraintSucceed() throws IOException { Map context = Map.of("p1", Map.of("Name", "P3", "Interests", Arrays.asList("Ski"))); JITDMNPayload jitdmnpayload = new JITDMNPayload(modelRef, List.of(model), - context); + context); given() .contentType(ContentType.JSON) .body(jitdmnpayload) @@ -97,7 +97,7 @@ void collectionTypeConstraintFails() throws IOException { Map context = Map.of("p1", Map.of("Name", "P3", "Interests", Arrays.asList("Ski", "Golf"))); JITDMNPayload jitdmnpayload = new JITDMNPayload(modelRef, List.of(model), - context); + context); given() .contentType(ContentType.JSON) .body(jitdmnpayload) @@ -114,7 +114,7 @@ void collectionAllowedValuesSucceed() throws IOException { Map context = Map.of("p1", Map.of("Name", "P3", "Interests", Arrays.asList("Golf"))); JITDMNPayload jitdmnpayload = new JITDMNPayload(modelRef, List.of(model), - context); + context); given() .contentType(ContentType.JSON) .body(jitdmnpayload) @@ -126,7 +126,7 @@ void collectionAllowedValuesSucceed() throws IOException { context = Map.of("p1", Map.of("Name", "P3", "Interests", Arrays.asList("Golf", "Jogging"))); jitdmnpayload = new JITDMNPayload(modelRef, List.of(model), - context); + context); given() .contentType(ContentType.JSON) .body(jitdmnpayload) @@ -143,7 +143,7 @@ void collectionAllowedValuesFails() throws IOException { Map context = Map.of("p1", Map.of("Name", "P3", "Interests", Arrays.asList("Ski"))); JITDMNPayload jitdmnpayload = new JITDMNPayload(modelRef, List.of(model), - context); + context); given() .contentType(ContentType.JSON) .body(jitdmnpayload) @@ -213,7 +213,7 @@ private void commonUnnamedImport(String importingModelRef, String importedModelR Map context = Map.of("A Person", Map.of("name", "John", "age", 47)); JITDMNPayload jitdmnpayload = new JITDMNPayload(importingModelRef, List.of(model1, model2), - context); + context); given() .contentType(ContentType.JSON) .body(jitdmnpayload)