Skip to content

Commit

Permalink
fix: kafka health indicator requires kafka configuration (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
rorueda authored Jan 15, 2024
1 parent d8d1d0a commit b1193d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
* @since 1.0
*/
@Singleton
@Requires(bean = KafkaDefaultConfiguration.class)
@Requires(property = KafkaHealthConfigurationProperties.PREFIX + ".enabled", value = StringUtils.TRUE, defaultValue = StringUtils.TRUE)
public class KafkaHealthIndicator implements HealthIndicator, ClusterResourceListener {
private static final String ID = "kafka";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.micronaut.configuration.kafka.health

import io.micronaut.configuration.kafka.AbstractKafkaSpec
import io.micronaut.configuration.kafka.config.KafkaDefaultConfiguration
import io.micronaut.context.ApplicationContext
import io.micronaut.core.io.socket.SocketUtils
import io.micronaut.management.health.indicator.HealthResult
Expand Down Expand Up @@ -70,6 +71,27 @@ class KafkaHealthIndicatorSpec extends AbstractKafkaSpec {
configvalue << [false, "false", "no", ""]
}
void "test kafka health indicator - disabled when no kafka configuration provided"() {
given:
ApplicationContext applicationContext = ApplicationContext.run(configuration +
["test-resources.containers.kafka.enabled": false])
when:
Optional<KafkaDefaultConfiguration> config = applicationContext.findBean(KafkaDefaultConfiguration)
then:
config.isEmpty()
when:
Optional<KafkaHealthIndicator> healthIndicator = applicationContext.findBean(KafkaHealthIndicator)
then:
healthIndicator.isEmpty()
cleanup:
applicationContext.close()
}
@Unroll
void "kafka health indicator handle missing replication factor config"() {
given:
Expand Down

0 comments on commit b1193d7

Please sign in to comment.