Skip to content

Conversation

@dennisvang
Copy link
Contributor

@dennisvang dennisvang commented Jan 27, 2026

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

path = {"", "{oUrlPrefix:[^.]+}/{oRecordId:[^.]+}"},

To count requests to individual resource URIs, I added a custom micrometer ObservationFilter implementation that replaces the default uri path 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

  • Exclude default metrics, only expose the custom one.
    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 develop branch...
    metrics:
    enable:
    all: false
    http:
    server: true

usage example

curl http://localhost:8080/actuator/metrics/http.server.requests?tag=uri:/distribution/distribution-1 | jq
{
  "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"
      ]
    }
  ]
}

@dennisvang
Copy link
Contributor Author

dennisvang commented Jan 28, 2026

Initially I implemented this by extending OncePerRequestFilter and creating a custom metric.

However, a micrometer dev suggested another approach in this comment from 2018.
Do note that the classes mentioned in that comment have been deprecated in favor of the micrometer observation APIs, as mentioned in spring boot 3 release notes.

The latest and greatest approach is probably to override either DefaultServerRequestObservationConvention, or micrometer ObservationFilter, as mentioned in the observability docs.

@dennisvang dennisvang force-pushed the feature/661-metrics branch 2 times, most recently from eca3a0e to 401221b Compare January 28, 2026 19:25
@dennisvang
Copy link
Contributor Author

dennisvang commented Jan 29, 2026

ran into #839

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants