Add a status option to the service health check

This commit is contained in:
Ali Afsharzadeh
2022-11-24 14:10:05 +03:30
committed by GitHub
parent 61325d7b91
commit 46c266661c
17 changed files with 97 additions and 2 deletions
+5 -1
View File
@@ -173,10 +173,14 @@ func (shc *ServiceHealthChecker) checkHealthHTTP(ctx context.Context, target *ur
defer resp.Body.Close()
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusBadRequest {
if shc.config.Status == 0 && (resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusBadRequest) {
return fmt.Errorf("received error status code: %v", resp.StatusCode)
}
if shc.config.Status != 0 && shc.config.Status != resp.StatusCode {
return fmt.Errorf("received error status code: %v expected status code: %v", resp.StatusCode, shc.config.Status)
}
return nil
}