Skip to content

Commit

Permalink
Merge branch 'dev-cere' into master-cere
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Navoichyk committed Jun 9, 2022
2 parents 80625dc + 53737a6 commit 1a2abde
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions metrics/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/big"
"net/http"
"path"
"sync"
"time"

"github.com/Cerebellum-Network/chainbridge-utils/core"
Expand All @@ -17,6 +18,7 @@ import (
)

type httpMetricServer struct {
lock *sync.RWMutex
port int
blockTimeout int // After this duration (seconds) with no change in block height a chain will be considered unhealthy
chains map[string]core.Chain
Expand All @@ -37,6 +39,7 @@ func NewHealthServer(port int, chains []core.Chain, blockTimeout int) *httpMetri
}

return &httpMetricServer{
lock: &sync.RWMutex{},
port: port,
chains: chainMap,
blockTimeout: blockTimeout,
Expand All @@ -48,6 +51,8 @@ func NewHealthServer(port int, chains []core.Chain, blockTimeout int) *httpMetri
// The last segment of the URL is used to identify the chain (eg. "health/goerli" will return "goerli").
func (s httpMetricServer) HealthStatus(w http.ResponseWriter, r *http.Request) {
// Get last segment of URL
s.lock.Lock()
defer s.lock.Unlock()
chainName := path.Base(r.URL.String())
chain, ok := s.chains[chainName]
if !ok {
Expand Down

0 comments on commit 1a2abde

Please sign in to comment.