/** * Registers an application {@link HealthCheck} with a given name. * * @param healthCheck the {@link HealthCheck} instance */ public static void register(HealthCheck healthCheck) { DEFAULT_REGISTRY.register(healthCheck); }
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof HealthCheck) { healthChecks.register((HealthCheck) bean); if (log.isDebugEnabled()) { log.debug("Registering HealthCheck bean " + beanName); } } return bean; }
/** * This method is adapted from ServerFactory.buildServer. * * @param env the {@link ExtendedEnvironment} to get {@link HealthCheck}s from. */ private void addHealthChecks(ExtendedEnvironment env) { HealthChecks.defaultRegistry().register(new DeadlockHealthCheck()); for (HealthCheck healthCheck : env.getHealthChecks()) { HealthChecks.defaultRegistry().register(healthCheck); } if (env.getHealthChecks().isEmpty()) { logger.warn('\n' + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + "! THIS SERVICE HAS NO HEALTHCHECKS. THIS MEANS YOU WILL NEVER KNOW IF IT !\n" + "! DIES IN PRODUCTION, WHICH MEANS YOU WILL NEVER KNOW IF YOU'RE LETTING !\n" + "! YOUR USERS DOWN. YOU SHOULD ADD A HEALTHCHECK FOR EACH DEPENDENCY OF !\n" + "! YOUR SERVICE WHICH FULLY (BUT LIGHTLY) TESTS YOUR SERVICE'S ABILITY TO !\n" + "! USE THAT SERVICE. THINK OF IT AS A CONTINUOUS INTEGRATION TEST. !\n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ); } }
@Override public AdminServlet get() { for (HealthCheck healthCheck : healthChecks) { healthCheckRegistry.register(healthCheck); } final JsonFactory factory = jsonFactory == null ? new JsonFactory(new ObjectMapper()) : jsonFactory; return new AdminServlet(new HealthCheckServlet(healthCheckRegistry), new MetricsServlet(Clock.defaultClock(), VirtualMachineMetrics.getInstance(), metricsRegistry, factory, true), new PingServlet(), new ThreadDumpServlet(VirtualMachineMetrics.getInstance()), healthcheckUri, metricsUri, pingUri, threadsUri); } }
@Override protected void configureServlets() { bind(GuiceContainer.class).to(DropwizardGuiceContainer.class); // Bind Jersey @Provider classes bindCatchallExceptionMapper(binder()); bind(InvalidEntityExceptionMapper.class); bind(JsonProcessingExceptionMapper.class); bind(InstrumentedResourceMethodDispatchAdapter.class).toInstance(new InstrumentedResourceMethodDispatchAdapter()); bind(CacheControlledResourceMethodDispatchAdapter.class); bind(OptionalQueryParamInjectableProvider.class); bind(Lifecycle.class).toInstance(lifecycle); bind(getConfigurationClass()).toInstance(conf); if (conf.getAdminConfiguration().isPresent()) { AdminConfiguration adminConf = conf.getAdminConfiguration().get(); filter("/admin/*").through(new BasicAuthFilter(adminConf.getUsername(), adminConf.getPassword())); serve("/admin/*").with(new AdminServlet()); } bind(HealthCheckRegistry.class).toInstance(HealthChecks.defaultRegistry()); HealthChecks.defaultRegistry().register(new DeadlockHealthCheck()); serve("/*").with(GuiceContainer.class); } }), createModules(conf)));