-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Interface for HealthCheck Operations Providers #846
Comments
We use Java 8 and it would be nice if HealthCheck was a functional interface instead of an abstract class. That way we could use lambda functions to quickly create health checks without a lot of boiler plate for the inner class. The execute method in the class could move elsewhere probably. Unfortunately it is public and non-final, which suggest that somebody might be overriding this. Or if you want to keep the abstract class, it could be renamed to Another interface that would be nice is something similar to the public interface HealthCheckProvider {
HealthCheck healthCheck();
}
public class HealthCheckContextListener implements ApplicationListener<ContextRefreshedEvent> {
private static final Logger LOG = LoggerFactory.getLogger(HealthCheckContextListener.class);
private final HealthCheckRegistry healthCheckRegistry;
public HealthCheckContextListener(HealthCheckRegistry healthCheckRegistry) {
this.healthCheckRegistry = healthCheckRegistry;
}
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
// register health checks provided by other beans
Map<String, HealthCheckProvider> healthCheckProvidingBeans = event.getApplicationContext().getBeansOfType(HealthCheckProvider.class);
for(Entry<String, HealthCheckProvider> e: healthCheckProvidingBeans.entrySet()) {
LOG.info("health check " + e.getKey() + " " + e.getValue().getClass().getName());
HealthCheck check = e.getValue().healthCheck();
healthCheckRegistry.register(e.getKey(), check);
}
// register any health check beans registered directly
Map<String, HealthCheck> healthCheckBeans = event.getApplicationContext().getBeansOfType(HealthCheck.class);
for(Entry<String, HealthCheck> e: healthCheckBeans.entrySet()) {
LOG.info("health check " + e.getKey() + " " + e.getValue().getClass().getName());
HealthCheck check = e.getValue();
healthCheckRegistry.register(e.getKey(), check);
}
}
} |
This issue is stale because it has been open 180 days with no activity. Remove the "stale" label or comment or this will be closed in 14 days. |
It seems this was resolved by #1289 |
@jillesvangurp Thanks for finding the PR! 😄 |
We are using an OSGi environment and we have created a "wrapper" interface for HealthCheck objects, so that they can be exposed as OSGi services and picked up using the "whiteboard" pattern. It would be great if there were a native interface bundled with this library that folks could implement in order to provide health check results.
The text was updated successfully, but these errors were encountered: