[PROPOSAL] Introspect metrics annotations from an implemented interface

77 views
Skip to first unread message

Carlos Chacín

unread,
Oct 1, 2019, 1:41:50 PM10/1/19
to microp...@googlegroups.com

Hi everyone,

My name is Carlos Chacin and I started to use MicroProfile a few months ago. I’m doing some code generation based on OpenAPI Specs, which creates interfaces with all the JAX-RS annotations, so after implementing the interface we don’t have to add any JAX-RS annotations to the methods but only worry about the business logic and implementation details.

This works pretty well with JAX-RS, but I tried to do something similar with the MicroProfile Metrics without success and I wanted to discuss here with all of you about if makes sense that the same JAX-RS behavior should be applied to the metrics specification/implementation.

There is a GitHub issue with some details but I’m happy to provide an example project to reproduce the behavior if required: #451

Given the following interface:

    @Timed(name = "GET_pet/{petId}", absolute = true, unit = MetricUnits.NANOSECONDS, displayName = "getPetById", reusable = false, tags = {"action=PetApi.getPetById"}, description = "Find pet by ID")
    @GET
    @Path("pet/{petId}")
    @Produces({ "application/xml", "application/json" })
    CompletionStage<Response> getPetById(
        @BeanParam GetPetByIdParams params
    ) throws javax.ws.rs.WebApplicationException;

Given the following class implementing the above interface:

public class PetResource implements PetApi {

    @Override
    public CompletionStage<Response> getPetById(
        GetPetByIdParams params
    ) throws WebApplicationException {
        return CompletableFuture.supplyAsync(() -> Response.ok("[]").build());
    }
}

When the endpoint is executed

$ curl http://host:port/pet/1

Expected Behavior

Then Eclipse Microprofile implementation should generate the following metric

application_GET_pet/{petId}

Current Behavior

NOT METRIC GENERATED

Additional Info

beans.xml
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
       bean-discovery-mode="all">
</beans>
JAXRS Configuration
@ApplicationPath("/")
public class JAXRSConfiguration extends Application {
}
Environment
  • OpenJDK 11.0.4
  • OpenLiberty-MicroProfile3 19.0.0.9


--
Carlos Chacin
Senior SDE

Alasdair Nottingham

unread,
Oct 7, 2019, 11:31:19 AM10/7/19
to microp...@googlegroups.com
So you are essentially asking if the interface definition of the method could be checked in addition to the implementation definition of the method.

I’m wondering if that could be expensive at runtime, having to check all those interfaces via reflection. What if there was some kind of maven plugin that could copy the annotations from the interface to the implementation?

Alasdair

> On Oct 1, 2019, at 1:41 PM, Carlos Chacín <cch...@gmail.com> wrote:
>
> S behavior should be

Carlos Chacín

unread,
Oct 7, 2019, 8:28:59 PM10/7/19
to microp...@googlegroups.com
Thanks for reviewing this Alasdair,

On Mon, Oct 7, 2019 at 8:31 AM Alasdair Nottingham <alasdair....@gmail.com> wrote:
So you are essentially asking if the interface definition of the method could be checked in addition to the implementation definition of the method.

^^ Yes, alá JAX-RS, were the implementation scan the classes and interfaces boot-time and it performs validations as well.

I’m wondering if that could be expensive at runtime, having to check all those interfaces via reflection. What if there was some kind of maven plugin that could copy the annotations from the interface to the implementation?

Alasdair

> On Oct 1, 2019, at 1:41 PM, Carlos Chacín <cch...@gmail.com> wrote:
>
> S behavior should be

--
You received this message because you are subscribed to the Google Groups "Eclipse MicroProfile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to microprofile...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/microprofile/1F81141A-C830-4A84-9DD6-3C69D42E873D%40gmail.com.

Jean-Louis Monteiro

unread,
Oct 8, 2019, 7:26:52 AM10/8/19
to MicroProfile
I think it makes sense to support interfaces.

