diff --git a/pkg/health/health.go b/pkg/health/health.go index 9136409a404..56c00803417 100644 --- a/pkg/health/health.go +++ b/pkg/health/health.go @@ -16,11 +16,7 @@ limitations under the License. package health -import ( - "net/http" - - "github.com/golang/glog" -) +import () type Status int @@ -30,25 +26,3 @@ const ( Unhealthy Unknown ) - -// HTTPGetInterface is an abstract interface for testability. It abstracts the interface of http.Client.Get. -type HTTPGetInterface interface { - Get(url string) (*http.Response, error) -} - -// DoHTTPCheck checks if a GET request to the url succeeds. -// If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Healthy. -// If the HTTP response code is unsuccessful, it returns Unhealthy. -// It returns Unknown and err if the HTTP communication itself fails. -func DoHTTPCheck(url string, client HTTPGetInterface) (Status, error) { - res, err := client.Get(url) - if err != nil { - return Unknown, err - } - defer res.Body.Close() - if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest { - return Healthy, nil - } - glog.V(1).Infof("Health check failed for %s, Response: %v", url, *res) - return Unhealthy, nil -} diff --git a/pkg/health/health_check.go b/pkg/health/health_check.go index 1444d6b230c..f98ccaa6f5d 100644 --- a/pkg/health/health_check.go +++ b/pkg/health/health_check.go @@ -61,6 +61,12 @@ func (m *MuxHealthChecker) HealthCheck(currentState api.PodState, container api. return checker.HealthCheck(currentState, container) } +// HTTPGetInterface is an abstract interface for testability. It abstracts the interface of http.Client.Get. +type HTTPGetInterface interface { + Get(url string) (*http.Response, error) +} + +// DoHTTPCheck checks if a GET request to the url succeeds. // HTTPHealthChecker is an implementation of HealthChecker which checks container health by sending HTTP Get requests. type HTTPHealthChecker struct { client HTTPGetInterface @@ -115,6 +121,22 @@ func formatURL(host string, port int, path string) string { return fmt.Sprintf("http://%s:%d%s", host, port, path) } +// If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Healthy. +// If the HTTP response code is unsuccessful, it returns Unhealthy. +// It returns Unknown and err if the HTTP communication itself fails. +func DoHTTPCheck(url string, client HTTPGetInterface) (Status, error) { + res, err := client.Get(url) + if err != nil { + return Unknown, err + } + defer res.Body.Close() + if res.StatusCode >= http.StatusOK && res.StatusCode < http.StatusBadRequest { + return Healthy, nil + } + glog.V(1).Infof("Health check failed for %s, Response: %v", url, *res) + return Unhealthy, nil +} + // HealthCheck checks if the container is healthy by trying sending HTTP Get requests to the container. func (h *HTTPHealthChecker) HealthCheck(currentState api.PodState, container api.Container) (Status, error) { host, port, path, err := getURLParts(currentState, container)