Skip to content

http.server.requests metric does not record HTTP 401 & 403 #970

@frank-mueller-at-kiwigrid-com

Description

Expected Behavior

http.server.requests metric records HTTP 401 & 403

Actual Behaviour

Micronaut: 4.7.14
Micrometer: 1.13.6
Micronaut Micrometer: 5.10.1

also reproducible with

Micronaut Platform: 4.8.2
Micronaut Core: 4.8.11
Micrometer: 1.13.6
Micronaut Micrometer: 5.10.1

After migrating from 4.6.3 to 4.7.1 we noticed, that "http.server.requests" did not record HTTP 401 & 403 anymore.
But we were sure that our service returned such status.

I was aware of this major refactoring of Server Metrics implementation, that came in with version 4.7.0
https://github.com/micronaut-projects/micronaut-micrometer/commit/8490cc81232feb311b39965e874aab790b31a5a0#diff-2fa72ab761f85c602cf4433f12a2b2ee73f7b406b0ffb6edc0cbf149de0647fd)

I made myself a copy of the old implementation https://github.com/micronaut-projects/micronaut-micrometer/blob/5.10.x/micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/web/ServerRequestMeterRegistryFilter.java
and added all annotations that it had before and changed the name of the metric.

E voila, I see "http.server.requests" metric properly recording HTTP 401 & 403

I went on and made myself a copy of the new implementation https://github.com/micronaut-projects/micronaut-micrometer/blob/5.10.x/micrometer-core/src/main/java/io/micronaut/configuration/metrics/binder/web/ServerMetricsFilter.java

but let the copy implement interface https://docs.micronaut.io/4.1.5/api/io/micronaut/core/order/Ordered.html
with

        @Override
	public int getOrder() {
		return Integer.MAX_VALUE;//metrics NOT recorded
		//return ServerFilterPhase.SECURITY.before(); //metrics recorded
		//return ServerFilterPhase.SECURITY.order(); //metrics recorded
		//return ServerFilterPhase.SECURITY.after(); //metrics NOT recorded
		//return ServerFilterPhase.TRACING.order(); //metrics recorded
	}

What might be the root cause:

  • "ServerRequestMeterRegistryFilter" works because it derives the getOrder() from https://docs.micronaut.io/4.1.5/api/io/micronaut/core/order/Ordered.html
    The implementation of https://docs.micronaut.io/latest/api/io/micronaut/core/order/Ordered.html#getOrder() returns 0 as default.
    The order number of 0 puts "ServerRequestMeterRegistryFilter" at the beginning of the filter chain and allows it to get notified
  • "ServerMetricsFilter" without implementing the "Ordered" interface gets a default order of MAX_INT (2147483647).
    The order number of MAX_INT puts the filter at the end of the filter chain where it never get notified, because other filter with a lower order number (probably security filters) already finished the request.
  • "ServerMetricsFilter" with implementing the "Ordered" interface and order >= ServerFilterPhase.SECURITY.after (39250)
    behave the same as if not implementing the "Ordered" interface.
    Probably because of the same reason: other filters just finished the request before

Steps To Reproduce

No response

Environment Information

No response

Example Application

No response

Version

4.7.14

also with

Micronaut Platform: 4.8.2
Micronaut Core: 4.8.11
Micrometer: 1.13.6
Micronaut Micrometer: 5.10.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions