Skip to content

Commit

Permalink
Make readiness state of EPP dependant on availability of NATS (#49)
Browse files Browse the repository at this point in the history
* Make readiness state of EPP dependant on availability of NATS

* Sort imports
  • Loading branch information
grischperl authored Jan 16, 2024
1 parent 4304da4 commit 859d9df
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/sender/jetstream/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ package jetstream
import (
"net/http"

"github.com/nats-io/nats.go"

"github.com/kyma-project/eventing-publisher-proxy/pkg/handler/health"
)

// ReadinessCheck returns an instance of http.HandlerFunc that checks the readiness of the given NATS Handler.
// 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)
}

Expand Down

0 comments on commit 859d9df

Please sign in to comment.