From 38721cfe007891a38b919070bbb9d3b4ba4dc285 Mon Sep 17 00:00:00 2001 From: JiriOndrusek Date: Thu, 29 Jun 2023 14:15:32 +0200 Subject: [PATCH] Micrometer: Router policy should be disabled by default (to be consistent with Camel) #5028 --- .../ROOT/pages/migration-guide/3.0.0.adoc | 13 ++++ .../reference/extensions/micrometer.adoc | 2 +- .../MicrometerMetricsConfigDefaultsTest.java | 4 +- ...icrometerMetricsConfigRoutePolicyTest.java | 71 +++++++++++++++++++ .../micrometer/CamelMicrometerConfig.java | 2 +- .../it/MicrometerRoutePolicyProfile.java | 29 ++++++++ .../it/MicrometerRoutePolicyTest.java | 40 +++++++++++ .../micrometer/it/MicrometerTest.java | 8 ++- 8 files changed, 161 insertions(+), 8 deletions(-) create mode 100644 extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigRoutePolicyTest.java create mode 100644 integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerRoutePolicyProfile.java create mode 100644 integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerRoutePolicyTest.java diff --git a/docs/modules/ROOT/pages/migration-guide/3.0.0.adoc b/docs/modules/ROOT/pages/migration-guide/3.0.0.adoc index bc1348046acb..4fac36d41dff 100644 --- a/docs/modules/ROOT/pages/migration-guide/3.0.0.adoc +++ b/docs/modules/ROOT/pages/migration-guide/3.0.0.adoc @@ -39,3 +39,16 @@ The following extensions have been removed. |=== +== Change to default values of `camel.metrics.enableRoutePolicy` configuration + +In previous releases, the Micrometer extension default was to enable MicrometerRoutePolicyFactory (value `true`). + +This has now changed to reflect behavior in Camel. + +To enable MicrometerRoutePolicyFactory, you can add configuration propertty to `application.properties`. + +``` +quarkus.camel.metrics.enable-route-policy=true +``` + +For more information, refer to the xref:reference/extensions/micrometerr.adoc[Camel Quarkus Micrometer Extension] documentation. diff --git a/docs/modules/ROOT/pages/reference/extensions/micrometer.adoc b/docs/modules/ROOT/pages/reference/extensions/micrometer.adoc index 830a2c9648f2..edb54336f754 100644 --- a/docs/modules/ROOT/pages/reference/extensions/micrometer.adoc +++ b/docs/modules/ROOT/pages/reference/extensions/micrometer.adoc @@ -86,7 +86,7 @@ Prometheus backend ignores negative values during increment of Counter metrics. Set whether to enable the MicrometerRoutePolicyFactory for capturing metrics on route processing times. | `boolean` -| `true` +| `false` |icon:lock[title=Fixed at build time] [[quarkus.camel.metrics.enable-message-history]]`link:#quarkus.camel.metrics.enable-message-history[quarkus.camel.metrics.enable-message-history]` diff --git a/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigDefaultsTest.java b/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigDefaultsTest.java index cf0612ee4328..54fe916e24d7 100644 --- a/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigDefaultsTest.java +++ b/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigDefaultsTest.java @@ -22,7 +22,6 @@ import io.quarkus.test.QuarkusUnitTest; import jakarta.inject.Inject; import org.apache.camel.CamelContext; -import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory; import org.apache.camel.component.micrometer.spi.InstrumentedThreadPoolFactory; import org.apache.camel.impl.engine.DefaultMessageHistoryFactory; import org.apache.camel.spi.EventNotifier; @@ -51,8 +50,7 @@ public class MicrometerMetricsConfigDefaultsTest { @Test public void testMicrometerMetricsConfiguration() { List routePolicyFactories = context.getRoutePolicyFactories(); - assertEquals(1, routePolicyFactories.size()); - assertTrue(routePolicyFactories.get(0) instanceof MicrometerRoutePolicyFactory); + assertEquals(0, routePolicyFactories.size()); MessageHistoryFactory messageHistoryFactory = context.getMessageHistoryFactory(); assertNotNull(messageHistoryFactory); diff --git a/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigRoutePolicyTest.java b/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigRoutePolicyTest.java new file mode 100644 index 000000000000..5dd75bcba2cd --- /dev/null +++ b/extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerMetricsConfigRoutePolicyTest.java @@ -0,0 +1,71 @@ +/* + * 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.apache.camel.quarkus.component.micrometer.deployment; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.List; +import java.util.Properties; + +import io.quarkus.test.QuarkusUnitTest; +import jakarta.inject.Inject; +import org.apache.camel.CamelContext; +import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory; +import org.apache.camel.spi.RoutePolicyFactory; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.Asset; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MicrometerMetricsConfigRoutePolicyTest { + + @RegisterExtension + static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) + .addAsResource(applicationProperties(), "application.properties")); + + @Inject + CamelContext context; + + @Test + public void testRouteConfigEnabledConfiguration() { + List routePolicyFactories = context.getRoutePolicyFactories(); + assertEquals(1, routePolicyFactories.size()); + assertTrue(routePolicyFactories.get(0) instanceof MicrometerRoutePolicyFactory); + } + + public static final Asset applicationProperties() { + Writer writer = new StringWriter(); + + Properties props = new Properties(); + props.setProperty("camel.metrics.enableRoutePolicy", "true"); + + try { + props.store(writer, ""); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return new StringAsset(writer.toString()); + } +} diff --git a/extensions/micrometer/runtime/src/main/java/org/apache/camel/quarkus/component/micrometer/CamelMicrometerConfig.java b/extensions/micrometer/runtime/src/main/java/org/apache/camel/quarkus/component/micrometer/CamelMicrometerConfig.java index e283580286e4..3f9c8bd52d3b 100644 --- a/extensions/micrometer/runtime/src/main/java/org/apache/camel/quarkus/component/micrometer/CamelMicrometerConfig.java +++ b/extensions/micrometer/runtime/src/main/java/org/apache/camel/quarkus/component/micrometer/CamelMicrometerConfig.java @@ -27,7 +27,7 @@ public class CamelMicrometerConfig { * Set whether to enable the MicrometerRoutePolicyFactory for capturing metrics * on route processing times. */ - @ConfigItem(defaultValue = "true") + @ConfigItem(defaultValue = "false") public boolean enableRoutePolicy; /** diff --git a/integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerRoutePolicyProfile.java b/integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerRoutePolicyProfile.java new file mode 100644 index 000000000000..4df0d50590c1 --- /dev/null +++ b/integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerRoutePolicyProfile.java @@ -0,0 +1,29 @@ +/* + * 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.apache.camel.quarkus.component.micrometer.it; + +import java.util.Map; + +import io.quarkus.test.junit.QuarkusTestProfile; + +public class MicrometerRoutePolicyProfile implements QuarkusTestProfile { + + @Override + public Map getConfigOverrides() { + return Map.of("quarkus.camel.metrics.enable-route-policy", "true"); + } +} diff --git a/integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerRoutePolicyTest.java b/integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerRoutePolicyTest.java new file mode 100644 index 000000000000..5ecb777ca94f --- /dev/null +++ b/integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerRoutePolicyTest.java @@ -0,0 +1,40 @@ +/* + * 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.apache.camel.quarkus.component.micrometer.it; + +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; +import io.restassured.RestAssured; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@QuarkusTest +@TestProfile(MicrometerRoutePolicyProfile.class) +class MicrometerRoutePolicyTest extends AbstractMicrometerTest { + + @Test + public void testMicrometerRoutePolicyFactory() { + RestAssured.get("/micrometer/timer") + .then() + .statusCode(200); + assertTrue( + getMetricValue(Integer.class, "counter", "camel.exchanges.succeeded", "routeId=micrometer-metrics-timer") > 0); + assertEquals(0, getMetricValue(Integer.class, "counter", "camel.exchanges.failed", "routeId=micrometer-metrics-timer")); + } +} diff --git a/integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerTest.java b/integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerTest.java index 5589f43a4a65..2a42e9c5a2b3 100644 --- a/integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerTest.java +++ b/integration-tests/micrometer/src/test/java/org/apache/camel/quarkus/component/micrometer/it/MicrometerTest.java @@ -104,9 +104,11 @@ public void testMicrometerRoutePolicyFactory() { RestAssured.get("/micrometer/timer") .then() .statusCode(200); - assertTrue( - getMetricValue(Integer.class, "counter", "camel.exchanges.succeeded", "routeId=micrometer-metrics-timer") > 0); - assertEquals(0, getMetricValue(Integer.class, "counter", "camel.exchanges.failed", "routeId=micrometer-metrics-timer")); + + assertEquals("Metric does not exist", + getMetricValue(String.class, "counter", "camel.exchanges.succeeded", "routeId=micrometer-metrics-timer", 500)); + assertEquals("Metric does not exist", + getMetricValue(String.class, "counter", "camel.exchanges.failed", "routeId=micrometer-metrics-timer", 500)); } @Test