-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
The documentation listed for disabling Spring Batch Metrics appears to be incomplete.
See https://docs.spring.io/spring-batch/reference/monitoring-and-metrics.html#disabling-metrics
From what I've found, the following does not disable all spring.batch metrics
Metrics.globalRegistry.config().meterFilter(MeterFilter.denyNameStartsWith("spring.batch"));
This appears to only disable metrics explicitly registered with Metrics.globalRegistry.
Other metrics are registered via an ObservationRegistry using Micrometer's Observation API and requires disabling via (in the case of spring boot) using properties such as:
management:
observations:
enable:
spring:
batch: false
If you want to disable all spring.batch metrics, you have to do both. The property configuration will disable the metrics associated with the ObservationRegistry and Metrics.globalRegistry.config().meterFilter(MeterFilter.denyNameStartsWith("spring.batch")); will deny properties registered to the global registry.
To reproduce:
Create a bean that executes
Metrics.globalRegistry.config().meterFilter(MeterFilter.denyNameStartsWith("spring.batch")); on construction
Run a job. Check the metric output (we use prometheus) and note that all metrics set via the observer api still exist.
Update the properties to set
management:
observations:
enable:
spring:
batch: false
Re-run job. Notice the metrics set via the observer api are no longer present.
If you remove the bean and no longer execute Metrics.globalRegistry.config().meterFilter(MeterFilter.denyNameStartsWith("spring.batch"));
but keep the properties set.
You will notice the metrics set via the observer api are still absent, but other spring batch metrics like (spring.batch.job.active and spring.batch.job.launch and a few others) continue to exist.