Search in sources :

Example 1 with HealthResponseProvider

use of io.dropwizard.health.response.HealthResponseProvider in project dropwizard by dropwizard.

the class DefaultHealthFactory method configure.

@Override
public void configure(final LifecycleEnvironment lifecycle, final ServletEnvironment servlets, final JerseyEnvironment jersey, final HealthEnvironment health, final ObjectMapper mapper, final String name) {
    if (!isEnabled()) {
        LOGGER.info("Health check configuration is disabled.");
        return;
    }
    final MetricRegistry metrics = lifecycle.getMetricRegistry();
    final HealthCheckRegistry envHealthChecks = health.healthChecks();
    final String fullName = DEFAULT_BASE_NAME + "-" + name;
    final List<HealthCheckConfiguration> healthCheckConfigs = getHealthCheckConfigurations();
    // setup schedules for configured health checks
    final ScheduledExecutorService scheduledHealthCheckExecutor = createScheduledExecutorForHealthChecks(healthCheckConfigs.size(), metrics, lifecycle, fullName);
    final HealthCheckScheduler scheduler = new HealthCheckScheduler(scheduledHealthCheckExecutor);
    // configure health manager to receive registered health state listeners from HealthEnvironment (via reference)
    final HealthCheckManager healthCheckManager = new HealthCheckManager(healthCheckConfigs, scheduler, metrics, shutdownWaitPeriod, initialOverallState, health.healthStateListeners());
    healthCheckManager.initializeAppHealth();
    // setup response provider and responder to respond to health check requests
    final HealthResponseProvider responseProvider = healthResponseProviderFactory.build(healthCheckManager, healthCheckManager, mapper);
    healthResponderFactory.configure(fullName, healthCheckUrlPaths, responseProvider, health, jersey, servlets, mapper);
    // register listener for HealthCheckRegistry and setup validator to ensure correct config
    envHealthChecks.addListener(healthCheckManager);
    lifecycle.manage(new HealthCheckConfigValidator(healthCheckConfigs, envHealthChecks));
    // register shutdown handler with Jetty
    final Duration shutdownDelay = getShutdownWaitPeriod();
    if (isDelayedShutdownHandlerEnabled() && shutdownDelay.toMilliseconds() > 0) {
        final DelayedShutdownHandler shutdownHandler = new DelayedShutdownHandler(healthCheckManager);
        shutdownHandler.register();
        LOGGER.debug("Set up delayed shutdown with delay: {}", shutdownDelay);
    }
    // Set the health state aggregator on the HealthEnvironment
    health.setHealthStateAggregator(healthCheckManager);
    LOGGER.debug("Configured ongoing health check monitoring for healthChecks: {}", getHealthChecks());
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InstrumentedScheduledExecutorService(com.codahale.metrics.InstrumentedScheduledExecutorService) HealthResponseProvider(io.dropwizard.health.response.HealthResponseProvider) MetricRegistry(com.codahale.metrics.MetricRegistry) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) Duration(io.dropwizard.util.Duration)

Aggregations

InstrumentedScheduledExecutorService (com.codahale.metrics.InstrumentedScheduledExecutorService)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)1 HealthResponseProvider (io.dropwizard.health.response.HealthResponseProvider)1 Duration (io.dropwizard.util.Duration)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1