How to produce metrics of URI correctly in spring boot 2 + webflux - spring-boot

I have a problem using spring boot 2.0.3 + spring webflux (functional endpoints) + metrics. According to the official doc:
The generated metrics of uri should be the request’s URI template prior to variable substitution
Which means instead of /api/person/123, the generated metrics of URI should be something like /api/person/{id}. However, when I query those metrics on my spring boot app with this link http://localhost:8080/actuator/metrics/http.server.requests, I got these URIs:
/api/person/2
/api/person/33
/api/person/12
To reproduce this issue, I put a sample code here: https://gitlab.com/itsleon/demo
Can someone please shed some light on this issue? Thanks in advance!

There's an open issue for that in Spring Boot.
Currently, Spring WebFlux fn doesn't provide the information about the URI pattern that matched for the current request, so there's no way to achieve that currently.
Your assessment is correct, currently the full request URIs are collected.

Related

How to get spring boot cloud/actuator to support prometheus Exemplars?

The Exemplars support essentially adds the trace-id to metrics that are being scraped. I found a tutorial on how would it work with GoLang[1] but cannot figure out how to do this with spring boot libraries/functionalities. I know that Prometheus Java Client supports it as described at [2] but not sure how to get it to work with Springboot.
https://vbehar.medium.com/using-prometheus-exemplars-to-jump-from-metrics-to-traces-in-grafana-249e721d4192
https://github.com/prometheus/client_java/pull/615
Update: Exemplars are supported by Micrometer and Spring Cloud Sleuth.
I'm not 100% sure I get your question right: I'm assuming you are talking about the /actuator/prometheus endpoint.
The support for metrics in Spring is provided by Micrometer that also supports Prometheus and Spring Boot "just" sets up an actuator endpoint for it.
So the real question is: does Micrometer support exemplars? Right now it does not and we haven't had anyone asking for it so far (this issue is a little bit connected). So if you want this feature, please open an issue(Enhancement request) on GitHub.
Update: I opened an issue for this: https://github.com/micrometer-metrics/micrometer/issues/2672, please feel free to +1 or chime-in.
Adding exemplars support in Micrometer is not the end of the story, we need to add support for Spring Cloud Sleuth too and solve a few other potential issues.
Until this is implemented, I guess your best bet is using the prometheus client.

Spring boot metrics for rest api with PathVariables

In my spring boot project I would like to keep count of how many times the rest api endpoint responded with status 200. The spring boot actuator metrics endpoint came close to solving this issue for me out of the box.
However, the /metrics endpoint names provided the aggregate of responses by the endpoint method rather than each of the dynamic endpoints created through #PathVariable.
For example:
while I can get http://localhost:8084/myproject/actuator/metrics/http.server.requests?tag=status:200,uri:/api/users/{id}/books
I would like to do something like
http://localhost:8084/myproject/actuator/metrics/http.server.requests?tag=status:200,uri:/api/users/1/books
and
http://localhost:8084/myproject/actuator/metrics/http.server.requests?tag=status:200,uri:/api/users/2/books
and so on.
Is there an easy way to do this?
You can roll your own WebMvcTagsProvider. That's the place where you can hook into the tag generation. Have a look at DefaultWebMvcTagsProvider to get insight on how it is done for the default behaviour.
A note: The default tagging is done on purpose the way it is to hinder metrics explosion, because every metric name + tag combination is a new metric. So be aware of that.

How does the Spring Boot Actuator work together with the Netflix Servo?

There are Spring Boot project that uses a Netflix Servo to collect metrics and send to Graphite.
I want to send metrics with the Spring Boot Actuator on Graphite, such as number request per every endpoint and time of response for every request, instead of creating custom metric.
But I ran into the problem. When I use the library only spring-boot-starter-actuator, then the desired parameters displays:
but when I apply library spring-cloud-starter-eureka, displayed only time of response from servo:
If someone faced with this problem, can you explain why it happens and how to solve it?
I use such version Spring Boot - 1.5.9.RELEASE and Spring Cloud - Edgware.SR1.
I will be glad to any response)
Link to test project: https://github.com/rmartseniuk/spring-metric

Accessing localhost:8080/actuator endpoint (with spring boot actuator)

In spring docs I have read about endpoint named "actuator" which is provided by actuator dependency, but I haven't managed to access it on my local testing app.
Question: Does someone know how to access that endpoint? of coarse if it is possible :)
Sub-question 1: If this endpoint exists, then why it is hidden?
Sub-question 2: If this endpoint doesn't exist, how can we notify spring.io to correct documentation page (open some kind of ticket) ?
Details:
I want to access exactly "actuator" endpoint, not other endpoints provided by spring boot actuator (localhost:8080/actuator)
Yes, I have tried to enable that endpoint manually in properties file (endpoints.enabled=true OR endpoints.actuator.enabled=true)
Yes, I have tried to enable/disable endpoints.sencitive property
Yes, other endpoints of actuator work just fine
No special reason why I need that, just want to try it out (just learning new stuff :) )
Please don't just answer "there is no such endpoint dude!", there should be some kind of reason why it is written in the docs
Please use spring boot version which I am using now before answering "it is working for me with these configs" (spring boot version: 1.5.4.RELEASE)
Thank you in advance :)
You must include the Spring Hateoas dependency in order for the /actuator endpoint to become available:
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
Per the docs:
Provides a hypermedia-based “discovery page” for the other endpoints.
Requires Spring HATEOAS to be on the classpath.

How to remove default Metrics data provided by Spring Actuator

I am trying to get Production metrics for my application. I am using Actuator on top of Spring Boot. Actuator exposes an endpoint for that "/metrics". I have Autowired CounterService class to get my own metrics data. I will be displaying the metrics data in one of our Application Management UI. The problem here is that I don't want all the default metrics data, as the Response JSON given back by the /metrics endpoint is kind off heavy for me to parse and most of the default metrics data are useless for me and give it to the UI. I have gone through the Spring Docs, I didn't get any help.
Appreciate your help on this!
Oh So I found a way to deal with the scenario. Actually Spring This GitHub Link pretty much solves my problem. Actuator Supports Reqex support to query for the data you need. So my url looks like this now : http://{{hostname}}/metrics/counter.*.count instead of this http://{{hostname}}/metrics/. Hope this helps.
Have you tried wrapping the response class from metrics, with a Custom class?

Resources