1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-api-healthcheck synced 2026-06-19 05:10:02 +02:00

Adding check for HTTPStatusCode to support varnish

This commit is contained in:
xebb 2020-10-11 11:51:06 +02:00
parent d7e643fd73
commit 2a521ab333
3 changed files with 20 additions and 0 deletions

View file

@ -56,6 +56,9 @@ func GetInfo(params ReqParams) (Info, error) {
resp := r.Response()
body, _ := ioutil.ReadAll(resp.Body)
// Set HTTPStatusCode
info.HTTPStatusCode = resp.StatusCode
// Parse json
err = json.Unmarshal(body, &info)
}
@ -71,6 +74,9 @@ func GetHealth(params ReqParams) (Health, error) {
resp := r.Response()
body, _ := ioutil.ReadAll(resp.Body)
// Set HTTPStatusCode
health.HTTPStatusCode = resp.StatusCode
// Parse json
err = json.Unmarshal(body, &health)
}

View file

@ -8,6 +8,7 @@ type Info struct {
ServerVersion string `json:"server_version"`
HeadBlockNum int64 `json:"head_block_num"`
HeadBlockTime time.Time `json:"head_block_time"`
HTTPStatusCode int
}
// Service struct from /v2/health
@ -22,4 +23,5 @@ type Service struct {
type Health struct {
VersionHash string `json:"version_hash"`
Health []Service `json:"health"`
HTTPStatusCode int
}

View file

@ -24,6 +24,12 @@ func check_api(p eosapi.ReqParams, block_time float64) (haproxy.HealthCheckStatu
return haproxy.HealthCheckFailed, msg
}
// Check HTTP Status Code
if info.HTTPStatusCode > 299 {
return haproxy.HealthCheckDown,
fmt.Sprintf("Taking offline because %v was received from backend", info.HTTPStatusCode)
}
// Validate head block.
now := time.Now().In(time.UTC)
diff := now.Sub(info.HeadBlockTime).Seconds()
@ -50,6 +56,12 @@ func check_api_v2(p eosapi.ReqParams, offset int64) (haproxy.HealthCheckStatus,
return haproxy.HealthCheckFailed, msg
}
// Check HTTP Status Code
if health.HTTPStatusCode > 299 {
return haproxy.HealthCheckDown,
fmt.Sprintf("Taking offline because %v was received from backend", health.HTTPStatusCode)
}
// Fetch elasticsearch and nodeos block numbers from json.
var es_block int64 = 0
var node_block int64 = 0