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

  1. start the attached sample-project
  2. send a couple hundred requests to it via curl: for i in {1..200}; do curl http://localhost:8080/test; done
  3. notice the log event in the console: OnlyOnceLoggingDenyMeterFilter : Reached the maximum number of URI tags for 'http.client.requests'. Are you using 'uriVariables'?
  4. capture a heap dump via /actuator/heapdump
  5. analyze the heap dump and see
    • the number of elements in the meterMap for the AutoConfiguredCompositeMeterRegistry grows and grows
    • the number of elements in the meterMap for the PrometheusMeterRegistry is static (does not grow and grow)

Image

Conditions:

  1. 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.
  2. the application is generating unique metrics / tags

possible cause: 9f2141300035554aa078fcd4f6daea710ea96d13

See also: #38912 #39070