With all annotations, it becomes harder and harder to find the business code in the middle. Most people like Carlos tend to extract all this into an interface acting as a contract. It also makes it possible to create a client jar with model and interfaces and use it for the rest client for instance.

I don't think it would be much more expensive. Most specifications like openapi already does that. This is done at deploy time in a CDI Extension usually, and not at runtime.

Emily Jiang

unread,
Oct 8, 2019, 5:34:10 PM10/8/19
to Eclipse MicroProfile
Since the referenced annotations are inherited, the implementation classes should have the annotations. I think this kind of support might be achievable. Can you raise an issue on the Metrics spec so that further discussion can be done in more details to see whether the relevant specs can be enhanced to support this?

Emily

On Tuesday, October 8, 2019 at 12:26:52 PM UTC+1, Jean-Louis Monteiro wrote:
I think it makes sense to support interfaces.

With all annotations, it becomes harder and harder to find the business code in the middle. Most people like Carlos tend to extract all this into an interface acting as a contract. It also makes it possible to create a client jar with model and interfaces and use it for the rest client for instance.

I don't think it would be much more expensive. Most specifications like openapi already does that. This is done at deploy time in a CDI Extension usually, and not at runtime.

On Tue, Oct 8, 2019 at 2:28 AM Carlos Chacín <cch...@gmail.com> wrote:
Thanks for reviewing this Alasdair,

On Mon, Oct 7, 2019 at 8:31 AM Alasdair Nottingham <alasdair....@gmail.com> wrote:
So you are essentially asking if the interface definition of the method could be checked in addition to the implementation definition of the method.

^^ Yes, alá JAX-RS, were the implementation scan the classes and interfaces boot-time and it performs validations as well.

I’m wondering if that could be expensive at runtime, having to check all those interfaces via reflection. What if there was some kind of maven plugin that could copy the annotations from the interface to the implementation?

Alasdair

> On Oct 1, 2019, at 1:41 PM, Carlos Chacín <cch...@gmail.com> wrote:
>
> S behavior should be

--
You received this message because you are subscribed to the Google Groups "Eclipse MicroProfile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to microp...@googlegroups.com.


--
Carlos Chacin
Senior SDE

--
You received this message because you are subscribed to the Google Groups "Eclipse MicroProfile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to microp...@googlegroups.com.

Carlos Chacín

unread,
Oct 8, 2019, 8:02:49 PM10/8/19
to microp...@googlegroups.com
Thanks Jean-Louis and Emily for reviewing this, there is an issue already in the repo: https://github.com/eclipse/microprofile-metrics/issues/451

Carlos Chacin

Senior SDE

To unsubscribe from this group and stop receiving emails from it, send an email to microprofile...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/microprofile/6aed99eb-7cc5-47d8-9995-f1936312bfe5%40googlegroups.com.

Emily Jiang

unread,
Oct 11, 2019, 1:57:17 PM10/11/19
to Eclipse MicroProfile
Thank you Carlos for taking time to raise this issue! Let's continue the conversation on the issue!
Emily

Amelia Eiras

unread,
Dec 9, 2019, 4:25:05 PM12/9/19
to Eclipse MicroProfile

Hola #usualsuspects & MicroProfiler Carlos, 

Wondering if you have the bandwidth to attend the very last Community hangout tomorrow at 11am-12 PST? 
If yes:
  • zoom link
  • agenda minutes (for you to own in case you can attend) here 
Why I ask if you could introduce yourself and give us a tracing on what/why/how your MP proposal exists matters greatly, specially when coming from a DOER like you. 

If you are not able to attend, so be it. It is just bias me sending you via forum a pull. See it as such and feel no pressure. Thank YOU for caring enough to share, for pushing your time on the Project via twitter and for being wonderful welcoming you. We need for Carlos' attitude b/c it is MicroProfilers like you who make this ecosystem thrive and put CommunityFIRST. 
Reply all
Reply to author
Forward
0 new messages