Skip to content
Permalink
Browse files
fixing concurrent gauge interceptor decr call
  • Loading branch information
rmannibucau committed Dec 31, 2019
1 parent 0ea5ccb commit 516365c57e9b047bb35384e7c163040375865f7d
Showing 2 changed files with 13 additions and 13 deletions.
@@ -34,9 +34,14 @@ public MicroprofileMetricsAdapter(final MetricRegistry registry) {

public Consumer<Definition> registrer() {
return def -> {
final Metadata metadata = new Metadata(def.getName(), def.getDisplayName(), def.getDescription(), GAUGE,
def.getUnit());
metadata.setReusable(true);
final Metadata metadata = Metadata.builder()
.withName(def.getName())
.withDisplayName(def.getDisplayName())
.withDescription(def.getDescription())
.withType(GAUGE)
.withUnit(def.getUnit())
.reusable(true)
.build();
try {
registry.register(metadata, (Gauge<Double>) () -> def.getEvaluator()
.getAsDouble());
@@ -76,9 +76,7 @@ private Object invoke(final InvocationContext context, final Executable executab
try {
return context.proceed();
} finally {
if (!counter.skipDecrement) {
counter.gauge.dec();
}
counter.gauge.dec();
}
}

@@ -106,25 +104,22 @@ private Meta find(final Executable executable) {
.map(org.eclipse.microprofile.metrics.annotation.ConcurrentGauge::name)
.orElse(""));

final ConcurrentGauge counter = ConcurrentGauge.class.cast(registry.getMetrics().get(
final ConcurrentGauge gauge = ConcurrentGauge.class.cast(registry.getMetrics().get(
new MetricID(name, concurrentGauge == null ? new Tag[0] : extension.createTags(concurrentGauge.tags()))));
if (counter == null) {
if (gauge == null) {
throw new IllegalStateException("No counter with name [" + name + "] found in registry [" + registry + "]");
}
meta = new Meta(counter, !ofNullable(concurrentGauge)
.orElseGet(() -> type.getAnnotation(org.eclipse.microprofile.metrics.annotation.ConcurrentGauge.class)).absolute());
meta = new Meta(gauge);
gauges.putIfAbsent(executable, meta);
}
return meta;
}

private static final class Meta {
private final ConcurrentGauge gauge;
private final boolean skipDecrement;

private Meta(final ConcurrentGauge gauge, final boolean skipDecrement) {
private Meta(final ConcurrentGauge gauge) {
this.gauge = gauge;
this.skipDecrement = skipDecrement;
}
}
}

0 comments on commit 516365c

Please sign in to comment.