Custom actuator metric with request counter#836
Draft
dennisvang wants to merge 15 commits intosupport/1.18.xfrom
Draft
Custom actuator metric with request counter#836dennisvang wants to merge 15 commits intosupport/1.18.xfrom
dennisvang wants to merge 15 commits intosupport/1.18.xfrom
Conversation
b1a58f1 to
e957051
Compare
Contributor
Author
|
Initially I implemented this by extending However, a micrometer dev suggested another approach in this comment from 2018. The latest and greatest approach is probably to override either DefaultServerRequestObservationConvention, or micrometer ObservationFilter, as mentioned in the observability docs. |
eca3a0e to
401221b
Compare
Contributor
Author
|
ran into #839 |
Creates a custom actuator metric that counts requests to custom endpoints
and use Optional to handle nullable query string
conforming to the existing http.server.requests metric name
…ionFilter implementation following the examples from the spring-boot docs https://docs.spring.io/spring-framework/reference/integration/observability.html#observability.config.conventions
401221b to
4c69720
Compare
Here we override the DefaultServerRequestObservationConvention instead of subclassing the ObservationFilter Based on advise by micrometer devs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For #661 we are interested in counting the requests to individual resources.
However, the default Spring MVC actuator metric http.server.requests does not count requests for individual resources. Instead, it only shows counts for the path patterns defined for the controllers, such as
FAIRDataPoint/src/main/java/org/fairdatapoint/api/controller/metadata/GenericController.java
Line 150 in f65cd35
To count requests to individual resource URIs, I added a custom micrometer
ObservationFilterimplementation that replaces the defaulturipath pattern by the full path. Also see spring observability docs.Note
Although it is relatively quick and easy to use Spring actuator metrics for this, I'm not convinced this is the best approach. I think it would make more sense to do this at the deployment level, e.g. based on proxy logs, instead of the app level.
fixes #661
todo
So, figure out why the following lines are ignored by the fdp, whereas they do work in a fresh spring project, and they also work without issue if we apply them to the
developbranch...FAIRDataPoint/src/main/resources/application.yml
Lines 35 to 39 in 4c69720
usage example
{ "name": "http.server.requests", "baseUnit": "seconds", "measurements": [ { "statistic": "COUNT", "value": 3.0 }, { "statistic": "TOTAL_TIME", "value": 0.042224172 }, { "statistic": "MAX", "value": 0.02092224 } ], "availableTags": [ { "tag": "exception", "values": [ "none" ] }, { "tag": "method", "values": [ "GET" ] }, { "tag": "error", "values": [ "none" ] }, { "tag": "outcome", "values": [ "SUCCESS" ] }, { "tag": "status", "values": [ "200" ] } ] }