Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and Misc changes to Micrometer branch #505

Merged
merged 8 commits into from
Jun 28, 2022
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>smallrye-metrics-parent</artifactId>
<groupId>io.smallrye</groupId>
<version>5.0.1-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-metrics-parent</artifactId>
<version>5.0.1-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
</parent>

<artifactId>smallrye-metrics-coverage</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion implementation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-metrics-parent</artifactId>
<version>5.0.1-SNAPSHOT</version>
<version>5.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import java.lang.annotation.Annotation;

import org.eclipse.microprofile.metrics.annotation.ConcurrentGauge;
import org.eclipse.microprofile.metrics.annotation.Counted;
import org.eclipse.microprofile.metrics.annotation.Gauge;
import org.eclipse.microprofile.metrics.annotation.Metered;
import org.eclipse.microprofile.metrics.annotation.SimplyTimed;
import org.eclipse.microprofile.metrics.annotation.Timed;

import io.smallrye.metrics.SmallRyeMetricsMessages;
Expand All @@ -24,16 +21,10 @@ public class CDIAnnotationInfo implements AnnotationInfo {
public String name() {
if (annotation instanceof Counted) {
return ((Counted) annotation).name();
} else if (annotation instanceof ConcurrentGauge) {
return ((ConcurrentGauge) annotation).name();
} else if (annotation instanceof Gauge) {
return ((Gauge) annotation).name();
} else if (annotation instanceof Metered) {
return ((Metered) annotation).name();
} else if (annotation instanceof Timed) {
return ((Timed) annotation).name();
} else if (annotation instanceof SimplyTimed) {
return ((SimplyTimed) annotation).name();
} else {
throw new IllegalArgumentException("Unknown metric annotation type " + annotation.annotationType());
}
Expand All @@ -43,16 +34,10 @@ public String name() {
public boolean absolute() {
if (annotation instanceof Counted) {
return ((Counted) annotation).absolute();
} else if (annotation instanceof ConcurrentGauge) {
return ((ConcurrentGauge) annotation).absolute();
} else if (annotation instanceof Gauge) {
return ((Gauge) annotation).absolute();
} else if (annotation instanceof Metered) {
return ((Metered) annotation).absolute();
} else if (annotation instanceof Timed) {
return ((Timed) annotation).absolute();
} else if (annotation instanceof SimplyTimed) {
return ((SimplyTimed) annotation).absolute();
} else {
throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
}
Expand All @@ -62,16 +47,10 @@ public boolean absolute() {
public String[] tags() {
if (annotation instanceof Counted) {
return ((Counted) annotation).tags();
} else if (annotation instanceof ConcurrentGauge) {
return ((ConcurrentGauge) annotation).tags();
} else if (annotation instanceof Gauge) {
return ((Gauge) annotation).tags();
} else if (annotation instanceof Metered) {
return ((Metered) annotation).tags();
} else if (annotation instanceof Timed) {
return ((Timed) annotation).tags();
} else if (annotation instanceof SimplyTimed) {
return ((SimplyTimed) annotation).tags();
} else {
throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
}
Expand All @@ -81,16 +60,10 @@ public String[] tags() {
public String unit() {
if (annotation instanceof Counted) {
return ((Counted) annotation).unit();
} else if (annotation instanceof ConcurrentGauge) {
return ((ConcurrentGauge) annotation).unit();
} else if (annotation instanceof Gauge) {
return ((Gauge) annotation).unit();
} else if (annotation instanceof Metered) {
return ((Metered) annotation).unit();
} else if (annotation instanceof Timed) {
return ((Timed) annotation).unit();
} else if (annotation instanceof SimplyTimed) {
return ((SimplyTimed) annotation).unit();
} else {
throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
}
Expand All @@ -100,16 +73,10 @@ public String unit() {
public String description() {
if (annotation instanceof Counted) {
return ((Counted) annotation).description();
} else if (annotation instanceof ConcurrentGauge) {
return ((ConcurrentGauge) annotation).description();
} else if (annotation instanceof Gauge) {
return ((Gauge) annotation).description();
} else if (annotation instanceof Metered) {
return ((Metered) annotation).description();
} else if (annotation instanceof Timed) {
return ((Timed) annotation).description();
} else if (annotation instanceof SimplyTimed) {
return ((SimplyTimed) annotation).description();
} else {
throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
}
Expand All @@ -119,16 +86,10 @@ public String description() {
public String displayName() {
if (annotation instanceof Counted) {
return ((Counted) annotation).displayName();
} else if (annotation instanceof ConcurrentGauge) {
return ((ConcurrentGauge) annotation).displayName();
} else if (annotation instanceof Gauge) {
return ((Gauge) annotation).displayName();
} else if (annotation instanceof Metered) {
return ((Metered) annotation).displayName();
} else if (annotation instanceof Timed) {
return ((Timed) annotation).displayName();
} else if (annotation instanceof SimplyTimed) {
return ((SimplyTimed) annotation).displayName();
} else {
throw SmallRyeMetricsMessages.msg.unknownMetricAnnotationType(annotation.annotationType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ private void update(boolean success, long startTimestamp, MetricID metricID) {
}
}

//TODO: Verify it works properly.
private void updateAfterSuccess(long startTimestamp, MetricID metricID) {
long duration = System.nanoTime() - startTimestamp;
MetricRegistry registry = MetricRegistries.getOrCreate(MetricRegistry.Type.BASE);
registry.getSimpleTimer(metricID).update(Duration.ofNanos(duration));
registry.getTimer(metricID).update(Duration.ofNanos(duration));
}

private void updateAfterFailure(MetricID metricID) {
Expand All @@ -94,17 +95,18 @@ private MetricID transformToMetricIDForFailedRequest(MetricID metricID) {
return new MetricID("REST.request.unmappedException.total", metricID.getTagsAsArray());
}

//TODO: Verify it works properly.
private void createMetrics(MetricID metricID) {
MetricRegistry registry = MetricRegistries.getOrCreate(MetricRegistry.Type.BASE);
if (registry.getSimpleTimer(metricID) == null) {
if (registry.getTimer(metricID) == null) {
Metadata successMetadata = Metadata.builder()
.withName(metricID.getName())
.withDescription(
"The number of invocations and total response time of this RESTful " +
"resource method since the start of the server.")
.withUnit(MetricUnits.NANOSECONDS)
.build();
registry.simpleTimer(successMetadata, metricID.getTagsAsArray());
registry.timer(successMetadata, metricID.getTagsAsArray());
}
MetricID metricIDForFailure = transformToMetricIDForFailedRequest(metricID);
if (registry.getCounter(metricIDForFailure) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
import io.smallrye.metrics.MetricRegistries;

interface GaugeAdapter<T> extends Gauge<T>, MeterHolder {

Expand All @@ -26,12 +27,14 @@ static class DoubleFunctionGauge<S> implements GaugeAdapter<Double> {
}

public GaugeAdapter<Double> register(MpMetadata metadata, MetricDescriptor metricInfo, MeterRegistry registry) {
MetricRegistries.MP_APP_METER_REG_ACCESS.set(true);
gauge = io.micrometer.core.instrument.Gauge.builder(metricInfo.name(), obj, f)
.description(metadata.getDescription())
.tags(metricInfo.tags())
.baseUnit(metadata.getUnit())
.strongReference(true)
.register(registry);
MetricRegistries.MP_APP_METER_REG_ACCESS.set(false);
return this;
}

Expand Down Expand Up @@ -63,12 +66,14 @@ static class FunctionGauge<S, R extends Number> implements GaugeAdapter<R> {
}

public GaugeAdapter<R> register(MpMetadata metadata, MetricDescriptor metricInfo, MeterRegistry registry) {
MetricRegistries.MP_APP_METER_REG_ACCESS.set(true);
gauge = io.micrometer.core.instrument.Gauge.builder(metricInfo.name(), obj, obj -> f.apply(obj).doubleValue())
.description(metadata.getDescription())
.tags(metricInfo.tags())
.baseUnit(metadata.getUnit())
.strongReference(true)
.register(registry);
MetricRegistries.MP_APP_METER_REG_ACCESS.set(false);
return this;
}

Expand Down Expand Up @@ -99,11 +104,13 @@ static class NumberSupplierGauge<T extends Number> implements GaugeAdapter<T> {
@Override
public GaugeAdapter<T> register(MpMetadata metadata, MetricDescriptor metricInfo, MeterRegistry registry) {
if (gauge == null || metadata.cleanDirtyMetadata()) {
MetricRegistries.MP_APP_METER_REG_ACCESS.set(true);
gauge = io.micrometer.core.instrument.Gauge.builder(metricInfo.name(), (Supplier<Number>) supplier)
.description(metadata.getDescription())
.tags(metricInfo.tags())
.baseUnit(metadata.getUnit())
.strongReference(true).register(registry);
MetricRegistries.MP_APP_METER_REG_ACCESS.set(false);
}

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ class HistogramAdapter implements Histogram, MeterHolder {
HistogramAdapter register(MpMetadata metadata, MetricDescriptor metricInfo, MeterRegistry registry) {
MetricRegistries.MP_APP_METER_REG_ACCESS.set(true);
if (summary == null || metadata.cleanDirtyMetadata()) {
summary = DistributionSummary.builder(metricInfo.name()).description(metadata.getDescription())
.baseUnit(metadata.getUnit()).tags(metricInfo.tags()).register(registry);
summary = DistributionSummary.builder(metricInfo.name())
.description(metadata.getDescription())
.baseUnit(metadata.getUnit())
.tags(metricInfo.tags())
.publishPercentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999)
.percentilePrecision(5) //from 0 - 5 , more precision == more memory usage
.register(registry);
}
MetricRegistries.MP_APP_METER_REG_ACCESS.set(false);
return this;
Expand Down
Loading