@@ -15,14 +15,11 @@ import (
1515 log "github.com/ChainSafe/log15"
1616)
1717
18- // After this duration with no changes a chain will return an error
19- const BlockTimeout = 20
20-
2118type httpMetricServer struct {
22- port int
23- timeDelay int
24- chains []core.Chain
25- stats []ChainInfo
19+ port int
20+ blockTimeout int // After this duration (seconds) with no change in block height a chain will be considered unhealthy
21+ chains []core.Chain
22+ stats []ChainInfo
2623}
2724
2825type httpResponse struct {
@@ -36,12 +33,12 @@ type ChainInfo struct {
3633 LastUpdated time.Time `json:"lastUpdated"`
3734}
3835
39- func NewHealthServer (port int , chains []core.Chain ) * httpMetricServer {
36+ func NewHealthServer (port int , chains []core.Chain , blockTimeout int ) * httpMetricServer {
4037 return & httpMetricServer {
41- port : port ,
42- chains : chains ,
43- timeDelay : BlockTimeout ,
44- stats : make ([]ChainInfo , len (chains )),
38+ port : port ,
39+ chains : chains ,
40+ blockTimeout : blockTimeout ,
41+ stats : make ([]ChainInfo , len (chains )),
4542 }
4643}
4744
@@ -69,7 +66,7 @@ func (s httpMetricServer) HealthStatus(w http.ResponseWriter, _ *http.Request) {
6966 if current .Height .Cmp (prev .Height ) == 1 {
7067 s .stats [i ].LastUpdated = current .LastUpdated
7168 s .stats [i ].Height = current .Height
72- } else if int (timeDiff .Seconds ()) >= s .timeDelay { // Error if we exceeded the time limit
69+ } else if int (timeDiff .Seconds ()) >= s .blockTimeout { // Error if we exceeded the time limit
7370 response := & httpResponse {
7471 Chains : []ChainInfo {},
7572 Error : fmt .Sprintf ("chain %d height hasn't changed for %f seconds. Current Height: %s" , prev .ChainId , timeDiff .Seconds (), current .Height ),
0 commit comments