ARTEMIS-5045 add test + polish

This commit is contained in:
Justin Bertram 2024-09-10 17:01:20 -05:00 committed by Robbie Gemmell
parent 91ddc6a2e7
commit dc64d9be78
5 changed files with 180 additions and 96 deletions

View File

@ -53,11 +53,13 @@ import org.slf4j.LoggerFactory;
public class MetricsManager { public class MetricsManager {
public static final String BROKER_TAG_NAME = "broker";
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final String brokerName; private final String brokerName;
private final Tags tags; private final Tags commonTags;
private final MeterRegistry meterRegistry; private final MeterRegistry meterRegistry;
private final Map<String, List<Meter>> meters = new ConcurrentHashMap<>(); private final Map<String, List<Meter>> meters = new ConcurrentHashMap<>();
@ -71,38 +73,36 @@ public class MetricsManager {
this.brokerName = brokerName; this.brokerName = brokerName;
this.meterRegistry = metricsConfiguration.getPlugin().getRegistry(); this.meterRegistry = metricsConfiguration.getPlugin().getRegistry();
this.addressSettingsRepository = addressSettingsRepository; this.addressSettingsRepository = addressSettingsRepository;
this.tags = Tags.of("broker", brokerName); this.commonTags = Tags.of(BROKER_TAG_NAME, brokerName);
if (meterRegistry != null) { if (meterRegistry != null) {
Metrics.globalRegistry.add(meterRegistry); Metrics.globalRegistry.add(meterRegistry);
if (metricsConfiguration.isJvmMemory()) { if (metricsConfiguration.isJvmMemory()) {
new JvmMemoryMetrics(tags).bindTo(meterRegistry); new JvmMemoryMetrics(commonTags).bindTo(meterRegistry);
} }
if (metricsConfiguration.isJvmGc()) { if (metricsConfiguration.isJvmGc()) {
new JvmGcMetrics(tags).bindTo(meterRegistry); new JvmGcMetrics(commonTags).bindTo(meterRegistry);
} }
if (metricsConfiguration.isJvmThread()) { if (metricsConfiguration.isJvmThread()) {
new JvmThreadMetrics(tags).bindTo(meterRegistry); new JvmThreadMetrics(commonTags).bindTo(meterRegistry);
} }
if (metricsConfiguration.isNettyPool()) { if (metricsConfiguration.isNettyPool()) {
new NettyPooledAllocatorMetrics(PooledByteBufAllocator.DEFAULT.metric(), tags).bindTo(meterRegistry); new NettyPooledAllocatorMetrics(PooledByteBufAllocator.DEFAULT.metric(), commonTags).bindTo(meterRegistry);
} }
if (metricsConfiguration.isFileDescriptors()) { if (metricsConfiguration.isFileDescriptors()) {
new FileDescriptorMetrics(tags).bindTo(meterRegistry); new FileDescriptorMetrics(commonTags).bindTo(meterRegistry);
} }
if (metricsConfiguration.isProcessor()) { if (metricsConfiguration.isProcessor()) {
new ProcessorMetrics(tags).bindTo(meterRegistry); new ProcessorMetrics(commonTags).bindTo(meterRegistry);
} }
if (metricsConfiguration.isUptime()) { if (metricsConfiguration.isUptime()) {
new UptimeMetrics(tags).bindTo(meterRegistry); new UptimeMetrics(commonTags).bindTo(meterRegistry);
} }
if (metricsConfiguration.isLogging()) { if (metricsConfiguration.isLogging()) {
new Log4j2Metrics(tags).bindTo(meterRegistry); new Log4j2Metrics(commonTags).bindTo(meterRegistry);
} }
if (metricsConfiguration.isSecurityCaches() && securityStore.isSecurityEnabled()) { if (metricsConfiguration.isSecurityCaches() && securityStore.isSecurityEnabled()) {
CaffeineCacheMetrics.monitor(meterRegistry, CaffeineCacheMetrics.monitor(meterRegistry, ((SecurityStoreImpl)securityStore).getAuthenticationCache(), "authentication", commonTags);
((SecurityStoreImpl)securityStore).getAuthenticationCache(), "authentication", tags); CaffeineCacheMetrics.monitor(meterRegistry, ((SecurityStoreImpl)securityStore).getAuthorizationCache(), "authorization", commonTags);
CaffeineCacheMetrics.monitor(meterRegistry,
((SecurityStoreImpl)securityStore).getAuthorizationCache(), "authorization", tags);
} }
} }
} }
@ -125,7 +125,7 @@ public class MetricsManager {
builder.accept((metricName, state, f, description, gaugeTags) -> { builder.accept((metricName, state, f, description, gaugeTags) -> {
Builder<Object> meter = Gauge Builder<Object> meter = Gauge
.builder("artemis." + metricName, state, f) .builder("artemis." + metricName, state, f)
.tags(tags) .tags(commonTags)
.tags(gaugeTags) .tags(gaugeTags)
.tag("address", address) .tag("address", address)
.tag("queue", queue) .tag("queue", queue)
@ -143,7 +143,7 @@ public class MetricsManager {
builder.accept((metricName, state, f, description, gaugeTags) -> { builder.accept((metricName, state, f, description, gaugeTags) -> {
Builder<Object> meter = Gauge Builder<Object> meter = Gauge
.builder("artemis." + metricName, state, f) .builder("artemis." + metricName, state, f)
.tags(tags) .tags(commonTags)
.tags(gaugeTags) .tags(gaugeTags)
.tag("address", address) .tag("address", address)
.description(description); .description(description);
@ -160,7 +160,7 @@ public class MetricsManager {
builder.accept((metricName, state, f, description, gaugeTags) -> { builder.accept((metricName, state, f, description, gaugeTags) -> {
Builder<Object> meter = Gauge Builder<Object> meter = Gauge
.builder("artemis." + metricName, state, f) .builder("artemis." + metricName, state, f)
.tags(tags) .tags(commonTags)
.tags(gaugeTags) .tags(gaugeTags)
.description(description); .description(description);
gaugeBuilders.add(meter); gaugeBuilders.add(meter);

View File

@ -34,64 +34,64 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
private static final String BYTES_UNIT = "bytes"; private static final String BYTES_UNIT = "bytes";
private final PooledByteBufAllocatorMetric metric; 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.metric = pooledAllocatorMetric;
this.tags = tags; this.commonTags = commonTags;
} }
@Override @Override
public void bindTo(final MeterRegistry registry) { public void bindTo(final MeterRegistry registry) {
Gauge.builder("netty.pooled.used.memory", this.metric, metric -> metric.usedDirectMemory()) Gauge.builder("netty.pooled.used.memory", this.metric, metric -> metric.usedDirectMemory())
.tags(tags) .tags(commonTags)
.tags("type", "direct") .tags("type", "direct")
.description("The used memory") .description("The used memory")
.baseUnit(BYTES_UNIT).register(registry); .baseUnit(BYTES_UNIT).register(registry);
Gauge.builder("netty.pooled.used.memory", this.metric, metric -> metric.usedHeapMemory()) Gauge.builder("netty.pooled.used.memory", this.metric, metric -> metric.usedHeapMemory())
.tags(tags) .tags(commonTags)
.tags("type", "heap") .tags("type", "heap")
.description("The used memory") .description("The used memory")
.baseUnit(BYTES_UNIT).register(registry); .baseUnit(BYTES_UNIT).register(registry);
Gauge.builder("netty.pooled.arenas.num", this.metric, metric -> metric.numDirectArenas()) Gauge.builder("netty.pooled.arenas.num", this.metric, metric -> metric.numDirectArenas())
.tags(tags) .tags(commonTags)
.tags("type", "direct") .tags("type", "direct")
.description("The number of arenas") .description("The number of arenas")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.arenas.num", this.metric, metric -> metric.numHeapArenas()) Gauge.builder("netty.pooled.arenas.num", this.metric, metric -> metric.numHeapArenas())
.tags(tags) .tags(commonTags)
.tags("type", "heap").description("The number or arenas") .tags("type", "heap").description("The number or arenas")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.cachesize", this.metric, metric -> metric.tinyCacheSize()) Gauge.builder("netty.pooled.cachesize", this.metric, metric -> metric.tinyCacheSize())
.tags(tags) .tags(commonTags)
.tags("type", "tiny") .tags("type", "tiny")
.description("The cachesize used by this netty allocator") .description("The cachesize used by this netty allocator")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.cachesize", this.metric, metric -> metric.smallCacheSize()) Gauge.builder("netty.pooled.cachesize", this.metric, metric -> metric.smallCacheSize())
.tags(tags) .tags(commonTags)
.tags("type", "small") .tags("type", "small")
.description("The cachesize used by this netty allocator") .description("The cachesize used by this netty allocator")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.cachesize", this.metric, metric -> metric.normalCacheSize()) Gauge.builder("netty.pooled.cachesize", this.metric, metric -> metric.normalCacheSize())
.tags(tags) .tags(commonTags)
.tags("type", "normal") .tags("type", "normal")
.description("The cachesize used by this netty allocator") .description("The cachesize used by this netty allocator")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.threadlocalcache.num", this.metric, metric -> metric.numThreadLocalCaches()) 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") .description("The number of thread local caches used by this netty allocator")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.chunk.size", this.metric, metric -> metric.chunkSize()) Gauge.builder("netty.pooled.chunk.size", this.metric, metric -> metric.chunkSize())
.tags(tags) .tags(commonTags)
.description("The arena chunk size of this netty allocator") .description("The arena chunk size of this netty allocator")
.baseUnit(BYTES_UNIT) .baseUnit(BYTES_UNIT)
.register(registry); .register(registry);
@ -119,140 +119,140 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
*/ */
final String poolArenaIndexString = Integer.toString(poolArenaIndex); final String poolArenaIndexString = Integer.toString(poolArenaIndex);
Gauge.builder("netty.pooled.arena.threadcaches.num", poolArenaMetric, metric -> metric.numThreadCaches()) Gauge.builder("netty.pooled.arena.threadcaches.num", poolArenaMetric, metric -> metric.numThreadCaches())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString) .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString)
.description("The number of thread caches backed by this arena") .description("The number of thread caches backed by this arena")
.register(registry); .register(registry);
FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric, FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric,
metric -> metric.numAllocations()) metric -> metric.numAllocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "all") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "all")
.description("The number of allocations done via the arena. This includes all sizes") .description("The number of allocations done via the arena. This includes all sizes")
.register(registry); .register(registry);
FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric, FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric,
metric -> metric.numTinyAllocations()) metric -> metric.numTinyAllocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny")
.description("The number of tiny allocations done via the arena") .description("The number of tiny allocations done via the arena")
.register(registry); .register(registry);
FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric, FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric,
metric -> metric.numSmallAllocations()) metric -> metric.numSmallAllocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small")
.description("The number of small allocations done via the arena") .description("The number of small allocations done via the arena")
.register(registry); .register(registry);
FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric, FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric,
metric -> metric.numNormalAllocations()) metric -> metric.numNormalAllocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "normal") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "normal")
.description("The number of normal allocations done via the arena") .description("The number of normal allocations done via the arena")
.register(registry); .register(registry);
FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric, FunctionCounter.builder("netty.pooled.arena.allocations.num", poolArenaMetric,
metric -> metric.numHugeAllocations()) metric -> metric.numHugeAllocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "huge") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "huge")
.description("The number of huge allocations done via the arena") .description("The number of huge allocations done via the arena")
.register(registry); .register(registry);
FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric, FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric,
metric -> metric.numDeallocations()) metric -> metric.numDeallocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "all") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "all")
.description("The number of deallocations done via the arena. This includes all sizes") .description("The number of deallocations done via the arena. This includes all sizes")
.register(registry); .register(registry);
FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric, FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric,
metric -> metric.numTinyDeallocations()) metric -> metric.numTinyDeallocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny")
.description("The number of tiny deallocations done via the arena") .description("The number of tiny deallocations done via the arena")
.register(registry); .register(registry);
FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric, FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric,
metric -> metric.numSmallDeallocations()) metric -> metric.numSmallDeallocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small")
.description("The number of small deallocations done via the arena") .description("The number of small deallocations done via the arena")
.register(registry); .register(registry);
FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric, FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric,
metric -> metric.numNormalDeallocations()) metric -> metric.numNormalDeallocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "normal") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "normal")
.description("The number of normal deallocations done via the arena") .description("The number of normal deallocations done via the arena")
.register(registry); .register(registry);
FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric, FunctionCounter.builder("netty.pooled.arena.deallocations.num", poolArenaMetric,
metric -> metric.numHugeDeallocations()) metric -> metric.numHugeDeallocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "huge") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "huge")
.description("The number of huge deallocations done via the arena") .description("The number of huge deallocations done via the arena")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric, Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric,
metric -> metric.numActiveAllocations()) metric -> metric.numActiveAllocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "all") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "all")
.description("The number of currently active allocations") .description("The number of currently active allocations")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric, Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric,
metric -> metric.numActiveTinyAllocations()) metric -> metric.numActiveTinyAllocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny")
.description("The number of currently active tiny allocations") .description("The number of currently active tiny allocations")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric, Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric,
metric -> metric.numActiveSmallAllocations()) metric -> metric.numActiveSmallAllocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small")
.description("The number of currently active small allocations") .description("The number of currently active small allocations")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric, Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric,
metric -> metric.numActiveNormalAllocations()) metric -> metric.numActiveNormalAllocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "normal") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "normal")
.description("The number of currently active normal allocations") .description("The number of currently active normal allocations")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric, Gauge.builder("netty.pooled.arena.active.allocations.num", poolArenaMetric,
metric -> metric.numActiveHugeAllocations()) metric -> metric.numActiveHugeAllocations())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "huge") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "huge")
.description("The number of currently active huge allocations") .description("The number of currently active huge allocations")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.arena.active.allocated.num", poolArenaMetric, Gauge.builder("netty.pooled.arena.active.allocated.num", poolArenaMetric,
metric -> metric.numActiveBytes()) metric -> metric.numActiveBytes())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString) .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString)
.description("The number of active bytes that are currently allocated by the arena") .description("The number of active bytes that are currently allocated by the arena")
.baseUnit(BYTES_UNIT).register(registry); .baseUnit(BYTES_UNIT).register(registry);
Gauge.builder("netty.pooled.arena.chunk.num", poolArenaMetric, Gauge.builder("netty.pooled.arena.chunk.num", poolArenaMetric,
metric -> metric.numChunkLists()) metric -> metric.numChunkLists())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString) .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString)
.description("The number of chunk lists for the arena") .description("The number of chunk lists for the arena")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.arena.subpages.num", poolArenaMetric, Gauge.builder("netty.pooled.arena.subpages.num", poolArenaMetric,
metric -> metric.numTinySubpages()) metric -> metric.numTinySubpages())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "tiny")
.description("The number of tiny sub-pages for the arena") .description("The number of tiny sub-pages for the arena")
.register(registry); .register(registry);
Gauge.builder("netty.pooled.arena.subpages.num", poolArenaMetric, Gauge.builder("netty.pooled.arena.subpages.num", poolArenaMetric,
metric -> metric.numSmallSubpages()) metric -> metric.numSmallSubpages())
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small") .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndexString, "size", "small")
.description("The number of small sub-pages for the arena") .description("The number of small sub-pages for the arena")
.register(registry); .register(registry);
@ -287,7 +287,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
} }
return total; return total;
}) })
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size) .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
.description("The total count of subpages") .description("The total count of subpages")
.register(registry); .register(registry);
@ -299,7 +299,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
} }
return total; return total;
}) })
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size) .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
.description("The total size (in bytes) of the elements that will be allocated") .description("The total size (in bytes) of the elements that will be allocated")
.baseUnit(BYTES_UNIT) .baseUnit(BYTES_UNIT)
@ -312,7 +312,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
} }
return total; return total;
}) })
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size) .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.") .description("The total number of maximal elements that can be allocated out of the sub-page.")
.register(registry); .register(registry);
@ -324,7 +324,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
} }
return total; return total;
}) })
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size) .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
.description("The total number of available elements to be allocated") .description("The total number of available elements to be allocated")
.register(registry); .register(registry);
@ -335,7 +335,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
} }
return total; return total;
}) })
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size) .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "size", size)
.description("The total size (in bytes) of the pages") .description("The total size (in bytes) of the pages")
.baseUnit(BYTES_UNIT) .baseUnit(BYTES_UNIT)
@ -375,7 +375,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
} }
return total; return total;
}) })
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "pool_chunk_list_type", poolChunkListType) .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") .description("The total capacity in bytes of the chunks in the list")
.baseUnit(BYTES_UNIT) .baseUnit(BYTES_UNIT)
@ -387,7 +387,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
} }
return total; return total;
}) })
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "pool_chunk_list_type", poolChunkListType) .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") .description("The total free bytes of the chunks in the list")
.baseUnit(BYTES_UNIT) .baseUnit(BYTES_UNIT)
@ -400,7 +400,7 @@ public final class NettyPooledAllocatorMetrics implements MeterBinder {
} }
return total; return total;
}) })
.tags(tags) .tags(commonTags)
.tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "pool_chunk_list_type", poolChunkListType) .tags("pool_arena_type", poolArenaType, "pool_arena_index", poolArenaIndex, "pool_chunk_list_type", poolChunkListType)
.description("The number of chunks in the list") .description("The number of chunks in the list")
.register(registry); .register(registry);

