Repository: cortexlabs/cortex (language: go)

Issue:
Remove liveness check on API containers



Discussion / hints:

Fix patch:
diff --git a/pkg/cortex/serve/cortex_internal/serve/serve.py b/pkg/cortex/serve/cortex_internal/serve/serve.py
index afe5152ecc..1a80f0c751 100644
--- a/pkg/cortex/serve/cortex_internal/serve/serve.py
+++ b/pkg/cortex/serve/cortex_internal/serve/serve.py
@@ -44,7 +44,6 @@
     "make a prediction by sending a post request to this endpoint with a json payload"
 )
 
-API_LIVENESS_UPDATE_PERIOD = 5  # seconds
 NANOSECONDS_IN_SECOND = 1e9
 
 
@@ -64,16 +63,9 @@
 }
 
 
-def update_api_liveness():
-    threading.Timer(API_LIVENESS_UPDATE_PERIOD, update_api_liveness).start()
-    with open("/mnt/workspace/api_liveness.txt", "w") as f:
-        f.write(str(math.ceil(time.time())))
-
-
 @app.on_event("startup")
 def startup():
     open(f"/mnt/workspace/proc-{os.getpid()}-ready.txt", "a").close()
-    update_api_liveness()
 
 
 @app.on_event("shutdown")
@@ -88,11 +80,6 @@ def shutdown():
     except FileNotFoundError:
         pass
 
-    try:
-        os.remove("/mnt/workspace/api_liveness.txt")
-    except FileNotFoundError:
-        pass
-
 
 def is_prediction_request(request):
     return request.url.path == local_cache["predict_route"] and request.method == "POST"
diff --git a/pkg/cortex/serve/init/bootloader.sh b/pkg/cortex/serve/init/bootloader.sh
index 3f12a3da01..9cd9c3d126 100755
--- a/pkg/cortex/serve/init/bootloader.sh
+++ b/pkg/cortex/serve/init/bootloader.sh
@@ -37,9 +37,6 @@ rm -rf /mnt/workspace/api_readiness.txt
 rm -rf /mnt/workspace/init_script_run.txt
 rm -rf /mnt/workspace/proc-*-ready.txt
 
-# allow for the liveness check to pass until the API is running
-echo "9999999999" > /mnt/workspace/api_liveness.txt
-
 if [ "$CORTEX_KIND" == "RealtimeAPI" ]; then
     sysctl -w net.core.somaxconn="65535" >/dev/null
     sysctl -w net.ipv4.ip_local_port_range="15000 64000" >/dev/null
diff --git a/pkg/cortex/serve/start/batch.py b/pkg/cortex/serve/start/batch.py
index 7c7959ac6e..a26a96e3f0 100644
--- a/pkg/cortex/serve/start/batch.py
+++ b/pkg/cortex/serve/start/batch.py
@@ -37,7 +37,6 @@
 from cortex_internal.lib.storage import S3
 from cortex_internal.lib.exceptions import UserRuntimeException
 
-API_LIVENESS_UPDATE_PERIOD = 5  # seconds
 SQS_POLL_WAIT_TIME = 10  # seconds
 MESSAGE_NOT_FOUND_SLEEP = 10  # seconds
 INITIAL_MESSAGE_VISIBILITY = 30  # seconds
diff --git a/pkg/operator/operator/k8s.go b/pkg/operator/operator/k8s.go
index 7f11248550..b2d2f6274d 100644
--- a/pkg/operator/operator/k8s.go
+++ b/pkg/operator/operator/k8s.go
@@ -64,9 +64,7 @@ const (
 	_tfServingLoadTimeMicros                       = "30000000" // 30 seconds (how much time a model can take to load into memory)
 	_tfServingBatchConfig                          = "/etc/tfs/batch_config.conf"
 	_apiReadinessFile                              = "/mnt/workspace/api_readiness.txt"
-	_apiLivenessFile                               = "/mnt/workspace/api_liveness.txt"
 	_neuronRTDSocket                               = "/sock/neuron.sock"
-	_apiLivenessStalePeriod                        = 7 // seconds (there is a 2-second buffer to be safe)
 	_requestMonitorReadinessFile                   = "/request_monitor_ready.txt"
 )
 
@@ -196,7 +194,6 @@ func PythonPredictorContainers(api *spec.API) ([]kcore.Container, []kcore.Volume
 		EnvFrom:         baseEnvVars(),
 		VolumeMounts:    apiPodVolumeMounts,
 		ReadinessProbe:  FileExistsProbe(_apiReadinessFile),
-		LivenessProbe:   _apiLivenessProbe,
 		Lifecycle:       nginxGracefulStopper(api.Kind),
 		Resources: kcore.ResourceRequirements{
 			Requests: apiPodResourceList,
@@ -301,7 +298,6 @@ func TensorFlowPredictorContainers(api *spec.API) ([]kcore.Container, []kcore.Vo
 		EnvFrom:         baseEnvVars(),
 		VolumeMounts:    volumeMounts,
 		ReadinessProbe:  FileExistsProbe(_apiReadinessFile),
-		LivenessProbe:   _apiLivenessProbe,
 		Lifecycle:       nginxGracefulStopper(api.Kind),
 		Resources: kcore.ResourceRequirements{
 			Requests: apiResourceList,
@@ -373,7 +369,6 @@ func ONNXPredictorContainers(api *spec.API) ([]kcore.Container, []kcore.Volume)
 		EnvFrom:         baseEnvVars(),
 		VolumeMounts:    apiPodVolumeMounts,
 		ReadinessProbe:  FileExistsProbe(_apiReadinessFile),
-		LivenessProbe:   _apiLivenessProbe,
 		Lifecycle:       nginxGracefulStopper(api.Kind),
 		Resources: kcore.ResourceRequirements{
 			Requests: resourceList,
@@ -803,19 +798,6 @@ func RequestMonitorContainer(api *spec.API) kcore.Container {
 	}
 }
 
-var _apiLivenessProbe = &kcore.Probe{
-	InitialDelaySeconds: 5,
-	TimeoutSeconds:      5,
-	PeriodSeconds:       5,
-	SuccessThreshold:    1,
-	FailureThreshold:    3,
-	Handler: kcore.Handler{
-		Exec: &kcore.ExecAction{
-			Command: []string{"/bin/bash", "-c", `now="$(date +%s)" && min="$(($now-` + s.Int(_apiLivenessStalePeriod) + `))" && test "$(cat ` + _apiLivenessFile + ` | tr -d '[:space:]')" -ge "$min"`},
-		},
-	},
-}
-
 func FileExistsProbe(fileName string) *kcore.Probe {
 	return &kcore.Probe{
 		InitialDelaySeconds: 3,


Test patch: