I am trying to implement health check using "github.com/heptiolabs/healthcheck" package in go but unable to figure out how to do it for kafka.
package main
import (
"fmt"
"github.com/heptiolabs/healthcheck"
)
func runHealthCheck() {
health := healthcheck.NewHandler()
timeoutDuration := 5 * time.Second
kafkaUrl := "<kafka_broker>:port"
health.AddLivenessCheck("health-check", healthcheck.HTTPGetCheck(kafkaUrl, timeoutDuration))
go func() {
err = http.ListenAndServe(":9080", health)
if err != nil {
panic(fmt.Sprintf("Error running server: %v", err))
}
}()
}
First, no, Kafka is not an HTTP server. Don't use HTTP healthchecks for it.
You can use AdminClient to describe the topic you're using to check topic health (min ISR is met, for example), or describe the cluster to check Kafka connectivity separately from any consumer/producer.
Otherwise, you could catch certain errors from the other clients, then set some boolean flag in the app for health