Spring Boot Version: 3.5.6
Expected Behavior
Setting the management.metrics.web.client.max-uri-tags
property should prevent memory leaks. So should setting the management.metrics.enable.http.client.requests
property to false.
Actual Behavior
Neither property prevents a memory leak because under certain conditions, the AutoConfiguredCompositeMeterRegistry
will accumulate unbounded entries in its meterMap
because no MeterFilters
are being applied to it. This leads to the eventual exhaustion of heap memory and causes the application to crash.
Replication
- start the attached sample-project
- send a couple hundred requests to it via curl:
for i in {1..200}; do curl http://localhost:8080/test; done
- notice the log event in the console:
OnlyOnceLoggingDenyMeterFilter : Reached the maximum number of URI tags for 'http.client.requests'. Are you using 'uriVariables'?
- capture a heap dump via
/actuator/heapdump
- analyze the heap dump and see
- the number of elements in the
meterMap
for theAutoConfiguredCompositeMeterRegistry
grows and grows - the number of elements in the
meterMap
for thePrometheusMeterRegistry
is static (does not grow and grow)
- the number of elements in the
Conditions:
- more than one meter registry is configured
- the attached sample is using
micrometer-registry-prometheus
+micrometer-registry-jmx
but it could be any combination of two or more.
- the attached sample is using
- the application is generating unique metrics / tags
- for example: using a
RestClient
to call a URI without proper use of URI variables (that's the case in the provided sample)
- for example: using a
possible cause: 9f2141300035554aa078fcd4f6daea710ea96d13
See also: #38912 #39070