/** * Create a {@link CompositeHealthIndicator} based on the specified health indicators. * @param healthAggregator the {@link HealthAggregator} * @param healthIndicators the {@link HealthIndicator} instances mapped by name * @return a {@link HealthIndicator} that delegates to the specified * {@code healthIndicators}. */ public CompositeHealthIndicator createHealthIndicator( HealthAggregator healthAggregator, Map<String, HealthIndicator> healthIndicators) { Assert.notNull(healthAggregator, "HealthAggregator must not be null"); Assert.notNull(healthIndicators, "HealthIndicators must not be null"); HealthIndicatorRegistryFactory factory = new HealthIndicatorRegistryFactory( this.healthIndicatorNameFactory); return new CompositeHealthIndicator(healthAggregator, factory.createHealthIndicatorRegistry(healthIndicators)); }
private HealthIndicator getNestedHealthIndicator(HealthIndicator healthIndicator, String name) { if (healthIndicator instanceof CompositeHealthIndicator) { return ((CompositeHealthIndicator) healthIndicator).getRegistry().get(name); } return null; }
@Override public void afterBinderContextInitialized(String binderConfigurationName, ConfigurableApplicationContext binderContext) { if (this.bindersHealthIndicator != null) { OrderedHealthAggregator healthAggregator = new OrderedHealthAggregator(); Map<String, HealthIndicator> indicators = binderContext.getBeansOfType(HealthIndicator.class); // if there are no health indicators in the child context, we just mark // the binder's health as unknown // this can happen due to the fact that configuration is inherited HealthIndicator binderHealthIndicator = indicators.isEmpty() ? new DefaultHealthIndicator() : new CompositeHealthIndicator(healthAggregator, indicators); bindersHealthIndicator.getRegistry().register(binderConfigurationName, binderHealthIndicator); } }
@Override public void afterPropertiesSet() throws Exception { final Map<String, HealthIndicator> healthIndicators = applicationContext.getBeansOfType(HealthIndicator.class); for (Map.Entry<String, HealthIndicator> entry : healthIndicators.entrySet()) { //ignore EurekaHealthIndicator and flatten the rest of the composite //otherwise there is a never ending cycle of down. See gh-643 if (entry.getValue() instanceof DiscoveryCompositeHealthIndicator) { DiscoveryCompositeHealthIndicator indicator = (DiscoveryCompositeHealthIndicator) entry.getValue(); for (DiscoveryCompositeHealthIndicator.Holder holder : indicator.getHealthIndicators()) { if (!(holder.getDelegate() instanceof EurekaHealthIndicator)) { healthIndicator.addHealthIndicator(holder.getDelegate().getName(), holder); } } } else { healthIndicator.addHealthIndicator(entry.getKey(), entry.getValue()); } } }
protected InstanceStatus getHealthStatus() { final Status status = getHealthIndicator().health().getStatus(); return mapToInstanceStatus(status); }
public BootHealthCheckHandler(ApplicationInfoManager applicationInfoManager, HealthAggregator aggregator, Map<String, HealthIndicator> healthIndicators) { this.applicationInfoManager = Objects.requireNonNull(applicationInfoManager, "applicationInfoManager"); this.aggregateHealth = new CompositeHealthIndicator(aggregator, healthIndicators); }
public EurekaHealthCheckHandler(HealthAggregator healthAggregator) { Assert.notNull(healthAggregator, "HealthAggregator must not be null"); this.healthIndicator = new CompositeHealthIndicator(healthAggregator); }
@Bean @ConditionalOnMissingBean public HealthEndpoint healthEndpoint(HealthAggregator healthAggregator, HealthIndicatorRegistry registry) { return new HealthEndpoint( new CompositeHealthIndicator(healthAggregator, registry)); }
protected HealthIndicator createHealthIndicator(Map<String, S> beans) { if (beans.size() == 1) { return createHealthIndicator(beans.values().iterator().next()); } HealthIndicatorRegistry registry = new DefaultHealthIndicatorRegistry(); beans.forEach( (name, source) -> registry.register(name, createHealthIndicator(source))); return new CompositeHealthIndicator(this.healthAggregator, registry); }
@Bean @ConditionalOnMissingBean(name = "bindersHealthIndicator") public CompositeHealthIndicator bindersHealthIndicator() { return new CompositeHealthIndicator(new OrderedHealthAggregator(), new DefaultHealthIndicatorRegistry()); }