refactor: improve route healthcheck

This commit is contained in:
Jonas Kaninda
2024-11-12 15:00:16 +01:00
parent 9eadd08a1f
commit 5bc85c9814

View File

@@ -40,8 +40,8 @@ func (health Health) Check() error {
client := &http.Client{Timeout: health.TimeOut} client := &http.Client{Timeout: health.TimeOut}
healthResp, err := client.Do(healthReq) healthResp, err := client.Do(healthReq)
if err != nil { if err != nil {
logger.Error("Error route %s: performing HealthCheck request: %v ", health.Name, err) logger.Debug("Error route %s: performing HealthCheck request: %v ", health.Name, err)
return fmt.Errorf("Error route %s: performing HealthCheck request: %v ", health.Name, err) return fmt.Errorf("error performing HealthCheck request: %v ", err)
} }
defer func(Body io.ReadCloser) { defer func(Body io.ReadCloser) {
err := Body.Close() err := Body.Close()
@@ -50,13 +50,13 @@ func (health Health) Check() error {
}(healthResp.Body) }(healthResp.Body)
if len(health.HealthyStatuses) > 0 { if len(health.HealthyStatuses) > 0 {
if !slices.Contains(health.HealthyStatuses, healthResp.StatusCode) { if !slices.Contains(health.HealthyStatuses, healthResp.StatusCode) {
logger.Error("Error: Route %s: health check failed with status code %d", health.Name, healthResp.StatusCode) logger.Debug("Error: Route %s: health check failed with status code %d", health.Name, healthResp.StatusCode)
return fmt.Errorf("route %s health check failed with status code %d", health.Name, healthResp.StatusCode) return fmt.Errorf("health check failed with status code %d", healthResp.StatusCode)
} }
} else { } else {
if healthResp.StatusCode >= 400 { if healthResp.StatusCode >= 400 {
logger.Error("Error: Route %s: health check failed with status code %d", health.Name, healthResp.StatusCode) logger.Debug("Error: Route %s: health check failed with status code %d", health.Name, healthResp.StatusCode)
return fmt.Errorf("route %s: health check failed with status code %d", health.Name, healthResp.StatusCode) return fmt.Errorf("health check failed with status code %d", healthResp.StatusCode)
} }
} }
return nil return nil