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:09 UTC

(activemq-artemis) 01/02: ARTEMIS-5045 don't change the Micrometer MeterRegistry config

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 91ddc6a2e75208ac0fffeb22323f59be0995c76a
Author: fogninid <d....@f12o.eu>
AuthorDate: Tue Sep 10 15:29:49 2024 +0100

    ARTEMIS-5045 don't change the Micrometer MeterRegistry config
    
    For embedded use-cases the Micrometer MeterRegistry may be passed in
    from the application and used for other meters unrelated to the broker.
    Therefore, the broker should not change the config of the MeterRegistry
    (e.g. by adding common tags to all meters) as the config change(s) may
    be incompatible with the needs of the embedding application.
---
 .../core/server/metrics/MetricsManager.java        | 39 +++++++++++--------
 .../metrics/NettyPooledAllocatorMetrics.java       | 44 +++++++++++++++++++++-
 2 files changed, 65 insertions(+), 18 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 6f6d6caa9b..9915753ed2 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
@@ -31,6 +31,7 @@ import io.micrometer.core.instrument.Meter;
 import io.micrometer.core.instrument.MeterRegistry;
 import io.micrometer.core.instrument.Metrics;
 import io.micrometer.core.instrument.Tag;
+import io.micrometer.core.instrument.Tags;
 import io.micrometer.core.instrument.binder.cache.CaffeineCacheMetrics;
 import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
 import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
