When trying to export the Spring Boot health indicators as metrics with Micrometer. I followed the Mapping Health Indicators to Micrometer Metrics to implement the same. The implementation is as follows
public class HealthApiToMetricsConvertor {
@Bean
public MeterRegistryCustomizer<MeterRegistry> healthRegistryCustomizer(HealthContributorRegistry healthRegistry,
HealthEndpoint healthEndpoint) {
return registry -> {
registry.gauge("health", Tags.of("name", "root"), healthEndpoint, it -> healthToCode(it.health().getStatus()));
healthRegistry
.stream()
.forEach(
namedContributor -> registry.gauge(
"health",
Tags.of("name", namedContributor.getName()),
healthRegistry,
health -> {
var status = ((HealthIndicator) health.getContributor(namedContributor.getName()))
.getHealth(false).getStatus();
return healthToCode(status);
}
)
);
};
}
private int healthToCode(Status status) {
return status.equals(Status.UP) ? 1 : 0;
}
}
While building and running the test (using the test-container)I am facing an OutOfMemory error.
Following are the memory metrics.
When the following class is commented out there is no memory leak.
Could someone please tell me the possible cause and solution? If I’ve missed anything, or over- or under-emphasized a specific point, please let me know in the comments. Thank you so much in advance for your time.