From 859d9dfdddf0299912ff45d50fd4238fdbe5334c Mon Sep 17 00:00:00 2001 From: Carina Kothe <69976260+grischperl@users.noreply.github.com> Date: Tue, 16 Jan 2024 16:25:06 +0100 Subject: [PATCH] Make readiness state of EPP dependant on availability of NATS (#49) * Make readiness state of EPP dependant on availability of NATS * Sort imports --- pkg/sender/jetstream/health.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/sender/jetstream/health.go b/pkg/sender/jetstream/health.go index 129ab00..d5d5439 100644 --- a/pkg/sender/jetstream/health.go +++ b/pkg/sender/jetstream/health.go @@ -3,6 +3,8 @@ package jetstream import ( "net/http" + "github.com/nats-io/nats.go" + "github.com/kyma-project/eventing-publisher-proxy/pkg/handler/health" ) @@ -10,6 +12,11 @@ import ( // It checks the NATS server connection status and reports 2XX if connected, otherwise reports 5XX. // It panics if the given NATS Handler is nil. func (s *Sender) ReadinessCheck(w http.ResponseWriter, _ *http.Request) { + if status := s.ConnectionStatus(); status != nats.CONNECTED { + s.namedLogger().Error("Readiness check failed: not connected to nats server") + w.WriteHeader(health.StatusCodeNotHealthy) + return + } w.WriteHeader(health.StatusCodeHealthy) }