@Override public Health health() { return this.delegate.health(); }
@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.health-indicator.enabled", matchIfMissing = true) public DiscoveryClientHealthIndicator discoveryClientHealthIndicator( ObjectProvider<DiscoveryClient> discoveryClient, DiscoveryClientHealthIndicatorProperties properties) { return new DiscoveryClientHealthIndicator(discoveryClient, properties); }
@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 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()); }
@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()); }
@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); }
@Override public Health health() { Health.Builder builder = new Health.Builder(); if (this.discoveryInitialized.get()) { try { DiscoveryClient client = this.discoveryClient.getIfAvailable(); List<String> services = client.getServices(); String description = (this.properties.isIncludeDescription()) ? client.description() : ""; builder.status(new Status("UP", description)) .withDetail("services", services); } catch (Exception e) { log.error("Error", e); builder.down(e); } } else { builder.status(new Status(Status.UNKNOWN.getCode(), "Discovery Client not initialized")); } return builder.build(); }
@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); } }
@Override public Health health() { return this.delegate.health(); }
@Bean @ConditionalOnProperty(value = "spring.cloud.discovery.client.health-indicator.enabled", matchIfMissing = true) public DiscoveryClientHealthIndicator discoveryClientHealthIndicator( ObjectProvider<DiscoveryClient> discoveryClient, DiscoveryClientHealthIndicatorProperties properties) { return new DiscoveryClientHealthIndicator(discoveryClient, properties); }
@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); }
@Override public Health health() { Health.Builder builder = new Health.Builder(); if (this.discoveryInitialized.get()) { try { DiscoveryClient client = this.discoveryClient.getIfAvailable(); List<String> services = client.getServices(); String description = (this.properties.isIncludeDescription()) ? client.description() : ""; builder.status(new Status("UP", description)) .withDetail("services", services); } catch (Exception e) { log.error("Error", e); builder.down(e); } } else { builder.status(new Status(Status.UNKNOWN.getCode(), "Discovery Client not initialized")); } return builder.build(); }