Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
[#12] Use 80 port for health check
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
  • Loading branch information
KirillovDenis authored and alexvanin committed Oct 26, 2021
1 parent 383ac38 commit fdc6c37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 8 additions & 0 deletions plugin/geodns/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func (r *ResponseFilter) WriteMsg(res *dns.Msg) error {
return r.ResponseWriter.WriteMsg(res)
}

if len(res.Answer) == 0 {
log.Debugf("answer is empty, nothing to do")
return r.ResponseWriter.WriteMsg(res)
}

clientInf := r.filter.db.IPInfo(r.client)
if clientInf.IsEmpty() {
log.Warningf(formErrMessage(r.client))
Expand All @@ -66,6 +71,9 @@ func (r *ResponseFilter) WriteMsg(res *dns.Msg) error {
}

healthy := r.filterHealthy(res.Answer)
if len(healthy) == 0 {
log.Warning("no healthy answer servers")
}
distances := make([]serverInfo, len(healthy))

for i, rec := range healthy {
Expand Down
10 changes: 6 additions & 4 deletions plugin/geodns/health.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package geodns

import (
"net"
"net/http"
"sync"
"time"
Expand All @@ -21,8 +22,8 @@ func newHealthChecker() *checker {
client: &http.Client{
Timeout: 2 * time.Second,
},
schema: "https://",
port: ":443",
schema: "http://",
port: "80",
}
}

Expand Down Expand Up @@ -54,11 +55,12 @@ func (c *checker) check(endpoints []string) []bool {
}

func (c *checker) checkOne(endpoint string) bool {
response, err := c.client.Get(c.schema + endpoint + c.port)
response, err := c.client.Get(c.schema + net.JoinHostPort(endpoint, c.port))
if err != nil {
log.Debugf(err.Error())
return false
}
_ = response.Body.Close()

return response.StatusCode == http.StatusOK
return response.StatusCode < http.StatusInternalServerError
}

0 comments on commit fdc6c37

Please sign in to comment.