fixing lookup based on MetricId and not String anymore
diff --git a/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/ConcurrentGaugeInterceptor.java b/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/ConcurrentGaugeInterceptor.java
index 3ef809f..f87aed1 100644
--- a/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/ConcurrentGaugeInterceptor.java
+++ b/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/ConcurrentGaugeInterceptor.java
@@ -39,6 +39,7 @@
import org.eclipse.microprofile.metrics.ConcurrentGauge;
import org.eclipse.microprofile.metrics.MetricID;
import org.eclipse.microprofile.metrics.MetricRegistry;
+import org.eclipse.microprofile.metrics.Tag;
@Interceptor
@Priority(Interceptor.Priority.LIBRARY_BEFORE)
@@ -54,6 +55,9 @@
@Inject
private BeanManager beanManager;
+ @Inject
+ private MetricsExtension extension;
+
private transient volatile ConcurrentMap<Executable, Meta> gauges = new ConcurrentHashMap<>();
@AroundConstruct
@@ -89,24 +93,25 @@
Meta meta = gauges.get(executable);
if (meta == null) {
final AnnotatedType<?> type = beanManager.createAnnotatedType(bean.getBeanClass());
- final org.eclipse.microprofile.metrics.annotation.ConcurrentGauge counted = Stream.concat(type.getMethods().stream(), type.getConstructors().stream())
+ final org.eclipse.microprofile.metrics.annotation.ConcurrentGauge concurrentGauge = Stream.concat(type.getMethods().stream(), type.getConstructors().stream())
.filter(it -> it.getJavaMember().equals(executable))
.findFirst()
.map(m -> m.getAnnotation(org.eclipse.microprofile.metrics.annotation.ConcurrentGauge.class))
.orElse(null);
final String name = Names.findName(
Modifier.isAbstract(executable.getDeclaringClass().getModifiers()) ? type.getJavaClass() : executable.getDeclaringClass(),
- executable, counted == null ? null : counted.name(),
- counted != null && counted.absolute(),
+ executable, concurrentGauge == null ? null : concurrentGauge.name(),
+ concurrentGauge != null && concurrentGauge.absolute(),
ofNullable(type.getAnnotation(org.eclipse.microprofile.metrics.annotation.ConcurrentGauge.class))
.map(org.eclipse.microprofile.metrics.annotation.ConcurrentGauge::name)
.orElse(""));
- final ConcurrentGauge counter = ConcurrentGauge.class.cast(registry.getMetrics().get(new MetricID(name)));
+ final ConcurrentGauge counter = ConcurrentGauge.class.cast(registry.getMetrics().get(
+ new MetricID(name, concurrentGauge == null ? new Tag[0] : extension.createTags(concurrentGauge.tags()))));
if (counter == null) {
throw new IllegalStateException("No counter with name [" + name + "] found in registry [" + registry + "]");
}
- meta = new Meta(counter, !ofNullable(counted)
+ meta = new Meta(counter, !ofNullable(concurrentGauge)
.orElseGet(() -> type.getAnnotation(org.eclipse.microprofile.metrics.annotation.ConcurrentGauge.class)).absolute());
gauges.putIfAbsent(executable, meta);
}
diff --git a/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/CountedInterceptor.java b/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/CountedInterceptor.java
index d8e9efe..386f745 100644
--- a/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/CountedInterceptor.java
+++ b/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/CountedInterceptor.java
@@ -37,7 +37,9 @@
import javax.interceptor.InvocationContext;
import org.eclipse.microprofile.metrics.Counter;
+import org.eclipse.microprofile.metrics.MetricID;
import org.eclipse.microprofile.metrics.MetricRegistry;
+import org.eclipse.microprofile.metrics.Tag;
import org.eclipse.microprofile.metrics.annotation.Counted;
@Counted
@@ -54,6 +56,9 @@
@Inject
private BeanManager beanManager;
+ @Inject
+ private MetricsExtension extension;
+
private transient volatile ConcurrentMap<Executable, Meta> counters = new ConcurrentHashMap<>();
@AroundConstruct
@@ -94,7 +99,8 @@
counted != null && counted.absolute(),
ofNullable(type.getAnnotation(Counted.class)).map(Counted::name).orElse(""));
- final Counter counter = Counter.class.cast(registry.getMetrics().get(name));
+ final Counter counter = Counter.class.cast(registry.getMetrics().get(
+ new MetricID(name, counted == null ? new Tag[0] : extension.createTags(counted.tags()))));
if (counter == null) {
throw new IllegalStateException("No counter with name [" + name + "] found in registry [" + registry + "]");
}
diff --git a/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/MeteredInterceptor.java b/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/MeteredInterceptor.java
index ef68df5..a944811 100644
--- a/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/MeteredInterceptor.java
+++ b/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/MeteredInterceptor.java
@@ -37,7 +37,9 @@
import javax.interceptor.InvocationContext;
import org.eclipse.microprofile.metrics.Meter;
+import org.eclipse.microprofile.metrics.MetricID;
import org.eclipse.microprofile.metrics.MetricRegistry;
+import org.eclipse.microprofile.metrics.Tag;
import org.eclipse.microprofile.metrics.annotation.Metered;
@Metered
@@ -54,6 +56,9 @@
@Inject
private BeanManager beanManager;
+ @Inject
+ private MetricsExtension extension;
+
private transient volatile ConcurrentMap<Executable, Meter> meters = new ConcurrentHashMap<>();
@AroundConstruct
@@ -90,7 +95,8 @@
metered != null && metered.absolute(),
ofNullable(type.getAnnotation(Metered.class)).map(Metered::name).orElse(""));
- meter = Meter.class.cast(registry.getMetrics().get(name));
+ meter = Meter.class.cast(registry.getMetrics().get(
+ new MetricID(name, metered == null ? new Tag[0] : extension.createTags(metered.tags()))));
if (meter == null) {
throw new IllegalStateException("No meter with name [" + name + "] found in registry [" + registry + "]");
}
diff --git a/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/MetricsExtension.java b/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/MetricsExtension.java
index e4043ab..c8ec2e2 100644
--- a/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/MetricsExtension.java
+++ b/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/MetricsExtension.java
@@ -193,7 +193,7 @@
}
}
- private Tag[] createTags(final String[] tags) {
+ public Tag[] createTags(final String[] tags) {
return Stream.of(tags).filter(it -> it.contains("=")).map(it -> {
final int sep = it.indexOf("=");
return new Tag(it.substring(0, sep), it.substring(sep + 1));
diff --git a/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/TimedInterceptor.java b/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/TimedInterceptor.java
index 5d3bf36..f760c83 100644
--- a/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/TimedInterceptor.java
+++ b/geronimo-metrics/src/main/java/org/apache/geronimo/microprofile/metrics/cdi/TimedInterceptor.java
@@ -36,7 +36,9 @@
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
+import org.eclipse.microprofile.metrics.MetricID;
import org.eclipse.microprofile.metrics.MetricRegistry;
+import org.eclipse.microprofile.metrics.Tag;
import org.eclipse.microprofile.metrics.Timer;
import org.eclipse.microprofile.metrics.annotation.Timed;
@@ -89,7 +91,8 @@
Modifier.isAbstract(executable.getDeclaringClass().getModifiers()) ? type.getJavaClass() : executable.getDeclaringClass(),
executable, timed == null ? null : timed.name(), timed != null && timed.absolute(),
ofNullable(type.getAnnotation(Timed.class)).map(Timed::name).orElse(""));
- timer = Timer.class.cast(registry.getMetrics().get(name));
+ timer = Timer.class.cast(registry.getMetrics().get(
+ new MetricID(name, timed == null ? new Tag[0] : extension.createTags(timed.tags()))));
if (timer == null) {
throw new IllegalStateException("No timer with name [" + name + "] found in registry [" + registry + "]");
}