mirror of
https://github.com/umputun/reproxy.git
synced 2025-06-30 22:13:42 +02:00
removed unneded atomic in health check
This commit is contained in:
@ -5,7 +5,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/go-pkgz/lgr"
|
log "github.com/go-pkgz/lgr"
|
||||||
@ -33,22 +32,24 @@ func (h *Http) healthHandler(w http.ResponseWriter, _ *http.Request) {
|
|||||||
// runs pings in parallel
|
// runs pings in parallel
|
||||||
check := func(mappers []discovery.URLMapper) (ok bool, valid int, total int, errs []string) {
|
check := func(mappers []discovery.URLMapper) (ok bool, valid int, total int, errs []string) {
|
||||||
outCh := make(chan error, concurrent)
|
outCh := make(chan error, concurrent)
|
||||||
var pinged int32
|
pinged := 0
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, m := range mappers {
|
for _, m := range mappers {
|
||||||
if m.PingURL == "" {
|
if m.PingURL == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
sema <- struct{}{}
|
sema <- struct{}{}
|
||||||
|
pinged++
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|
||||||
go func(m discovery.URLMapper) {
|
go func(m discovery.URLMapper) {
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
<-sema
|
<-sema
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
atomic.AddInt32(&pinged, 1)
|
client := http.Client{Timeout: 500 * time.Millisecond}
|
||||||
client := http.Client{Timeout: 100 * time.Millisecond}
|
|
||||||
resp, err := client.Get(m.PingURL)
|
resp, err := client.Get(m.PingURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errMsg := strings.Replace(err.Error(), "\"", "", -1)
|
errMsg := strings.Replace(err.Error(), "\"", "", -1)
|
||||||
@ -72,7 +73,7 @@ func (h *Http) healthHandler(w http.ResponseWriter, _ *http.Request) {
|
|||||||
for e := range outCh {
|
for e := range outCh {
|
||||||
errs = append(errs, e.Error())
|
errs = append(errs, e.Error())
|
||||||
}
|
}
|
||||||
return len(errs) == 0, int(atomic.LoadInt32(&pinged)) - len(errs), len(mappers), errs
|
return len(errs) == 0, pinged - len(errs), len(mappers), errs
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
|
Reference in New Issue
Block a user