View File

@ -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));
}
}

View File

@ -17,16 +17,7 @@
package org.apache.activemq.artemis.tests.integration.plugin; 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.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; 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.Queue;
import org.apache.activemq.artemis.core.server.metrics.plugins.SimpleMetricsPlugin; import org.apache.activemq.artemis.core.server.metrics.plugins.SimpleMetricsPlugin;
import org.apache.activemq.artemis.core.settings.impl.AddressFullMessagePolicy; 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.ActiveMQTestBase;
import org.apache.activemq.artemis.tests.util.Wait; import org.apache.activemq.artemis.tests.util.Wait;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestTemplate; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.slf4j.Logger; import static org.hamcrest.MatcherAssert.assertThat;
import org.slf4j.LoggerFactory; 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;
@ExtendWith(ParameterizedTestExtension.class)
public class MetricsPluginTest extends ActiveMQTestBase { public class MetricsPluginTest extends ActiveMQTestBase {
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}});
}
public MetricsPluginTest(boolean legacyConfig) {
this.legacyConfig = legacyConfig;
}
protected ActiveMQServer server; protected ActiveMQServer server;
protected ClientSession session; protected ClientSession session;
protected ClientSessionFactory sf; protected ClientSessionFactory sf;
protected ServerLocator locator; protected ServerLocator locator;
protected void configureServer(ActiveMQServer server) {
server.getConfiguration().setMetricsConfiguration(new MetricsConfiguration().setPlugin(new SimpleMetricsPlugin().init(null)));
}
@Override @Override
@BeforeEach @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
server = createServer(false, createDefaultInVMConfig()); server = createServer(false, createDefaultInVMConfig());
if (legacyConfig) { configureServer(server);
server.getConfiguration().setMetricsPlugin(new SimpleMetricsPlugin().init(null));
} else {
server.getConfiguration().setMetricsConfiguration(new MetricsConfiguration().setPlugin(new SimpleMetricsPlugin().init(null)));
}
server.start(); server.start();
locator = createInVMNonHALocator(); locator = createInVMNonHALocator();
sf = createSessionFactory(locator); sf = createSessionFactory(locator);
session = addClientSession(sf.createSession(false, true, true)); session = addClientSession(sf.createSession(false, true, true));
} }
@TestTemplate @Test
public void testForArtemisMetricsPresence() throws Exception { public void testForArtemisMetricsPresence() throws Exception {
class Metric { class Metric {
public final String name; public final String name;
@ -195,12 +174,12 @@ public class MetricsPluginTest extends ActiveMQTestBase {
)); ));
} }
@TestTemplate @Test
public void testForBasicMetricsPresenceAndValue() throws Exception { public void testForBasicMetricsPresenceAndValue() throws Exception {
internalTestForBasicMetrics(true); internalTestForBasicMetrics(true);
} }
@TestTemplate @Test
public void testDisablingMetrics() throws Exception { public void testDisablingMetrics() throws Exception {
internalTestForBasicMetrics(false); internalTestForBasicMetrics(false);
} }
@ -262,7 +241,7 @@ public class MetricsPluginTest extends ActiveMQTestBase {
checkMetric(metrics, "artemis.consumer.count", "queue", queueName, 0.0, enabled); checkMetric(metrics, "artemis.consumer.count", "queue", queueName, 0.0, enabled);
} }
@TestTemplate @Test
public void testMessageCountWithPaging() throws Exception { public void testMessageCountWithPaging() throws Exception {
final String data = "Simple Text " + UUID.randomUUID().toString(); final String data = "Simple Text " + UUID.randomUUID().toString();
final String queueName = "simpleQueue"; final String queueName = "simpleQueue";
@ -292,7 +271,7 @@ public class MetricsPluginTest extends ActiveMQTestBase {
checkMetric(getMetrics(), "artemis.message.count", "queue", queueName, (double) (messageCount * 2)); checkMetric(getMetrics(), "artemis.message.count", "queue", queueName, (double) (messageCount * 2));
} }
@TestTemplate @Test
public void testMetricsPluginRegistration() { public void testMetricsPluginRegistration() {
assertEquals(SimpleMetricsPlugin.class, server.getConfiguration().getMetricsConfiguration().getPlugin().getClass()); assertEquals(SimpleMetricsPlugin.class, server.getConfiguration().getMetricsConfiguration().getPlugin().getClass());
assertEquals(server, ((SimpleMetricsPlugin)server.getConfiguration().getMetricsConfiguration().getPlugin()).getServer()); assertEquals(server, ((SimpleMetricsPlugin)server.getConfiguration().getMetricsConfiguration().getPlugin()).getServer());

View File

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