From 2a521ab3338c4720bec06e5e85ab6f46419674a6 Mon Sep 17 00:00:00 2001 From: xebb Date: Sun, 11 Oct 2020 11:51:06 +0200 Subject: [PATCH 1/3] Adding check for HTTPStatusCode to support varnish --- src/eosapi/functions.go | 6 ++++++ src/eosapi/types.go | 2 ++ src/server.go | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/eosapi/functions.go b/src/eosapi/functions.go index 910b23f..3f93827 100644 --- a/src/eosapi/functions.go +++ b/src/eosapi/functions.go @@ -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) } diff --git a/src/eosapi/types.go b/src/eosapi/types.go index 5b538f7..393cb48 100644 --- a/src/eosapi/types.go +++ b/src/eosapi/types.go @@ -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 } diff --git a/src/server.go b/src/server.go index c46c799..507034e 100644 --- a/src/server.go +++ b/src/server.go @@ -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 From 69253eaab3a75f2e6a296374f445e48d107391d3 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 2 Nov 2020 10:43:07 +0100 Subject: [PATCH 2/3] Minor indentation fixes. --- src/eosapi/functions.go | 4 ++-- src/server.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/eosapi/functions.go b/src/eosapi/functions.go index 3f93827..02558dc 100644 --- a/src/eosapi/functions.go +++ b/src/eosapi/functions.go @@ -74,8 +74,8 @@ func GetHealth(params ReqParams) (Health, error) { resp := r.Response() body, _ := ioutil.ReadAll(resp.Body) - // Set HTTPStatusCode - health.HTTPStatusCode = resp.StatusCode + // Set HTTPStatusCode + health.HTTPStatusCode = resp.StatusCode // Parse json err = json.Unmarshal(body, &health) diff --git a/src/server.go b/src/server.go index 507034e..b23b7d7 100644 --- a/src/server.go +++ b/src/server.go @@ -56,11 +56,11 @@ func check_api_v2(p eosapi.ReqParams, offset int64) (haproxy.HealthCheckStatus, return haproxy.HealthCheckFailed, msg } - // Check HTTP Status Code - if health.HTTPStatusCode > 299 { + // 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 From d6cc9ac185ce46b7e81cf40c264bb8e49081f5e6 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 4 Nov 2020 13:59:23 +0100 Subject: [PATCH 3/3] Version 0.3.5 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2f2dee8..0febdeb 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ deps: info-file : echo PACKAGE_NAME=\"$(PROGRAM_NAME)\" "\n"\ PACKAGE_DESCRIPTION=\"HAproxy healthcheck program for EOSIO API.\" "\n"\ - PACKAGE_VERSION=\"0.3.4\" "\n"\ + PACKAGE_VERSION=\"0.3.5\" "\n"\ PACKAGE_PREFIX=\"$(PREFIX:/%=%)\" "\n"\ PACKAGE_PROGRAM=\"build/$(PROGRAM_NAME)\" > scripts/info