health check depends on updated stats (#183)
This commit is contained in:
@@ -427,7 +427,7 @@ func (r *RedisRouter) handleRTCMessage(rm *livekit.RTCNodeMessage) error {
|
||||
}
|
||||
|
||||
case *livekit.RTCNodeMessage_KeepAlive:
|
||||
if time.Unix(rm.SenderTime, 0).Add(statsUpdateInterval).Before(time.Now()) {
|
||||
if time.Now().Sub(time.Unix(rm.SenderTime, 0)) > statsUpdateInterval {
|
||||
logger.Infow("keep alive too old, skipping", "senderTime", rm.SenderTime)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -256,7 +256,18 @@ func (s *LivekitServer) debugInfo(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *LivekitServer) healthCheck(w http.ResponseWriter, r *http.Request) {
|
||||
var updatedAt time.Time
|
||||
if s.Node().Stats != nil {
|
||||
updatedAt = time.Unix(s.Node().Stats.UpdatedAt, 0)
|
||||
}
|
||||
if time.Now().Sub(updatedAt) > 4*time.Second {
|
||||
w.WriteHeader(http.StatusNotAcceptable)
|
||||
w.Write([]byte(fmt.Sprintf("Not Ready\nNode Updated At %s", updatedAt)))
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte([]byte("OK")))
|
||||
}
|
||||
|
||||
// worker to perform periodic tasks per node
|
||||
|
||||
Reference in New Issue
Block a user