Replace Status port using a socket
This commit is contained in:
parent
bd74dce19c
commit
34b0580225
15 changed files with 357 additions and 309 deletions
|
|
@ -21,13 +21,13 @@ import (
|
|||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ncabatoff/process-exporter/proc"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
"k8s.io/klog"
|
||||
|
||||
const nginxPID = "/tmp/nginx.pid"
|
||||
"k8s.io/ingress-nginx/internal/nginx"
|
||||
)
|
||||
|
||||
// Name returns the healthcheck name
|
||||
func (n NGINXController) Name() string {
|
||||
|
|
@ -36,25 +36,25 @@ 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 {
|
||||
|
||||
url := fmt.Sprintf("http://127.0.0.1:%v%v", n.cfg.ListenPorts.Status, ngxHealthPath)
|
||||
timeout := n.cfg.HealthCheckTimeout
|
||||
statusCode, err := simpleGet(url, timeout)
|
||||
statusCode, _, err := nginx.NewGetStatusRequest(nginx.HealthPath)
|
||||
if err != nil {
|
||||
klog.Errorf("healthcheck error: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if statusCode != 200 {
|
||||
klog.Errorf("healthcheck error: %v", statusCode)
|
||||
return fmt.Errorf("ingress controller is not healthy")
|
||||
}
|
||||
|
||||
url = fmt.Sprintf("http://127.0.0.1:%v/is-dynamic-lb-initialized", n.cfg.ListenPorts.Status)
|
||||
statusCode, err = simpleGet(url, timeout)
|
||||
statusCode, _, err = nginx.NewGetStatusRequest("/is-dynamic-lb-initialized")
|
||||
if err != nil {
|
||||
klog.Errorf("healthcheck error: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if statusCode != 200 {
|
||||
klog.Errorf("healthcheck error: %v", statusCode)
|
||||
return fmt.Errorf("dynamic load balancer not started")
|
||||
}
|
||||
|
||||
|
|
@ -63,35 +63,14 @@ func (n *NGINXController) Check(_ *http.Request) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "unexpected error reading /proc directory")
|
||||
}
|
||||
f, err := n.fileSystem.ReadFile(nginxPID)
|
||||
f, err := n.fileSystem.ReadFile(nginx.PID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unexpected error reading %v", nginxPID)
|
||||
return errors.Wrapf(err, "unexpected error reading %v", nginx.PID)
|
||||
}
|
||||
pid, err := strconv.Atoi(strings.TrimRight(string(f), "\r\n"))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unexpected error reading the nginx PID from %v", nginxPID)
|
||||
return errors.Wrapf(err, "unexpected error reading the nginx PID from %v", nginx.PID)
|
||||
}
|
||||
_, err = fs.NewProc(pid)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func simpleGet(url string, timeout time.Duration) (int, error) {
|
||||
client := &http.Client{
|
||||
Timeout: timeout * 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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue