You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@yunikorn.apache.org by GitBox <gi...@apache.org> on 2022/03/26 12:16:46 UTC

[GitHub] [yunikorn-core] lowc1012 commented on a change in pull request #395: [YUNIKORN-1107] Make health check occur in the background

lowc1012 commented on a change in pull request #395:
URL: https://github.com/apache/yunikorn-core/pull/395#discussion_r835758297



##########
File path: pkg/webservice/handlers.go
##########
@@ -516,14 +516,23 @@ func isChecksumEqual(checksum string) bool {
 
 func checkHealthStatus(w http.ResponseWriter, r *http.Request) {
 	writeHeaders(w)
-	metrics := metrics2.GetSchedulerMetrics()
-	result := scheduler.GetSchedulerHealthStatus(metrics, schedulerContext)
-	if !result.Healthy {
-		log.Logger().Error("Scheduler is not healthy", zap.Any("health check values", result.HealthChecks))
-		buildJSONErrorResponse(w, "Scheduler is not healthy", http.StatusServiceUnavailable)
-	}
-	if err := json.NewEncoder(w).Encode(result); err != nil {
-		buildJSONErrorResponse(w, err.Error(), http.StatusInternalServerError)
+
+	// Fetch last healthCheck result
+	result := schedulerContext.GetLastHealthCheckResult()
+	if result != nil {
+		if !result.Healthy {
+			log.Logger().Error("Scheduler is not healthy", zap.Any("health check info", *result))
+			buildJSONErrorResponse(w, "Scheduler is not healthy", http.StatusServiceUnavailable)
+		} else {
+			log.Logger().Info("Scheduler is healthy", zap.Any("health check info", *result))
+			buildJSONErrorResponse(w, "Scheduler is healthy", http.StatusOK)

Review comment:
       done

##########
File path: pkg/webservice/handlers.go
##########
@@ -516,14 +516,23 @@ func isChecksumEqual(checksum string) bool {
 
 func checkHealthStatus(w http.ResponseWriter, r *http.Request) {
 	writeHeaders(w)
-	metrics := metrics2.GetSchedulerMetrics()
-	result := scheduler.GetSchedulerHealthStatus(metrics, schedulerContext)
-	if !result.Healthy {
-		log.Logger().Error("Scheduler is not healthy", zap.Any("health check values", result.HealthChecks))
-		buildJSONErrorResponse(w, "Scheduler is not healthy", http.StatusServiceUnavailable)
-	}
-	if err := json.NewEncoder(w).Encode(result); err != nil {
-		buildJSONErrorResponse(w, err.Error(), http.StatusInternalServerError)
+
+	// Fetch last healthCheck result
+	result := schedulerContext.GetLastHealthCheckResult()
+	if result != nil {
+		if !result.Healthy {
+			log.Logger().Error("Scheduler is not healthy", zap.Any("health check info", *result))
+			buildJSONErrorResponse(w, "Scheduler is not healthy", http.StatusServiceUnavailable)
+		} else {
+			log.Logger().Info("Scheduler is healthy", zap.Any("health check info", *result))
+			buildJSONErrorResponse(w, "Scheduler is healthy", http.StatusOK)

Review comment:
       Done. Thanks!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org