Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit b698aff

Browse files
author
David Ansermino
authored
Adds blockTimeout as a configurable param (#12)
1 parent 985a90f commit b698aff

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

metrics/health/health.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
2118
type 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

2825
type 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),

metrics/types/prometheus.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
)
1111

1212
type ChainMetrics struct {
13-
BlocksProcessed prometheus.Counter
13+
BlocksProcessed prometheus.Counter
1414
LatestProcessedBlock prometheus.Gauge
15-
LatestKnownBlock prometheus.Gauge
16-
VotesSubmitted prometheus.Counter
15+
LatestKnownBlock prometheus.Gauge
16+
VotesSubmitted prometheus.Counter
1717
}
1818

1919
func NewChainMetrics(chain string) *ChainMetrics {

0 commit comments

Comments
 (0)