I cannot reopen ticket https://github.com/spring-projects/spring-boot/issues/28188 "MeterFilter do not work for composite meter registres #28188" and not sure if my comment will be read, therefore I create this new ticket.

==== To give an example of what problems might bring - this specific behaviour of not applying the MeterFilters for the composite meter registry caused a memory leak for us.

I a nutshell this is what happened:

  • we were running an application that used only one meter registry (StatsdMeterRegistry).
  • we were not exposing http client metrics, i.e. management.metrics.enable.http.client.metrics = false
  • we added another meter registry to our application (PrometheusMeterRegistry)
  • the CompositeMeterRegistry (that was added because we now have more than one registry) accumulated a lot of http client meter instances, causing our application to run out of memory.

In our specific case a lot of http client metrics were created because of the specific way we use a URI builder to construct URIs for our WebClient. (See: this post https://rieckpil.de/expose-metrics-of-spring-webclient-using-spring-boot-actuator/ for more background on that.)

Even though this memory leak happened under very specific circumstances, I still believe that storing meters in memory is rather unexpected from a programmer perspective and certainly not ideal, especially because we are explicitly filtering these meters out. I can think of many more scenarios that might cause unexpected rises in memory usage or even memory leaks when only adding an extra meter registry to your application.

My advice is to reopen this issue and considering a way to ensure that these meters do not end up in memory.

Comment From: wilkinsona

Duplicates https://github.com/spring-projects/spring-boot/issues/28188#issuecomment-1023075705.