I would like the ability to assign a CompositeHealthContributor
to a Health Group via configuration.
Currently, the management.endpoint.health.group.<groupId>.include
/exclude
properties only accept health indicator ids. They do not accept the id of a CompositeHealthContributor
.
Concrete use case: In my application, I have exposed a CompositeHealthContributor
bean, composed of dynamically created HealthIndicators, with dynamically created indicator ids. Spring boot autoconfiguration will automatically discover the CompositeHealthContributor
and add it to the system health checks. This is great. However, I want to be able to add this contributor to a health group by the composite contributor id. I cannot configure the health group to include the health indicator ids, since the health indicator ids are dynamically created.
I have attached an example application that has a failing unit test that demonstrates the problem.
The example application has the following property configuration:
management.endpoint.health.show-details=always
management.endpoint.health.group.foo.include=foo
With the following bean configuration:
/*
* An example health contributor named "foo".
* (note the HealthContributorNameFactory will strip the HealthContributor bean name suffix)
*/
@Bean
public CompositeHealthContributor fooHealthContributor() {
return CompositeHealthContributor.fromMap(Map.<String, HealthIndicator>of(
// Pretend this is dynamically created
"foo-A", () -> Health.up().build(),
"foo-B", () -> Health.up().build()));
}
The /actuator/heath
endpoint returns the following (as expected):
{
"status": "UP",
"components": {
"diskSpace": {
"status": "UP",
"details": {
"total": 791643418624,
"free": 399057661952,
"threshold": 10485760
}
},
"foo": {
"status": "UP",
"components": {
"foo-A": {
"status": "UP"
},
"foo-B": {
"status": "UP"
}
}
},
"ping": {
"status": "UP"
}
},
"groups": [
"foo"
]
}
However, the /actuator/health/foo
endpoint returns a 404, because the "foo" CompositeHealthContributor
id is not included in the foo
health group.
If I change management.endpoint.health.group.foo.include
to foo,foo-A,foo-B
, the foo
group will work. However, I cannot statically configure the individual indicator ids, since they will be dynamically created.
As an alternative, if the include/exclude properties accepted a regex (rather than only *
or an exact match) , I could finagle the dynamic ids to always be able to be matched by a regex.
Comment From: snicoll
@philsttr thanks for the sample and the report. Ignoring the fact that the group has the same name as your composite (and therefore one attempts to shadow the other), there is something really odd going on once I rename the group to something else.