From 2a7efed53b1995ca8f339968a42fdd049cf3ab94 Mon Sep 17 00:00:00 2001 From: Michal Somora Date: Wed, 25 Oct 2023 13:14:30 +0200 Subject: [PATCH] validate deprecated configuration --- extensions/log/README.md | 19 +++++++++++++++- .../tkit/quarkus/log/cdi/LogProcessor.java | 16 ++++++++++++++ .../log/cdi/test/LogProcessorTest.java | 22 +++++++++++++++++++ .../src/test/resources/deprecated.properties | 1 + 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/LogProcessorTest.java create mode 100644 extensions/log/cdi/deployment/src/test/resources/deprecated.properties diff --git a/extensions/log/README.md b/extensions/log/README.md index 17e0353..ecca398 100644 --- a/extensions/log/README.md +++ b/extensions/log/README.md @@ -3,4 +3,21 @@ This group of the extension contains several interceptors implementation and uti * [cdi](cdi) - Quarkus extension for CDI method logging(business method start/stop logging). * [rs](rs) - Quarkus extension for HTTP request logging (client & server). -* [json](json) - Custom JSON log formatter that provides additional features \ No newline at end of file +* [json](json) - Custom JSON log formatter that provides additional features + + +Migration configration from old tkit library + +| old quarkus.tkit config | new tkit config | +|-----------------------------------------|-----------------| +| quarkus.tkit.log.console.json | tkit.log.json.enabled | +| quarkus.tkit.log.console.json.keys.type | tkit.log.json.keys.type | +| quarkus.tkit.log.console.json.keys.mdc | tkit.log.json.keys.mdc | +|quarkus.tkit.log.console.json.keys.ignore| tkit.log.json.keys.ignore| +|quarkus.tkit.log.console.json.keys.override| tkit.log.json.keys.override| +|quarkus.tkit.log.console.json.keys.env | tkit.log.json.keys.env| +|quarkus.tkit.log.console.json.keys.group| tkit.log.json.keys.group| +|quarkus.tkit.log.customdata.prefix | tkit.log.cdi.custom-data.prefix| +|quarkus.tkit.log.ignore.pattern | tkit.log.cdi.auto-discovery.ignore.pattern| +|quarkus.tkit.log.mdc.errorKey | tkit.log.cdi.mdc.errorKey| +``` \ No newline at end of file diff --git a/extensions/log/cdi/deployment/src/main/java/org/tkit/quarkus/log/cdi/LogProcessor.java b/extensions/log/cdi/deployment/src/main/java/org/tkit/quarkus/log/cdi/LogProcessor.java index 686e207..569897a 100644 --- a/extensions/log/cdi/deployment/src/main/java/org/tkit/quarkus/log/cdi/LogProcessor.java +++ b/extensions/log/cdi/deployment/src/main/java/org/tkit/quarkus/log/cdi/LogProcessor.java @@ -11,11 +11,13 @@ import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.RequestScoped; import javax.inject.Singleton; +import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.jandex.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,6 +31,7 @@ import io.quarkus.arc.processor.BuildExtension; import io.quarkus.deployment.annotations.*; import io.quarkus.deployment.annotations.Record; +import io.quarkus.deployment.builditem.ConfigPropertiesBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; import io.quarkus.deployment.builditem.RuntimeConfigSetupCompleteBuildItem; @@ -222,6 +225,19 @@ private boolean matchesIgnorePattern(String name) { }); } + @BuildStep + public ConfigPropertiesBuildItem validateDeprecatedConfiguration() { + Set quarkusTkitConfigNames = StreamSupport + .stream(ConfigProvider.getConfig().getPropertyNames().spliterator(), false) + .filter(s -> s.startsWith("quarkus.tkit")).collect(Collectors.toSet()); + if (!quarkusTkitConfigNames.isEmpty()) { + throw new IllegalArgumentException( + "Configuration with prefix quarkus.tkit are deprecated : " + quarkusTkitConfigNames + + " . You can find new configuration mapping on https://github.com/1000kit/tkit-quarkus/tree/main/extensions/log"); + } + return null; + } + private static LogService createLogService(AnnotationInstance annotationInstance) { return new LogService() { diff --git a/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/LogProcessorTest.java b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/LogProcessorTest.java new file mode 100644 index 0000000..b538d41 --- /dev/null +++ b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/LogProcessorTest.java @@ -0,0 +1,22 @@ +package org.tkit.quarkus.log.cdi.test; + +import io.quarkus.test.QuarkusUnitTest; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +public class LogProcessorTest { + + @RegisterExtension + static final QuarkusUnitTest config = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addAsResource("deprecated.properties", "application.properties")) + .setExpectedException(IllegalArgumentException.class, true); + + @Test + public void testPersistenceAndConfigTest() { + // should not be called, validation of deprecated configuration must fail + Assertions.fail(); + } + +} diff --git a/extensions/log/cdi/deployment/src/test/resources/deprecated.properties b/extensions/log/cdi/deployment/src/test/resources/deprecated.properties new file mode 100644 index 0000000..55c6243 --- /dev/null +++ b/extensions/log/cdi/deployment/src/test/resources/deprecated.properties @@ -0,0 +1 @@ +quarkus.tkit.log.packages=de.telekom \ No newline at end of file