This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch camel-main in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 0e992834d8e06a71c786464989414dfdf4be0acc Author: James Netherton <jamesnether...@gmail.com> AuthorDate: Wed Jul 3 15:42:05 2024 +0100 Add type converter configuration --- docs/modules/ROOT/pages/reference/extensions/core.adoc | 6 ++++++ .../camel/quarkus/core/deployment/CamelProcessor.java | 4 +++- .../java/org/apache/camel/quarkus/core/CamelConfig.java | 16 ++++++++++++++++ .../org/apache/camel/quarkus/core/CamelRecorder.java | 4 ++-- .../org/apache/camel/quarkus/core/FastTypeConverter.java | 4 ++-- .../quarkus/core/converter/it/ConverterResource.java | 10 +++------- .../src/main/resources/application.properties | 1 + .../camel/quarkus/core/converter/it/ConverterTest.java | 12 ++++++------ .../quarkus/core/converter/it/ConverterTestBase.java | 5 ++--- 9 files changed, 41 insertions(+), 21 deletions(-) diff --git a/docs/modules/ROOT/pages/reference/extensions/core.adoc b/docs/modules/ROOT/pages/reference/extensions/core.adoc index f3a3328c80..f7898292c3 100644 --- a/docs/modules/ROOT/pages/reference/extensions/core.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/core.adoc @@ -395,6 +395,12 @@ Filter for tracing messages. | `string` | +|icon:lock[title=Fixed at build time] [[quarkus.camel.type-converter.statistics-enabled]]`link:#quarkus.camel.type-converter.statistics-enabled[quarkus.camel.type-converter.statistics-enabled]` + +Whether type converter statistics are enabled. By default, type converter utilization statistics are disabled. Note that enabling statistics incurs a minor performance impact under very heavy load . +| `boolean` +| `false` + |icon:lock[title=Fixed at build time] [[quarkus.camel.main.shutdown.timeout]]`link:#quarkus.camel.main.shutdown.timeout[quarkus.camel.main.shutdown.timeout]` A timeout (with millisecond precision) to wait for `CamelMain++#++stop()` to finish diff --git a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java index cec76d1c94..ceab80efcb 100644 --- a/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java +++ b/extensions-core/core/deployment/src/main/java/org/apache/camel/quarkus/core/deployment/CamelProcessor.java @@ -248,6 +248,7 @@ class CamelProcessor { @Record(ExecutionTime.STATIC_INIT) @BuildStep CamelTypeConverterRegistryBuildItem typeConverterRegistry( + CamelConfig config, CamelRecorder recorder, ApplicationArchivesBuildItem applicationArchives, List<CamelTypeConverterLoaderBuildItem> additionalLoaders, @@ -256,7 +257,8 @@ class CamelProcessor { IndexView index = combinedIndex.getIndex(); - RuntimeValue<TypeConverterRegistry> typeConverterRegistry = recorder.createTypeConverterRegistry(); + RuntimeValue<TypeConverterRegistry> typeConverterRegistry = recorder + .createTypeConverterRegistry(config.typeConverter.statisticsEnabled); // // This should be simplified by searching for classes implementing TypeConverterLoader but that diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java index fb1b2a8f30..f223ec3fe2 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelConfig.java @@ -91,6 +91,12 @@ public class CamelConfig { @ConfigItem public TraceConfig trace; + /** + * Build time configuration options for Camel type converters. + */ + @ConfigItem + public TypeConverterConfig typeConverter; + @ConfigGroup public static class BootstrapConfig { /** @@ -504,4 +510,14 @@ public class CamelConfig { @ConfigItem public Optional<String> traceFilter; } + + @ConfigGroup + public static class TypeConverterConfig { + /** + * Whether type converter statistics are enabled. By default, type converter utilization statistics are disabled. + * Note that enabling statistics incurs a minor performance impact under very heavy load . + */ + @ConfigItem(defaultValue = "false") + public boolean statisticsEnabled; + } } diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java index 95b77d2c6a..3dc39f6953 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelRecorder.java @@ -68,8 +68,8 @@ public class CamelRecorder { return new RuntimeValue<>(new RuntimeRegistry(beanQualifierResolvers)); } - public RuntimeValue<TypeConverterRegistry> createTypeConverterRegistry() { - return new RuntimeValue<>(new FastTypeConverter()); + public RuntimeValue<TypeConverterRegistry> createTypeConverterRegistry(boolean statisticsEnabled) { + return new RuntimeValue<>(new FastTypeConverter(statisticsEnabled)); } public void addTypeConverterLoader(RuntimeValue<TypeConverterRegistry> registry, RuntimeValue<TypeConverterLoader> loader) { diff --git a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java index f4587dc151..6de2ae21d9 100644 --- a/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java +++ b/extensions-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/FastTypeConverter.java @@ -24,8 +24,8 @@ import org.slf4j.LoggerFactory; public class FastTypeConverter extends DefaultTypeConverter { private static final Logger LOG = LoggerFactory.getLogger(FastTypeConverter.class); - public FastTypeConverter() { - super(null, null, null, false); + public FastTypeConverter(boolean statisticsEnabled) { + super(null, null, null, false, statisticsEnabled); } @Override diff --git a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java index 37f2bbe96e..c5a7c8e0f8 100644 --- a/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java +++ b/integration-test-groups/foundation/type-converter/src/main/java/org/apache/camel/quarkus/core/converter/it/ConverterResource.java @@ -103,14 +103,10 @@ public class ConverterResource { return context.getTypeConverter().convertTo(MyNullablePair.class, input); } - @Path("/setStatisticsEnabled") + @Path("/resetStatistics") @POST - @Produces(MediaType.TEXT_PLAIN) - public void converterSetStatisticsEnabled(boolean value) { - context.getTypeConverterRegistry().getStatistics().setStatisticsEnabled(value); - if (value) { - context.getTypeConverterRegistry().getStatistics().reset(); - } + public void resetStatistics() { + context.getTypeConverterRegistry().getStatistics().reset(); } @Path("/getStatisticsHit") diff --git a/integration-test-groups/foundation/type-converter/src/main/resources/application.properties b/integration-test-groups/foundation/type-converter/src/main/resources/application.properties index b6ff2229d0..deb6a5d251 100644 --- a/integration-test-groups/foundation/type-converter/src/main/resources/application.properties +++ b/integration-test-groups/foundation/type-converter/src/main/resources/application.properties @@ -16,3 +16,4 @@ ## --------------------------------------------------------------------------- quarkus.log.file.enable = true quarkus.log.file.path = target/quarkus.log +quarkus.camel.type-converter.statistics-enabled=true diff --git a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java index 3b79b05bf5..b32d45745f 100644 --- a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java +++ b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTest.java @@ -49,24 +49,24 @@ public class ConverterTest extends ConverterTestBase { @Test void testConverterToNull() { - enableStatistics(true); + resetStatistics(); testConverterReturningNull("/converter/myNullablePair", "null"); RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(1), "miss", is(0)); - enableStatistics(false); + resetStatistics(); } @Test void testNotRegisteredConverter() { - enableStatistics(true); + resetStatistics(); testConverterReturningNull("/converter/myNotRegisteredPair", "a:b"); RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(0), "miss", is(1)); - enableStatistics(false); + resetStatistics(); } @Test @@ -84,13 +84,13 @@ public class ConverterTest extends ConverterTestBase { @Test void testConverterGetStatistics() { - enableStatistics(true); + resetStatistics(); //cause 1 hit testConverterFromAnnotationWithStaticMethods(); RestAssured.when().get("/converter/getStatisticsHit").then().body("hit", is(1), "miss", is(0)); - enableStatistics(false); + resetStatistics(); } } diff --git a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTestBase.java b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTestBase.java index e3e18cfb41..e1e2d8e387 100644 --- a/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTestBase.java +++ b/integration-test-groups/foundation/type-converter/src/test/java/org/apache/camel/quarkus/core/converter/it/ConverterTestBase.java @@ -25,10 +25,9 @@ import static org.hamcrest.Matchers.is; public abstract class ConverterTestBase { - void enableStatistics(boolean b) { + void resetStatistics() { RestAssured.given() - .contentType(ContentType.TEXT).body(b) - .post("/converter/setStatisticsEnabled") + .post("/converter/resetStatistics") .then() .statusCode(204); }