node/pkg/p2p: add metric for guardian network heights
Change-Id: Ie09d203d316a448dba5d4ac9269113467e2da78e
This commit is contained in:
parent
61a90136ca
commit
73b0fce440
|
@ -0,0 +1,31 @@
|
||||||
|
package p2p
|
||||||
|
|
||||||
|
import (
|
||||||
|
gossipv1 "github.com/certusone/wormhole/bridge/pkg/proto/gossip/v1"
|
||||||
|
"github.com/certusone/wormhole/bridge/pkg/vaa"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
wormholeNetworkNodeHeight = promauto.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Name: "wormhole_network_node_height",
|
||||||
|
Help: "Network height of the given guardian node per network",
|
||||||
|
}, []string{"guardian_addr", "node_id", "node_name", "network"})
|
||||||
|
)
|
||||||
|
|
||||||
|
func collectNodeMetrics(addr common.Address, peerId peer.ID, hb *gossipv1.Heartbeat) {
|
||||||
|
for _, n := range hb.Networks {
|
||||||
|
if n == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
chain := vaa.ChainID(n.Id)
|
||||||
|
|
||||||
|
wormholeNetworkNodeHeight.WithLabelValues(
|
||||||
|
addr.Hex(), peerId.Pretty(), hb.NodeName, chain.String()).Set(float64(n.Height))
|
||||||
|
}
|
||||||
|
}
|
|
@ -209,6 +209,7 @@ func Run(obsvC chan *gossipv1.SignedObservation, sendC chan []byte, rawHeartbeat
|
||||||
if err := gst.SetHeartbeat(ourAddr, h.ID(), heartbeat); err != nil {
|
if err := gst.SetHeartbeat(ourAddr, h.ID(), heartbeat); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
collectNodeMetrics(ourAddr, h.ID(), heartbeat)
|
||||||
|
|
||||||
b, err := proto.Marshal(heartbeat)
|
b, err := proto.Marshal(heartbeat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -372,5 +373,7 @@ func processSignedHeartbeat(from peer.ID, s *gossipv1.SignedHeartbeat, gs *bridg
|
||||||
return nil, fmt.Errorf("failed to store in guardian set state: %w", err)
|
return nil, fmt.Errorf("failed to store in guardian set state: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
collectNodeMetrics(signerAddr, from, &h)
|
||||||
|
|
||||||
return &h, nil
|
return &h, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue