You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ro...@apache.org on 2024/09/16 09:17:10 UTC

(activemq-artemis) 02/02: ARTEMIS-5045 add test + polish

This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git

commit dc64d9be7821020e99edec08ad3f83b2e7d2c72a
Author: Justin Bertram <jb...@apache.org>
AuthorDate: Tue Sep 10 17:01:20 2024 -0500

    ARTEMIS-5045 add test + polish
---
 .../core/server/metrics/MetricsManager.java        | 34 ++++-----
 .../metrics/NettyPooledAllocatorMetrics.java       | 80 +++++++++++-----------
 .../plugin/LegacyConfigMetricsPluginTest.java      | 28 ++++++++
 .../integration/plugin/MetricsPluginTest.java      | 57 +++++----------
 .../plugin/PassthroughMetricsPluginTest.java       | 77 +++++++++++++++++++++
 5 files changed, 180 insertions(+), 96 deletions(-)

diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/MetricsManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/MetricsManager.java
index 9915753ed2..d3ed24eeb1 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/MetricsManager.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/MetricsManager.java
@@ -53,11 +53,13 @@ import org.slf4j.LoggerFactory;
 
 public class MetricsManager {
 
+   public static final String BROKER_TAG_NAME = "broker";
+
    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
    private final String brokerName;
 
-   private final Tags tags;
+   private final Tags commonTags;
    private final MeterRegistry meterRegistry;
 
    private final Map<String, List<Meter>> meters = new ConcurrentHashMap<>();
@@ -71,38 +73,36 @@ public class MetricsManager {
       this.brokerName = brokerName;
       this.meterRegistry = metricsConfiguration.getPlugin().getRegistry();
       this.addressSettingsRepository = addressSettingsRepository;
-      this.tags = Tags.of("broker", brokerName);
+      this.commonTags = Tags.of(BROKER_TAG_NAME, brokerName);
       if (meterRegistry != null) {
          Metrics.globalRegistry.add(meterRegistry);
          if (metricsConfiguration.isJvmMemory()) {
-            new JvmMemoryMetrics(tags).bindTo(meterRegistry);
+            new JvmMemoryMetrics(commonTags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isJvmGc()) {
-            new JvmGcMetrics(tags).bindTo(meterRegistry);
+            new JvmGcMetrics(commonTags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isJvmThread()) {
-            new JvmThreadMetrics(tags).bindTo(meterRegistry);
+            new JvmThreadMetrics(commonTags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isNettyPool()) {
-            new NettyPooledAllocatorMetrics(PooledByteBufAllocator.DEFAULT.metric(), tags).bindTo(meterRegistry);
+            new NettyPooledAllocatorMetrics(PooledByteBufAllocator.DEFAULT.metric(), commonTags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isFileDescriptors()) {
-            new FileDescriptorMetrics(tags).bindTo(meterRegistry);
+            new FileDescriptorMetrics(commonTags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isProcessor()) {
-            new ProcessorMetrics(tags).bindTo(meterRegistry);
+            new ProcessorMetrics(commonTags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isUptime()) {
-            new UptimeMetrics(tags).bindTo(meterRegistry);
+            new UptimeMetrics(commonTags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isLogging()) {
-            new Log4j2Metrics(tags).bindTo(meterRegistry);
+            new Log4j2Metrics(commonTags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isSecurityCaches() && securityStore.isSecurityEnabled()) {
-            CaffeineCacheMetrics.monitor(meterRegistry,
-               ((SecurityStoreImpl)securityStore).getAuthenticationCache(), "authentication", tags);
-            CaffeineCacheMetrics.monitor(meterRegistry,
-               ((SecurityStoreImpl)securityStore).getAuthorizationCache(), "authorization", tags);
+            CaffeineCacheMetrics.monitor(meterRegistry, ((SecurityStoreImpl)securityStore).getAuthenticationCache(), "authentication", commonTags);
+            CaffeineCacheMetrics.monitor(meterRegistry, ((SecurityStoreImpl)securityStore).getAuthorizationCache(), "authorization", commonTags);
          }
       }
    }
@@ -125,7 +125,7 @@ public class MetricsManager {
       builder.accept((metricName, state, f, description, gaugeTags) -> {
          Builder<Object> meter = Gauge
             .builder("artemis." + metricName, state, f)
-            .tags(tags)
+            .tags(commonTags)
             .tags(gaugeTags)
             .tag("address", address)
             .tag("queue", queue)
@@ -143,7 +143,7 @@ public class MetricsManager {
       builder.accept((metricName, state, f, description, gaugeTags) -> {
          Builder<Object> meter = Gauge
             .builder("artemis." + metricName, state, f)
-            .tags(tags)
+            .tags(commonTags)
             .tags(gaugeTags)
             .tag("address", address)
             .description(description);
@@ -160,7 +160,7 @@ public class MetricsManager {
       builder.accept((metricName, state, f, description, gaugeTags) -> {
          Builder<Object> meter = Gauge
             .builder("artemis." + metricName, state, f)
-            .tags(tags)
+            .tags(commonTags)
             .tags(gaugeTags)
             .description(description);
          gaugeBuilders.add(meter);
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/NettyPooledAllocatorMetrics.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/NettyPooledAllocatorMetrics.java
index 23f8af0316..10bc4790a0 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/NettyPooledAllocatorMetrics.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/metrics/NettyPooledAllocatorMetrics.java
@@ -34,64 +34,64 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
 
    private static final String BYTES_UNIT = "bytes";
    private final PooledByteBufAllocatorMetric metric;
-   private final Tags tags;
+   private final Tags commonTags;
 
-   public NettyPooledAllocatorMetrics(final PooledByteBufAllocatorMetric pooledAllocatorMetric, final Tags tags) {
+   public NettyPooledAllocatorMetrics(final PooledByteBufAllocatorMetric pooledAllocatorMetric, final Tags commonTags) {
       this.metric = pooledAllocatorMetric;
-      this.tags = tags;
+      this.commonTags = commonTags;
    }
 
    @Override
    public void bindTo(final MeterRegistry registry) {
 
       Gauge.builder("netty.pooled.used.memory", this.metric, metric -> metric.usedDirectMemory())
-         .tags(tags)
+         .tags(commonTags)
          .tags("type", "direct")
          .description("The used memory")
          .baseUnit(BYTES_UNIT).register(registry);
 
       Gauge.builder("netty.pooled.used.memory", this.metric, metric -> metric.usedHeapMemory())
-         .tags(tags)
+         .tags(commonTags)
          .tags("type", "heap")
          .description("The used memory")
          .baseUnit(BYTES_UNIT).register(registry);
 
       Gauge.builder("netty.pooled.arenas.num", this.metric, metric -> metric.numDirectArenas())
-         .tags(tags)
+         .tags(commonTags)
          .tags("type", "direct")
          .description("The number of arenas")
          .register(registry);
 
       Gauge.builder("netty.pooled.arenas.num", this.metric, metric -> metric.numHeapArenas())
-         .tags(tags)
+         .tags(commonTags)
          .tags("type", "heap").description("The number or arenas")
          .register(registry);
 
       Gauge.builder("netty.pooled.cachesize", this.metric, metric -> metric.tinyCacheSize())
-         .tags(tags)
+         .tags(commonTags)
          .tags("type", "tiny")
          .description("The cachesize used by this netty allocator")
          .register(registry);
 
       Gauge.builder("netty.pooled.cachesize", this.metric, metric -> metric.smallCacheSize())
-         .tags(tags)
+         .tags(commonTags)
          .tags("type", "small")
          .description("The cachesize used by this netty allocator")
          .register(registry);
 
       Gauge.builder("netty.pooled.cachesize", this.metric, metric -> metric.normalCacheSize())
-         .tags(tags)
+         .tags(commonTags)
          .tags("type", "normal")
          .description("The cachesize used by this netty allocator")
          .register(registry);
 
       Gauge.builder("netty.pooled.threadlocalcache.num", this.metric, metric -> metric.numThreadLocalCaches())
-         .tags(tags)
+         .tags(commonTags)
          .description("The number of thread local caches used by this netty allocator")
          .register(registry);
 
       Gauge.builder("netty.pooled.chunk.size", this.metric, metric -> metric.chunkSize())
-         .tags(tags)
+         .tags(commonTags)
          .description("The arena chunk size of this netty allocator")
          .baseUnit(BYTES_UNIT)
          .register(registry);
@@ -119,140 +119,140 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
        */
       final String poolArenaIndexString = Integer.toString(poolArenaIndex);
       Gauge.builder("netty.pooled.arena.threadcaches.num", poolArenaMetric, metric -> metric.numThreadCaches())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString)
          .description("The number of thread caches backed by this arena")
          .register(registry);
 
       FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric,
          metric -> metric.numAllocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "all")
          .description("The number of allocations done via the arena. This includes all sizes")
          .register(registry);
 
       FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric,
          metric -> metric.numTinyAllocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny")
          .description("The number of tiny allocations done via the arena")
          .register(registry);
 
       FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric,
          metric -> metric.numSmallAllocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small")
          .description("The number of small allocations done via the arena")
          .register(registry);
 
       FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric,
          metric -> metric.numNormalAllocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "normal")
          .description("The number of normal allocations done via the arena")
          .register(registry);
 
       FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric,
          metric -> metric.numHugeAllocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "huge")
          .description("The number of huge allocations done via the arena")
          .register(registry);
 
       FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric,
          metric -> metric.numDeallocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "all")
          .description("The number of deallocations done via the arena. This includes all sizes")
          .register(registry);
 
       FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric,
          metric -> metric.numTinyDeallocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny")
          .description("The number of tiny deallocations done via the arena")
          .register(registry);
 
       FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric,
          metric -> metric.numSmallDeallocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small")
          .description("The number of small deallocations done via the arena")
          .register(registry);
 
       FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric,
          metric -> metric.numNormalDeallocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "normal")
          .description("The number of normal deallocations done via the arena")
          .register(registry);
 
       FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric,
          metric -> metric.numHugeDeallocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "huge")
          .description("The number of huge deallocations done via the arena")
          .register(registry);
 
       Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric,
          metric -> metric.numActiveAllocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "all")
          .description("The number of currently active allocations")
          .register(registry);
 
       Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric,
          metric -> metric.numActiveTinyAllocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny")
          .description("The number of currently active tiny allocations")
          .register(registry);
 
       Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric,
          metric -> metric.numActiveSmallAllocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small")
          .description("The number of currently active small allocations")
          .register(registry);
 
       Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric,
          metric -> metric.numActiveNormalAllocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "normal")
          .description("The number of currently active normal allocations")
          .register(registry);
 
       Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric,
          metric -> metric.numActiveHugeAllocations())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "huge")
          .description("The number of currently active huge allocations")
          .register(registry);
 
       Gauge.builder("netty.pooled.arena.active.allocated.num", poolArenaMetric,
          metric -> metric.numActiveBytes())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString)
          .description("The number of active bytes that are currently allocated by the arena")
          .baseUnit(BYTES_UNIT).register(registry);
 
       Gauge.builder("netty.pooled.arena.chunk.num", poolArenaMetric,
          metric -> metric.numChunkLists())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString)
          .description("The number of chunk lists for the arena")
          .register(registry);
 
       Gauge.builder("netty.pooled.arena.subpages.num", poolArenaMetric,
          metric -> metric.numTinySubpages())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny")
          .description("The number of tiny sub-pages for the arena")
          .register(registry);
 
       Gauge.builder("netty.pooled.arena.subpages.num", poolArenaMetric,
          metric -> metric.numSmallSubpages())
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small")
          .description("The number of small sub-pages for the arena")
          .register(registry);
@@ -287,7 +287,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
          .description("The total count of subpages")
          .register(registry);
@@ -299,7 +299,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
          .description("The total size (in bytes) of the elements that will be allocated")
          .baseUnit(BYTES_UNIT)
@@ -312,7 +312,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
          .description("The total number of maximal elements that can be allocated out of the sub-page.")
          .register(registry);
@@ -324,7 +324,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
          .description("The total number of available elements to be allocated")
          .register(registry);
@@ -335,7 +335,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
          .description("The total size (in bytes) of the pages")
          .baseUnit(BYTES_UNIT)
@@ -375,7 +375,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "pool_chunk_list_type", poolChunkListType)
          .description("The total capacity in bytes of the chunks in the list")
          .baseUnit(BYTES_UNIT)
@@ -387,7 +387,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "pool_chunk_list_type", poolChunkListType)
          .description("The total free bytes of the chunks in the list")
          .baseUnit(BYTES_UNIT)
@@ -400,7 +400,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
-         .tags(tags)
+         .tags(commonTags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "pool_chunk_list_type", poolChunkListType)
          .description("The number of chunks in the list")
          .register(registry);
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/LegacyConfigMetricsPluginTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/LegacyConfigMetricsPluginTest.java
new file mode 100644
index 0000000000..beb05dc5b2
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/LegacyConfigMetricsPluginTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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.activemq.artemis.tests.integration.plugin;
+
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.metrics.plugins.SimpleMetricsPlugin;
+
+public class LegacyConfigMetricsPluginTest extends MetricsPluginTest {
+
+   @Override
+   protected void configureServer(ActiveMQServer server) {
+      server.getConfiguration().setMetricsPlugin(new SimpleMetricsPlugin().init(null));
+   }
+}
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MetricsPluginTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MetricsPluginTest.java
index 8e289ff1a7..0c82318f5a 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MetricsPluginTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/MetricsPluginTest.java
@@ -17,16 +17,7 @@
 
 package org.apache.activemq.artemis.tests.integration.plugin;
 
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.lang.invoke.MethodHandles;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -53,54 +44,42 @@ import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.Queue;
 import org.apache.activemq.artemis.core.server.metrics.plugins.SimpleMetricsPlugin;
 import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy;
-import org.apache.activemq.artemis.tests.extensions.parameterized.ParameterizedTestExtension;
-import org.apache.activemq.artemis.tests.extensions.parameterized.Parameters;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.apache.activemq.artemis.tests.util.Wait;
 import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.TestTemplate;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@ExtendWith(ParameterizedTestExtension.class)
-public class MetricsPluginTest extends ActiveMQTestBase {
+import org.junit.jupiter.api.Test;
 
-   private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-   private boolean legacyConfig;
-
-   @Parameters(name = "legacyConfig={0}")
-   public static Collection<Object[]> getParams() {
-      return Arrays.asList(new Object[][]{{true}, {false}});
-   }
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
-   public MetricsPluginTest(boolean legacyConfig) {
-      this.legacyConfig = legacyConfig;
-   }
+public class MetricsPluginTest extends ActiveMQTestBase {
 
    protected ActiveMQServer server;
    protected ClientSession session;
    protected ClientSessionFactory sf;
    protected ServerLocator locator;
 
+   protected void configureServer(ActiveMQServer server) {
+      server.getConfiguration().setMetricsConfiguration(new MetricsConfiguration().setPlugin(new SimpleMetricsPlugin().init(null)));
+   }
+
    @Override
    @BeforeEach
    public void setUp() throws Exception {
       super.setUp();
       server = createServer(false, createDefaultInVMConfig());
-      if (legacyConfig) {
-         server.getConfiguration().setMetricsPlugin(new SimpleMetricsPlugin().init(null));
-      } else {
-         server.getConfiguration().setMetricsConfiguration(new MetricsConfiguration().setPlugin(new SimpleMetricsPlugin().init(null)));
-      }
+      configureServer(server);
       server.start();
       locator = createInVMNonHALocator();
       sf = createSessionFactory(locator);
       session = addClientSession(sf.createSession(false, true, true));
    }
 
-   @TestTemplate
+   @Test
    public void testForArtemisMetricsPresence() throws Exception {
       class Metric {
          public final String name;
@@ -195,12 +174,12 @@ public class MetricsPluginTest extends ActiveMQTestBase {
       ));
    }
 
-   @TestTemplate
+   @Test
    public void testForBasicMetricsPresenceAndValue() throws Exception {
       internalTestForBasicMetrics(true);
    }
 
-   @TestTemplate
+   @Test
    public void testDisablingMetrics() throws Exception {
       internalTestForBasicMetrics(false);
    }
@@ -262,7 +241,7 @@ public class MetricsPluginTest extends ActiveMQTestBase {
       checkMetric(metrics, "artemis.consumer.count", "queue", queueName, 0.0, enabled);
    }
 
-   @TestTemplate
+   @Test
    public void testMessageCountWithPaging() throws Exception {
       final String data = "Simple Text " + UUID.randomUUID().toString();
       final String queueName = "simpleQueue";
@@ -292,7 +271,7 @@ public class MetricsPluginTest extends ActiveMQTestBase {
       checkMetric(getMetrics(), "artemis.message.count", "queue", queueName, (double) (messageCount * 2));
    }
 
-   @TestTemplate
+   @Test
    public void testMetricsPluginRegistration() {
       assertEquals(SimpleMetricsPlugin.class, server.getConfiguration().getMetricsConfiguration().getPlugin().getClass());
       assertEquals(server, ((SimpleMetricsPlugin)server.getConfiguration().getMetricsConfiguration().getPlugin()).getServer());
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/PassthroughMetricsPluginTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/PassthroughMetricsPluginTest.java
new file mode 100644
index 0000000000..b7e5c324ac
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/plugin/PassthroughMetricsPluginTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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.activemq.artemis.tests.integration.plugin;
+
+import java.util.Map;
+
+import io.micrometer.core.instrument.Meter;
+import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tags;
+import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
+import org.apache.activemq.artemis.core.config.MetricsConfiguration;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.metrics.ActiveMQMetricsPlugin;
+import org.apache.activemq.artemis.utils.RandomUtil;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.activemq.artemis.core.server.metrics.MetricsManager.BROKER_TAG_NAME;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class PassthroughMetricsPluginTest extends MetricsPluginTest {
+
+   private MeterRegistry meterRegistry;
+
+   @Override
+   protected void configureServer(ActiveMQServer server) {
+      meterRegistry = new SimpleMeterRegistry();
+      server.getConfiguration().setMetricsConfiguration(new MetricsConfiguration().setPlugin(new ActiveMQMetricsPlugin() {
+         @Override
+         public ActiveMQMetricsPlugin init(Map<String, String> map) {
+            return this;
+         }
+
+         @Override
+         public MeterRegistry getRegistry() {
+            return meterRegistry;
+         }
+      }));
+   }
+
+   @Test
+   public void testPassthroughMeterRegistry() {
+      final String meterName = getName();
+      meterRegistry.gauge(meterName, Tags.of(meterName, RandomUtil.randomString()), RandomUtil.randomDouble(), random -> random.doubleValue());
+      boolean found = false;
+      for (Meter.Id meter : getMetrics().keySet()) {
+         if (meter.getName().equals(meterName)) {
+            found = true;
+            assertNull(meter.getTag(BROKER_TAG_NAME));
+            assertNotNull(meter.getTag(meterName));
+         }
+      }
+      assertTrue(found);
+   }
+
+   @Disabled
+   @Override
+   public void testMetricsPluginRegistration() {
+      // this overrides & disables a test that is not applicable for this use-case
+   }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@activemq.apache.org
For additional commands, e-mail: commits-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact