Skip to content

Commit

Permalink
sidecar: check if transport is up in readiness check (#249)
Browse files Browse the repository at this point in the history
Fixes #249
  • Loading branch information
zimnx committed Nov 16, 2020
1 parent e1b79e2 commit b7e6314
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions pkg/controllers/sidecar/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,42 @@ func livenessCheck(mc *MemberReconciler) func(http.ResponseWriter, *http.Request

func readinessCheck(mc *MemberReconciler) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
ctx := log.WithTraceID(req.Context())

host, err := network.FindFirstNonLocalIP()
if err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
mc.logger.Error(log.WithTraceID(req.Context()), "Readiness check failed", "error", err)
mc.logger.Error(ctx, "Readiness check failed", "error", err)
return
}

// Contact Scylla to learn about the status of the member
hosts, err := mc.scyllaClient.Status(context.Background(), host.String())
if err != nil {
mc.logger.Error(log.WithTraceID(req.Context()), "error while executing nodetool status in readiness check", "error", err)
mc.logger.Error(ctx, "error while executing nodetool status in readiness check", "error", err)
}

for _, h := range hosts {
mc.logger.Debug(ctx, "Host readiness", "host", h.Addr, "status", h.Status, "state", h.State)
}
for _, h := range hosts {
if h.Addr == mc.member.StaticIP && h.IsUN() {
w.WriteHeader(http.StatusOK)
return
transportEnabled, err := mc.scyllaClient.IsNativeTransportEnabled(ctx, host.String())
if err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
mc.logger.Error(ctx, "Readiness check failed", "error", err)
return
}

mc.logger.Debug(ctx, "Host native transport", "host", h.Addr, "enabled", transportEnabled)
if transportEnabled {
w.WriteHeader(http.StatusOK)
return
}
}
}
mc.logger.Error(log.WithTraceID(req.Context()), "Readiness check failed, node not ready")

mc.logger.Error(ctx, "Readiness check failed, node not ready")
w.WriteHeader(http.StatusServiceUnavailable)
}
}

0 comments on commit b7e6314

Please sign in to comment.