quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.42k stars 2.58k forks source link

Micrometer-Microprofile adapter checks annotations in abstract classes #40752

Open sithmein opened 2 months ago

sithmein commented 2 months ago

Describe the bug

Consider the following abstract class:

public abstract class C {
  @Gauge(name = "foo", unit = MetricUnits.NONE)
  long metric () { return 0; }
}

When the Quarkus application starts, the GaugeAnnotationHandler complains about C uses a @Gauge annotation, but is not @ApplicationScoped, a @Singleton, or a REST endpoint. This doesn't make sense because abstract class can never be instantiated and therefore never report any metrics. Only concrete subclasses can and there the check make sense.

Expected behavior

Abstract classes are not checked by the annotation handlers.

Actual behavior

Abstract classes are checked for annotations when it doesn't make sense.

How to Reproduce?

See description.

Output of uname -a or ver

-

Output of java -version

17.0.11

Quarkus version or git rev

Tested with 3.2.12.Final but the code hasn't change since then

Build tool (ie. output of mvnw --version or gradlew --version)

Maven 3.9.2

Additional information

No response

quarkus-bot[bot] commented 2 months ago

/cc @brunobat (micrometer), @ebullient (micrometer)

geoand commented 1 month ago

Does the @Gauge nevertheless work as expected? Forget about that I see it throws an exception.

geoand commented 1 month ago

This check is rather sketchy... Is it really needed @brunobat, @ebullient?

ebullient commented 1 month ago

Just a bug. I was trying to be clear about limitations using the MP Metrics Gauge annotation as it does not work the same in the Micrometer extension as it did with SmallRye Metrics.