@Bean @ConditionalOnProperty(value = "spring.cloud.discovery.client.composite-indicator.enabled", matchIfMissing = true) @ConditionalOnBean({ DiscoveryHealthIndicator.class, HealthAggregator.class }) public DiscoveryCompositeHealthIndicator discoveryCompositeHealthIndicator( HealthAggregator aggregator, List<DiscoveryHealthIndicator> indicators) { return new DiscoveryCompositeHealthIndicator(aggregator, indicators); }
@Autowired public DiscoveryCompositeHealthIndicator(HealthAggregator healthAggregator, List<DiscoveryHealthIndicator> indicators) { super(healthAggregator); for (DiscoveryHealthIndicator indicator : indicators) { Holder holder = new Holder(indicator); addHealthIndicator(indicator.getName(), holder); healthIndicators.add(holder); } }
@Test public void testHealthIndicator() { assertNotNull("healthIndicator was null", this.healthIndicator); Health health = this.healthIndicator.health(); assertHealth(health, Status.UNKNOWN); clientHealthIndicator.onApplicationEvent(new InstanceRegisteredEvent<>(this, null)); health = this.healthIndicator.health(); Status status = assertHealth(health, Status.UP); assertEquals("status description was wrong", "", status.getDescription()); }
@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()); } } }
@Test public void testHealthIndicatorDescriptionDisabled() { assertNotNull("healthIndicator was null", this.healthIndicator); Health health = this.healthIndicator.health(); assertHealth(health, Status.UNKNOWN); clientHealthIndicator.onApplicationEvent(new InstanceRegisteredEvent<>(this, null)); health = this.healthIndicator.health(); Status status = assertHealth(health, Status.UP); assertEquals("status description was wrong", "TestDiscoveryClient", status.getDescription()); }
@Autowired public DiscoveryCompositeHealthIndicator(HealthAggregator healthAggregator, List<DiscoveryHealthIndicator> indicators) { super(healthAggregator); for (DiscoveryHealthIndicator indicator : indicators) { Holder holder = new Holder(indicator); addHealthIndicator(indicator.getName(), holder); healthIndicators.add(holder); } }
@Bean @ConditionalOnProperty(value = "spring.cloud.discovery.client.composite-indicator.enabled", matchIfMissing = true) @ConditionalOnBean({ DiscoveryHealthIndicator.class, HealthAggregator.class }) public DiscoveryCompositeHealthIndicator discoveryCompositeHealthIndicator( HealthAggregator aggregator, List<DiscoveryHealthIndicator> indicators) { return new DiscoveryCompositeHealthIndicator(aggregator, indicators); }