feat: add configuration checking

This commit is contained in:
Jonas Kaninda
2024-11-10 14:52:31 +01:00
parent 1a038ce0f5
commit a549e33e9a
9 changed files with 202 additions and 36 deletions

View File

@@ -21,9 +21,10 @@ import (
"io"
"net/http"
"net/url"
"slices"
)
func healthCheck(healthURL string) error {
func healthCheck(healthURL string, healthyStatuses []int) error {
healthCheckURL, err := url.Parse(healthURL)
if err != nil {
return fmt.Errorf("error parsing HealthCheck URL: %v ", err)
@@ -45,10 +46,16 @@ func healthCheck(healthURL string) error {
if err != nil {
}
}(healthResp.Body)
if healthResp.StatusCode >= 400 {
logger.Debug("Error performing HealthCheck request: %v ", err)
return fmt.Errorf("health check failed with status code %v", healthResp.StatusCode)
if len(healthyStatuses) > 0 {
if !slices.Contains(healthyStatuses, healthResp.StatusCode) {
logger.Error("Error performing HealthCheck request: %v ", err)
return fmt.Errorf("health check failed with status code %v", healthResp.StatusCode)
}
} else {
if healthResp.StatusCode >= 400 {
logger.Debug("Error performing HealthCheck request: %v ", err)
return fmt.Errorf("health check failed with status code %v", healthResp.StatusCode)
}
}
return nil
}