Skip to content
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

fix: kafka health indicator requires kafka configuration #937

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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