You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2024/03/13 06:34:02 UTC
(camel) branch camel-4.0.x updated: CAMEL-20558: Ability to use the old Micrometer meter names does not work on MicrometerExchangeEventNotifier. Thanks to Sébastien Perpignane for the patch.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.0.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.0.x by this push:
new 39ca538a769 CAMEL-20558: Ability to use the old Micrometer meter names does not work on MicrometerExchangeEventNotifier. Thanks to Sébastien Perpignane for the patch.
39ca538a769 is described below
commit 39ca538a7691ad73695f2dd3e108bb43cced6a4f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Mar 13 07:33:13 2024 +0100
CAMEL-20558: Ability to use the old Micrometer meter names does not work on MicrometerExchangeEventNotifier. Thanks to Sébastien Perpignane for the patch.
---
...rometerExchangeEventNotifierNamingStrategy.java | 6 ++
...terExchangeEventNotifierNamingStrategyTest.java | 66 ++++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java
index fdaa1c91053..2d6b15b27ab 100644
--- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java
+++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java
@@ -22,6 +22,7 @@ import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Tags;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
+import org.apache.camel.component.micrometer.MicrometerUtils;
import org.apache.camel.spi.CamelEvent.ExchangeEvent;
import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG;
@@ -51,6 +52,11 @@ public interface MicrometerExchangeEventNotifierNamingStrategy {
public String getName(Exchange exchange, Endpoint endpoint) {
return formatName(DEFAULT_CAMEL_EXCHANGE_EVENT_METER_NAME);
}
+
+ @Override
+ public String formatName(String name) {
+ return MicrometerUtils.legacyName(name);
+ }
};
String getName(Exchange exchange, Endpoint endpoint);
diff --git a/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategyTest.java b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategyTest.java
new file mode 100644
index 00000000000..d082aa00283
--- /dev/null
+++ b/components/camel-micrometer/src/test/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategyTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.component.micrometer.eventnotifier;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+class MicrometerExchangeEventNotifierNamingStrategyTest {
+
+ @Test
+ void testDefaultFormatName() {
+ MicrometerExchangeEventNotifierNamingStrategy defaultStrategy = MicrometerExchangeEventNotifierNamingStrategy.DEFAULT;
+
+ String result = defaultStrategy.formatName("some.metric.name");
+
+ assertThat(result).isEqualTo("some.metric.name");
+ }
+
+ @Test
+ void testLegacyFormatName() {
+ MicrometerExchangeEventNotifierNamingStrategy legacyStrategy = MicrometerExchangeEventNotifierNamingStrategy.LEGACY;
+
+ String result = legacyStrategy.formatName("some.metric.name");
+
+ assertThat(result).isEqualTo("SomeMetricName");
+ }
+
+ @Test
+ void getDefaultInflightExchangesName() {
+ Exchange exchange = mock(Exchange.class);
+ Endpoint endpoint = mock(Endpoint.class);
+ MicrometerExchangeEventNotifierNamingStrategy defaultStrategy = MicrometerExchangeEventNotifierNamingStrategy.DEFAULT;
+ String result = defaultStrategy.getInflightExchangesName(exchange, endpoint);
+
+ assertThat(result).isEqualTo("camel.exchanges.inflight");
+ }
+
+ @Test
+ void getLegacyInflightExchangesName() {
+ Exchange exchange = mock(Exchange.class);
+ Endpoint endpoint = mock(Endpoint.class);
+ MicrometerExchangeEventNotifierNamingStrategy defaultStrategy = MicrometerExchangeEventNotifierNamingStrategy.LEGACY;
+ String result = defaultStrategy.getInflightExchangesName(exchange, endpoint);
+
+ assertThat(result).isEqualTo("CamelExchangesInflight");
+ }
+
+}