Skip to content

DiscoveryClientHealthIndicator active but discovery client not initialized #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dkroehan opened this issue Nov 4, 2019 · 3 comments
Closed
Labels

Comments

@dkroehan
Copy link

dkroehan commented Nov 4, 2019

We just updated to Spring Boot 2.2.0 and also moved to the Hoxton Release Train.

We have the following integration test for our custom health checks:

@RunWith(SpringRunner.class)
@EnableAutoConfiguration
@SpringBootTest(classes = {LivenessCheckAutoConfiguration.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = {"management.endpoint.health.custom: false"})
public class CustomReadinessCheckDisabledIntTest {

    @Autowired
    private TestRestTemplate restTemplate;

    @Test
    public void testCustomHealthCheckDisabled() {
        String body = this.restTemplate.getForObject("/health", String.class);
        assertThat(body, is(notNullValue()));

        assertThat(body, is("{\"status\":\"UP\",\"components\":{\"ping\":{\"status\":\"UP\"}}}"));
    }
}

We also have the following properties set:
management.health.defaults.enabled: false and management.health.ping.enabled: true

Since the Hoxton.M3 Release the DiscoveryClientHealthIndicator is now active which results in the test to fail with:

java.lang.AssertionError:
Expected: is "{\"status\":\"UP\",\"components\":{\"ping\":{\"status\":\"UP\"}}}"
     but: was "{\"status\":\"UP\",\"components\":{\"discoveryComposite\":{\"description\":\"Discovery Client not initialized\",\"status\":\"UNKNOWN\",\"components\":{\"discoveryClient\":{\"description\":\"Discovery Client not initialized\",\"status\":\"UNKNOWN\"}}},\"ping\":{\"status\":\"UP\"}}}"

Is this intended behaviour or a bug?
Should the DiscoveryClientHealthIndicator be affected by management.health.defaults.enabled: false?
There was a related change in the Spring Boot 2.2.0 Update: See: spring-projects/spring-boot#17926 and spring-projects/spring-boot#18676

If it is an issue:
We tracked it down to the DiscoveryClientHealthIndicator bean that is registered in CommonsClientAutoConfiguration.DiscoveryLoadBalancerConfiguration.

In Greenwich.SR2 and Hoxton.M2 the CommonsClientAutoConfiguration.DiscoveryLoadBalancerConfiguration is not loaded, because of:

   CommonsClientAutoConfiguration.DiscoveryLoadBalancerConfiguration:
      Did not match:
         - @ConditionalOnBean (types: org.springframework.cloud.client.discovery.DiscoveryClient; SearchStrategy: all) did not find any beans of type org.springframework.cloud.client.discovery.DiscoveryClient (OnBeanCondition)
      Matched:
         - @ConditionalOnClass found required class 'org.springframework.boot.actuate.health.HealthIndicator' (OnClassCondition)
         - @ConditionalOnProperty (spring.cloud.discovery.enabled) matched (OnPropertyCondition)

Now this bean is loaded due the change of the @AutoConfigureBefore in SimpleDiscoveryClientAutoConfiguration.
See:

@OlgaMaciaszek
Copy link
Collaborator

Hello @dkroehan , I think this is something that the team has to discuss.

In the meantime, as stated in the docs:

Commons creates a Spring Boot HealthIndicator that DiscoveryClient implementations can participate in by implementing DiscoveryHealthIndicator.
To disable the composite HealthIndicator, set spring.cloud.discovery.client.composite-indicator.enabled=false.
A generic HealthIndicator based on DiscoveryClient is auto-configured (DiscoveryClientHealthIndicator).

Would that work as a workaround for you?

@dkroehan
Copy link
Author

dkroehan commented Jul 3, 2020

Yes, the workaround works for us. So far we used spring.cloud.discovery.enabled=false in our tests.

@spencergibb
Copy link
Member

fixed in previous commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants