spring-cloud / spring-cloud-stream-binder-kafka

Spring Cloud Stream binders for Apache Kafka and Kafka Streams
Apache License 2.0
331 stars 301 forks source link

Health Check for Binders Always Shows 'UNKNOWN' Status Due to Empty binderHealthContributors Map (Missing Bean Configuration for ReactorKafkaBinderHealthIndicator?) #1235

Closed hb12devtn closed 3 months ago

hb12devtn commented 3 months ago

Hi, I encountered an issue while working with Spring Cloud Stream where the ReactorKafkaBinderHealthIndicator class is not being found. Upon further investigation, it appears that the health check for the binders is consistently showing "UNKNOWN" status. This is because the binderHealthContributors map within the BindersHealthContributor class is always empty, leading to the obtainContributor method returning the UNKNOWN health contributor. It seems that the binderHealthContributors map is not being populated with any health contributors, hence the health status remains "UNKNOWN" for the binders.

Here's the relevant code snippet from the BindersHealthContributor class:

// Relevant code snippet from BindersHealthContributor class
private HealthContributor obtainContributor(Map<String, HealthContributor> binderHealthContributors) {
    if (binderHealthContributors.isEmpty()) {
        return UNKNOWN;
    }
    if (binderHealthContributors.size() == 1) {
        return binderHealthContributors.values().iterator().next();
    }
    return CompositeHealthContributor.fromMap(binderHealthContributors);
}

Steps to Reproduce:

  1. Include Spring Cloud Stream and Reactor Kafka Binder dependencies.
  2. Configure health checks for the binders.
  3. Observe the health status for the binders.

Expected Behavior:

Actual Behavior:

Additional Information:

hb12devtn commented 3 months ago

We can resolve this by adding a ReactorKafkaBinderHealthIndicator bean to ReactorKafkaBinderConfiguration:

@Bean
public ReactorKafkaBinderHealthIndicator reactorKafkaBinderHealthIndicator(ReactorKafkaBinder binder, ConsumerFactory<?, ?> cf) {
    return new ReactorKafkaBinderHealthIndicator(binder, cf);
}

Alternatively, we can create a separate configuration class, similar to KafkaBinderHealthIndicatorConfiguration, specifically for ReactorKafkaBinderHealthIndicator.

hb12devtn commented 3 months ago

closed in https://github.com/spring-cloud/spring-cloud-stream/issues/2948