@@ -56,6 +57,7 @@ public class MetricsManager {
 
    private final String brokerName;
 
+   private final Tags tags;
    private final MeterRegistry meterRegistry;
 
    private final Map<String, List<Meter>> meters = new ConcurrentHashMap<>();
@@ -69,36 +71,38 @@ public class MetricsManager {
       this.brokerName = brokerName;
       this.meterRegistry = metricsConfiguration.getPlugin().getRegistry();
       this.addressSettingsRepository = addressSettingsRepository;
+      this.tags = Tags.of("broker", brokerName);
       if (meterRegistry != null) {
          Metrics.globalRegistry.add(meterRegistry);
-         meterRegistry.config().commonTags("broker", brokerName);
          if (metricsConfiguration.isJvmMemory()) {
-            new JvmMemoryMetrics().bindTo(meterRegistry);
+            new JvmMemoryMetrics(tags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isJvmGc()) {
-            new JvmGcMetrics().bindTo(meterRegistry);
+            new JvmGcMetrics(tags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isJvmThread()) {
-            new JvmThreadMetrics().bindTo(meterRegistry);
+            new JvmThreadMetrics(tags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isNettyPool()) {
-            new NettyPooledAllocatorMetrics(PooledByteBufAllocator.DEFAULT.metric()).bindTo(meterRegistry);
+            new NettyPooledAllocatorMetrics(PooledByteBufAllocator.DEFAULT.metric(), tags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isFileDescriptors()) {
-            new FileDescriptorMetrics().bindTo(meterRegistry);
+            new FileDescriptorMetrics(tags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isProcessor()) {
-            new ProcessorMetrics().bindTo(meterRegistry);
+            new ProcessorMetrics(tags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isUptime()) {
-            new UptimeMetrics().bindTo(meterRegistry);
+            new UptimeMetrics(tags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isLogging()) {
-            new Log4j2Metrics().bindTo(meterRegistry);
+            new Log4j2Metrics(tags).bindTo(meterRegistry);
          }
          if (metricsConfiguration.isSecurityCaches() && securityStore.isSecurityEnabled()) {
-            CaffeineCacheMetrics.monitor(meterRegistry, ((SecurityStoreImpl)securityStore).getAuthenticationCache(), "authentication");
-            CaffeineCacheMetrics.monitor(meterRegistry, ((SecurityStoreImpl)securityStore).getAuthorizationCache(), "authorization");
+            CaffeineCacheMetrics.monitor(meterRegistry,
+               ((SecurityStoreImpl)securityStore).getAuthenticationCache(), "authentication", tags);
+            CaffeineCacheMetrics.monitor(meterRegistry,
+               ((SecurityStoreImpl)securityStore).getAuthorizationCache(), "authorization", tags);
          }
       }
    }
@@ -118,12 +122,13 @@ public class MetricsManager {
          return;
       }
       final List<Builder<Object>> gaugeBuilders = new ArrayList<>();
-      builder.accept((metricName, state, f, description, tags) -> {
+      builder.accept((metricName, state, f, description, gaugeTags) -> {
          Builder<Object> meter = Gauge
             .builder("artemis." + metricName, state, f)
+            .tags(tags)
+            .tags(gaugeTags)
             .tag("address", address)
             .tag("queue", queue)
-            .tags(tags)
             .description(description);
          gaugeBuilders.add(meter);
       });
@@ -135,11 +140,12 @@ public class MetricsManager {
          return;
       }
       final List<Builder<Object>> gaugeBuilders = new ArrayList<>();
-      builder.accept((metricName, state, f, description, tags) -> {
+      builder.accept((metricName, state, f, description, gaugeTags) -> {
          Builder<Object> meter = Gauge
             .builder("artemis." + metricName, state, f)
-            .tag("address", address)
             .tags(tags)
+            .tags(gaugeTags)
+            .tag("address", address)
             .description(description);
          gaugeBuilders.add(meter);
       });
@@ -151,10 +157,11 @@ public class MetricsManager {
          return;
       }
       final List<Builder<Object>> gaugeBuilders = new ArrayList<>();
-      builder.accept((metricName, state, f, description, tags) -> {
+      builder.accept((metricName, state, f, description, gaugeTags) -> {
          Builder<Object> meter = Gauge
             .builder("artemis." + metricName, state, f)
             .tags(tags)
+            .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 6274d8d2fd..23f8af0316 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
@@ -21,6 +21,7 @@ import java.util.function.Function;
 
 import io.micrometer.core.instrument.Gauge;
 import io.micrometer.core.instrument.MeterRegistry;
+import io.micrometer.core.instrument.Tags;
 import io.micrometer.core.instrument.binder.MeterBinder;
 import io.netty.buffer.PoolChunkListMetric;
 import io.netty.buffer.PoolChunkMetric;
@@ -33,53 +34,64 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
 
    private static final String BYTES_UNIT = "bytes";
    private final PooledByteBufAllocatorMetric metric;
+   private final Tags tags;
 
-   public NettyPooledAllocatorMetrics(final PooledByteBufAllocatorMetric pooledAllocatorMetric) {
+   public NettyPooledAllocatorMetrics(final PooledByteBufAllocatorMetric pooledAllocatorMetric, final Tags tags) {
       this.metric = pooledAllocatorMetric;
+      this.tags = tags;
    }
 
    @Override
    public void bindTo(final MeterRegistry registry) {
 
       Gauge.builder("netty.pooled.used.memory", this.metric, metric -> metric.usedDirectMemory())
+         .tags(tags)
          .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("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("type", "direct")
          .description("The number of arenas")
          .register(registry);
 
       Gauge.builder("netty.pooled.arenas.num", this.metric, metric -> metric.numHeapArenas())
+         .tags(tags)
          .tags("type", "heap").description("The number or arenas")
          .register(registry);
 
       Gauge.builder("netty.pooled.cachesize", this.metric, metric -> metric.tinyCacheSize())
+         .tags(tags)
          .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("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("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)
          .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)
          .description("The arena chunk size of this netty allocator")
          .baseUnit(BYTES_UNIT)
          .register(registry);
@@ -107,120 +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("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("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("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("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("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("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("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("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("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("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("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("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("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("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("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("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("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("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("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("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small")
          .description("The number of small sub-pages for the arena")
          .register(registry);
@@ -255,6 +287,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
+         .tags(tags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
          .description("The total count of subpages")
          .register(registry);
@@ -266,6 +299,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
+         .tags(tags)
          .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)
@@ -278,6 +312,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
+         .tags(tags)
          .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);
@@ -289,6 +324,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
+         .tags(tags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
          .description("The total number of available elements to be allocated")
          .register(registry);
@@ -299,6 +335,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
+         .tags(tags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
          .description("The total size (in bytes) of the pages")
          .baseUnit(BYTES_UNIT)
@@ -338,6 +375,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
+         .tags(tags)
          .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)
@@ -349,6 +387,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
+         .tags(tags)
          .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)
@@ -361,9 +400,10 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
          }
          return total;
       })
+         .tags(tags)
          .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "pool_chunk_list_type", poolChunkListType)
          .description("The number of chunks in the list")
          .register(registry);
    }
 
-}
\ No newline at end of file
+}


---------------------------------------------------------------------
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