You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "JiriOndrusek (via GitHub)" <gi...@apache.org> on 2023/06/28 13:05:19 UTC

[GitHub] [camel-quarkus] JiriOndrusek opened a new pull request, #5024: Micrometer: SimpleMeterRegistry is not created if no other registry is defined #5023

JiriOndrusek opened a new pull request, #5024:
URL: https://github.com/apache/camel-quarkus/pull/5024

   fixes https://github.com/apache/camel-quarkus/issues/5023
   
   Quarkus gathers all registerie and puts them together as CompositeRegistry (created by [code](https://github.com/micrometer-metrics/micrometer/blob/main/micrometer-core/src/main/java/io/micrometer/core/instrument/Metrics.java#L36))
   This happens even if there is no metric implementation dependency (which causes thet CompositeRepository is empty and can not be used). For such purposes the Camel component creates a SimpleMeterRegistry for the testing purposes  ([code](https://github.com/apache/camel/blob/main/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/MicrometerUtils.java#L67)).
   This PR adds code, which detects cases where CompositeRegistry is empty and in such cases  creates `SimpleMeterRegistry`.
   
   
   <!-- Uncomment and fill this section if your PR is not trivial
   [ ] An issue should be filed for the change unless this is a trivial change (fixing a typo or similar). One issue should ideally be fixed by not more than one commit and the other way round, each commit should fix just one issue, without pulling in other changes.
   [ ] Each commit in the pull request should have a meaningful and properly spelled subject line and body. Copying the title of the associated issue is typically enough. Please include the issue number in the commit message prefixed by #.
   [ ] The pull request description should explain what the pull request does, how, and why. If the info is available in the associated issue or some other external document, a link is enough.
   [ ] Phrases like Fix #<issueNumber> or Fixes #<issueNumber> will auto-close the named issue upon merging the pull request. Using them is typically a good idea.
   [ ] Please run mvn process-resources -Pformat (and amend the changes if necessary) before sending the pull request.
   [ ] Contributor guide is your good friend: https://camel.apache.org/camel-quarkus/latest/contributor-guide.html
   -->


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #5024: Micrometer: SimpleMeterRegistry is not created if no other registry is defined #5023

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #5024:
URL: https://github.com/apache/camel-quarkus/pull/5024#discussion_r1246290643


##########
extensions/micrometer/deployment/src/main/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerProcessor.java:
##########
@@ -65,4 +67,13 @@ RuntimeCamelContextCustomizerBuildItem runtimeContextCustomizer(
         return new RuntimeCamelContextCustomizerBuildItem(
                 recorder.createRuntimeContextCustomizer(config, rootMeterRegistryBuildItem.getValue()));
     }
+
+    @Record(ExecutionTime.STATIC_INIT)
+    @BuildStep
+    CamelRuntimeBeanBuildItem tikaComponent(CamelMicrometerRecorder recorder) {

Review Comment:
   N/A



##########
extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerSimpleMeterRegistryTest.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 io.micrometer.core.instrument.simple.SimpleMeterRegistry;
+import io.quarkus.test.QuarkusUnitTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.micrometer.MicrometerComponent;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+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.assertTrue;
+
+public class MicrometerSimpleMeterRegistryTest {
+
+    @RegisterExtension
+    static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+            .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+    @Inject
+    CamelContext context;
+
+    @Test
+    public void testQuarkusSchedulerAutowired() throws Exception {
+        MicrometerComponent component = context.getComponent("micrometer", MicrometerComponent.class);
+        assertTrue(component.getMetricsRegistry() instanceof SimpleMeterRegistry, "SimpleMeterRegistry");

Review Comment:
   N/A



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] JiriOndrusek commented on pull request #5024: Micrometer: SimpleMeterRegistry is not created if no other registry is defined #5023

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on PR #5024:
URL: https://github.com/apache/camel-quarkus/pull/5024#issuecomment-1612548816

   @jamesnetherton 
   my first attempt was not successful. Unfortunately it is not possible to consume  `List<MicrometerRegistryProviderBuildItem>` and create a new `MicrometerRegistryProviderBuildItem` at the same time. I'm getting `io.quarkus.builder.ChainBuildException: Cycle detected`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton merged pull request #5024: Micrometer: SimpleMeterRegistry is not created if no other registry is defined #5023

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton merged PR #5024:
URL: https://github.com/apache/camel-quarkus/pull/5024


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton commented on a diff in pull request #5024: Micrometer: SimpleMeterRegistry is not created if no other registry is defined #5023

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on code in PR #5024:
URL: https://github.com/apache/camel-quarkus/pull/5024#discussion_r1245216290


##########
extensions/micrometer/deployment/src/main/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerProcessor.java:
##########
@@ -65,4 +67,13 @@ RuntimeCamelContextCustomizerBuildItem runtimeContextCustomizer(
         return new RuntimeCamelContextCustomizerBuildItem(
                 recorder.createRuntimeContextCustomizer(config, rootMeterRegistryBuildItem.getValue()));
     }
+
+    @Record(ExecutionTime.STATIC_INIT)
+    @BuildStep
+    CamelRuntimeBeanBuildItem tikaComponent(CamelMicrometerRecorder recorder) {

Review Comment:
   ```suggestion
       CamelRuntimeBeanBuildItem micrometerComponent(CamelMicrometerRecorder recorder) {
   ```



##########
extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerSimpleMeterRegistryTest.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 io.micrometer.core.instrument.simple.SimpleMeterRegistry;
+import io.quarkus.test.QuarkusUnitTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.micrometer.MicrometerComponent;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+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.assertTrue;
+
+public class MicrometerSimpleMeterRegistryTest {
+
+    @RegisterExtension
+    static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+            .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+    @Inject
+    CamelContext context;
+
+    @Test
+    public void testQuarkusSchedulerAutowired() throws Exception {

Review Comment:
   ```suggestion
       public void testDefaultSimpleMeterRegistry() throws Exception {
   ```



##########
extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerSimpleMeterRegistryTest.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 io.micrometer.core.instrument.simple.SimpleMeterRegistry;
+import io.quarkus.test.QuarkusUnitTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.micrometer.MicrometerComponent;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+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.assertTrue;
+
+public class MicrometerSimpleMeterRegistryTest {
+
+    @RegisterExtension
+    static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+            .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+    @Inject
+    CamelContext context;
+
+    @Test
+    public void testQuarkusSchedulerAutowired() throws Exception {
+        MicrometerComponent component = context.getComponent("micrometer", MicrometerComponent.class);
+        assertTrue(component.getMetricsRegistry() instanceof SimpleMeterRegistry, "SimpleMeterRegistry");

Review Comment:
   ```suggestion
           assertInstanceOf(SimpleMeterRegistry.class, component.getMetricsRegistry() );
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #5024: Micrometer: SimpleMeterRegistry is not created if no other registry is defined #5023

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #5024:
URL: https://github.com/apache/camel-quarkus/pull/5024#discussion_r1246290988


##########
extensions/micrometer/deployment/src/test/java/org/apache/camel/quarkus/component/micrometer/deployment/MicrometerSimpleMeterRegistryTest.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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 io.micrometer.core.instrument.simple.SimpleMeterRegistry;
+import io.quarkus.test.QuarkusUnitTest;
+import jakarta.inject.Inject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.micrometer.MicrometerComponent;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+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.assertTrue;
+
+public class MicrometerSimpleMeterRegistryTest {
+
+    @RegisterExtension
+    static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+            .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+    @Inject
+    CamelContext context;
+
+    @Test
+    public void testQuarkusSchedulerAutowired() throws Exception {

Review Comment:
   N/A



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton commented on pull request #5024: Micrometer: SimpleMeterRegistry is not created if no other registry is defined #5023

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on PR #5024:
URL: https://github.com/apache/camel-quarkus/pull/5024#issuecomment-1612555899

   I don't think we need to create `MicrometerRegistryProviderBuildItem`, we only need to consume them.
   
   So I was thinking something like:
   
   ```java
   @BuildStep
   void configureDefaultRegistry(
           List<MicrometerRegistryProviderBuildItem> providers, 
           RootMeterRegistryBuildItem registry,
           CamelMicrometerRecorder recorder) {
       if (providers.isEmpty()) {
           // Adds SimpleMeterRegistry to the Quarkus composite one
           recorder.configureDefaultRegistry(registry.getValue());
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] JiriOndrusek commented on pull request #5024: Micrometer: SimpleMeterRegistry is not created if no other registry is defined #5023

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on PR #5024:
URL: https://github.com/apache/camel-quarkus/pull/5024#issuecomment-1612617278

   @jamesnetherton your suggestion work as expected. The PR now contains a different implementation of the fix. I added 1 line into the doc, describing autocreation of `SimpleMeterRegistry`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] JiriOndrusek commented on pull request #5024: Micrometer: SimpleMeterRegistry is not created if no other registry is defined #5023

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on PR #5024:
URL: https://github.com/apache/camel-quarkus/pull/5024#issuecomment-1612517525

   > I wonder if we should avoid extending the component?
   > 
   > And instead consume `List<MicrometerRegistryProviderBuildItem>`. And if it's empty, then we can just register `SimpleMeterRegistry` with the existing Quarkus composite registry (which has its own `BuildItem` where the value can be passed to a recorder).
   > 
   > I'm just thinking out loud, not sure if that would work or not.
   
   This is a nice idea. Registering simpleRegistry and keeping the Quarks mechanism working as expected should be nice and it would allow to share SimpleRegistry among more services/apps/beans. I'll try that solution.
   
   and thanks for the founded issues in the code , I'll rework the PR with this new approach to see if it works as expected.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel-quarkus] jamesnetherton commented on pull request #5024: Micrometer: SimpleMeterRegistry is not created if no other registry is defined #5023

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on PR #5024:
URL: https://github.com/apache/camel-quarkus/pull/5024#issuecomment-1611437270

   I wonder if we should avoid extending the component? 
   
   And instead consume `List<MicrometerRegistryProviderBuildItem>`. And if it's empty, then we can just register `SimpleMeterRegistry` with the existing Quarkus composite registry (which has its own `BuildItem` where the value can be passed to a recorder).
   
   I'm just thinking out loud, not sure if that would work or not.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org