eclipse / microprofile-metrics

microprofile-metrics
Apache License 2.0
100 stars 66 forks source link

Provide a built-in MP Rest Client interface for consuming metrics data #490

Open andymc12 opened 4 years ago

andymc12 commented 4 years ago

Similar to Issue https://github.com/eclipse/microprofile-health/issues/216 in the health check spec, I think it would be nice to have a built-in MP Rest Client interface for consuming MP Metrics data. Perhaps this could exist in a separate "client" package and essentially extract the metrics data in JSON format and then provide a metrics class with the details.

For Metrics (as opposed to Health Check) this might be tricky as the data object that represent the metrics values are undefined - especially in the vendor category. I wrote a simple MP Rest Client interface for some automated testing here: StatsClient.java - this shows both how easy the client interface could look, but also how tricky the data object (in this case, I know exactly which stats I'm interested in, so I could use hard-coded JsonbProperty values to extract what I wanted - see Stats.java.

Still, even if the MP Rest Client interface only returned a map full of metrics, it would probably be useful for many users. Or perhaps the interface could be designed in such a way as to be very specific about what it is looking for - so that a user could request a specific stat like statsClient.getVendorStat("MyJAXRSApp.com.mypkg.MyResource.count");...

jmartisk commented 4 years ago

I like this, but I have to ask - What is the intended use case of this? I understand that with Health checks, one service could need to know the health of another service before establishing some business processing with it. But with Metrics, I think the main use case is being consumed by tools like Prometheus for data storage and visualisation. Is this to enable an easier way for building new monitoring libraries? In this case it should probably be a separate Maven artifact, so that we don't unnecessarily bloat traditional microservice deployments with stuff that they will probably not need.

Yea I think the main challenge here will be how to represent the resulting JSON object, because its structure is a bit unpredictable. But with some custom entity providers working with JSON-P it should be doable. These would probably be for the implementation to provide them.

andymc12 commented 4 years ago

Hi @jmartisk, yes, I think that building new monitoring and testing libraries is probably the most common use case. Maybe this is a better feature in something like the MicroProfile Extension? @phillip-kruger, wdyt?

jmartisk commented 4 years ago

I too think that MP Extensions could be a good place for this. AFAIK there are no Metrics things there yet, so we could start a new repository.. But I'm not completely sure about the status of the extensions ecosystem, whether it is still considered actively developed.

phillip-kruger commented 4 years ago

MP extensions is moving to SmallRye. SmallRye will become an implementation and many extensions. We are still busy migrating, only at config extensions at the moment. I would think @kenfinnigan might be able to help on if this is a possibility for SmallRye ?

kenfinnigan commented 4 years ago

It's something that could be interesting to add to SmallRye Metrics