Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor probe url requests #3247

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions internal/ingress/controller/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"strconv"
"strings"
"time"

"github.com/ncabatoff/process-exporter/proc"
"github.com/pkg/errors"
Expand All @@ -35,21 +36,24 @@ func (n NGINXController) Name() string {

// Check returns if the nginx healthz endpoint is returning ok (status code 200)
func (n *NGINXController) Check(_ *http.Request) error {
res, err := http.Get(fmt.Sprintf("http://127.0.0.1:%v%v", n.cfg.ListenPorts.Status, ngxHealthPath))

url := fmt.Sprintf("http://127.0.0.1:%v%v", n.cfg.ListenPorts.Status, ngxHealthPath)
statusCode, err := simpleGet(url)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != 200 {

if statusCode != 200 {
return fmt.Errorf("ingress controller is not healthy")
}

res, err = http.Get(fmt.Sprintf("http://127.0.0.1:%v/is-dynamic-lb-initialized", n.cfg.ListenPorts.Status))
url = fmt.Sprintf("http://127.0.0.1:%v/is-dynamic-lb-initialized", n.cfg.ListenPorts.Status)
statusCode, err = simpleGet(url)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode != 200 {

if statusCode != 200 {
return fmt.Errorf("dynamic load balancer not started")
}

Expand All @@ -70,3 +74,23 @@ func (n *NGINXController) Check(_ *http.Request) error {

return err
}

func simpleGet(url string) (int, error) {
client := &http.Client{
Timeout: 10 * time.Second,
Transport: &http.Transport{DisableKeepAlives: true},
}

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return -1, err
}

res, err := client.Do(req)
if err != nil {
return -1, err
}
defer res.Body.Close()

return res.StatusCode, nil
}