From 654bebdb936eb1426deb6239776d1c60fbf70022 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Sat, 16 Oct 2021 17:50:49 -0400 Subject: [PATCH] fix: peer metrics --- go.mod | 5 ++-- go.sum | 14 +++------- waku/metrics/http.go | 11 ++++---- waku/node.go | 2 -- waku/v2/metrics/metrics.go | 36 +++++++++++++++++--------- waku/v2/node/connectedness.go | 9 ++++++- waku/v2/node/wakunode2.go | 10 +++++-- waku/v2/protocol/filter/waku_filter.go | 5 ++-- 8 files changed, 54 insertions(+), 38 deletions(-) diff --git a/go.mod b/go.mod index d33fd6db..11135b65 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.15 replace github.com/ethereum/go-ethereum v1.10.4 => github.com/status-im/go-ethereum v1.10.4-status.2 require ( - contrib.go.opencensus.io/exporter/prometheus v0.3.0 + contrib.go.opencensus.io/exporter/prometheus v0.4.0 github.com/cruxic/go-hmac-drbg v0.0.0-20170206035330-84c46983886d github.com/ethereum/go-ethereum v1.10.4 github.com/gogo/protobuf v1.3.2 @@ -22,8 +22,7 @@ require ( github.com/mattn/go-sqlite3 v1.14.6 github.com/minio/sha256-simd v1.0.0 github.com/multiformats/go-multiaddr v0.4.0 - github.com/prometheus/statsd_exporter v0.21.0 // indirect - github.com/status-im/go-waku-rendezvous v0.0.0-20211005020656-b53661c58574 + github.com/status-im/go-waku-rendezvous v0.0.0-20211016214658-a0d71f947cee github.com/stretchr/testify v1.7.0 github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 go.opencensus.io v0.23.0 diff --git a/go.sum b/go.sum index 0a8ec033..49a0f0c7 100644 --- a/go.sum +++ b/go.sum @@ -36,8 +36,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE= -contrib.go.opencensus.io/exporter/prometheus v0.3.0 h1:08FMdJYpItzsknogU6PiiNo7XQZg/25GjH236+YCwD0= -contrib.go.opencensus.io/exporter/prometheus v0.3.0/go.mod h1:rpCPVQKhiyH8oomWgm34ZmgIdZa8OVYO5WAIygPbBBE= +contrib.go.opencensus.io/exporter/prometheus v0.4.0 h1:0QfIkj9z/iVZgK31D9H9ohjjIDApI2GOPScCKwxedbs= +contrib.go.opencensus.io/exporter/prometheus v0.4.0/go.mod h1:o7cosnyfuPVK0tB8q0QmaQNhGnptITnPQB+z1+qeFB0= dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3/go.mod h1:Yl+fi1br7+Rr3LqpNJf1/uxUdtRUV+Tnj0o93V2B9MU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBrvjyP0v+ecvNYvCpyZgu5/xkfAUhi6wJj28eUfSU= @@ -483,7 +483,6 @@ github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlT github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= @@ -941,7 +940,6 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= -github.com/prometheus/client_golang v1.6.0/go.mod h1:ZLOG9ck3JLRdB5MgO8f+lLTe83AXG6ro35rLTxvnIl4= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.9.0/go.mod h1:FqZLKOZnGdFAhOK4nqGHa7D66IdsO+O441Eve7ptJDU= github.com/prometheus/client_golang v1.10.0/go.mod h1:WJM3cc3yu7XKBKa/I8WeZm+V3eltZnBwfENSU7mdogU= @@ -960,7 +958,6 @@ github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8 github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= -github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= github.com/prometheus/common v0.18.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= @@ -973,13 +970,11 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= -github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/statsd_exporter v0.20.0/go.mod h1:YL3FWCG8JBBtaUSxAg4Gz2ZYu22bS84XM89ZQXXTWmQ= github.com/prometheus/statsd_exporter v0.21.0 h1:hA05Q5RFeIjgwKIYEdFd59xu5Wwaznf33yKI+pyX6T8= github.com/prometheus/statsd_exporter v0.21.0/go.mod h1:rbT83sZq2V+p73lHhPZfMc3MLCHmSHelCh9hSGYNLTQ= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= @@ -1049,8 +1044,8 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/src-d/envconfig v1.0.0/go.mod h1:Q9YQZ7BKITldTBnoxsE5gOeB5y66RyPXeue/R4aaNBc= github.com/status-im/go-ethereum v1.10.4-status.2 h1:uvcD2U7skYqPQviARFb4w3wZyFSYLs/pfVrJaRSDcCA= github.com/status-im/go-ethereum v1.10.4-status.2/go.mod h1:GvIhpdCOgMHI6i5xVPEZOrv/qSMeOFHbZh77AoyZUoE= -github.com/status-im/go-waku-rendezvous v0.0.0-20211005020656-b53661c58574 h1:v2gpjWKyI+vZZugjjhPDqIhg6uNrGLusHh3ilvbv8/Y= -github.com/status-im/go-waku-rendezvous v0.0.0-20211005020656-b53661c58574/go.mod h1:Fa1uJjMz9MpfZc2tC5xdN9q90xg1VphSnevxWiBbFO0= +github.com/status-im/go-waku-rendezvous v0.0.0-20211016214658-a0d71f947cee h1:IczLt9Rd1QVFd7Llt3Eoresj7betaoIgAbL65YUBVPQ= +github.com/status-im/go-waku-rendezvous v0.0.0-20211016214658-a0d71f947cee/go.mod h1:Fa1uJjMz9MpfZc2tC5xdN9q90xg1VphSnevxWiBbFO0= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= github.com/status-im/status-go/extkeys v1.1.2/go.mod h1:hCmFzb2jiiVF2voZKYbzuhOQiHHCmyLJsZJXrFFg7BY= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= @@ -1334,7 +1329,6 @@ golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/waku/metrics/http.go b/waku/metrics/http.go index 3393f0cf..ae376931 100644 --- a/waku/metrics/http.go +++ b/waku/metrics/http.go @@ -27,9 +27,7 @@ func NewMetricsServer(address string, port int) *Server { EnableMemory: true, }) - pe, err := prometheus.NewExporter(prometheus.Options{ - Namespace: "wakunode", - }) + pe, err := prometheus.NewExporter(prometheus.Options{}) if err != nil { log.Fatalf("Failed to create the Prometheus stats exporter: %v", err) } @@ -49,10 +47,12 @@ func NewMetricsServer(address string, port int) *Server { // Register the views if err := view.Register( - metrics.MessageTypeView, + metrics.MessageView, metrics.FilterSubscriptionsView, metrics.StoreErrorTypesView, - metrics.StoreMessageTypeView, + metrics.StoreMessagesView, + metrics.PeersView, + metrics.DialsView, ); err != nil { log.Fatalf("Failed to register views: %v", err) } @@ -63,6 +63,7 @@ func NewMetricsServer(address string, port int) *Server { Handler: h, }, } + return &p } diff --git a/waku/node.go b/waku/node.go index 9f46dc55..d4e2d285 100644 --- a/waku/node.go +++ b/waku/node.go @@ -188,8 +188,6 @@ func Execute(options Options) { for _, n := range options.StaticNodes { go func(node string) { - ctx, cancel := context.WithTimeout(ctx, time.Duration(3)*time.Second) - defer cancel() err = wakuNode.DialPeer(ctx, node) if err != nil { log.Error("error dialing peer ", err) diff --git a/waku/v2/metrics/metrics.go b/waku/v2/metrics/metrics.go index e9c1868f..76ab699a 100644 --- a/waku/v2/metrics/metrics.go +++ b/waku/v2/metrics/metrics.go @@ -7,7 +7,9 @@ import ( ) var ( - Messages = stats.Int64("messages", "Number of messages received", stats.UnitDimensionless) + Messages = stats.Int64("node_messages", "Number of messages received", stats.UnitDimensionless) + Peers = stats.Int64("peers", "Number of connected peers", stats.UnitDimensionless) + Dials = stats.Int64("dials", "Number of peer dials", stats.UnitDimensionless) StoreMessages = stats.Int64("store_messages", "Number of historical messages", stats.UnitDimensionless) FilterSubscriptions = stats.Int64("filter_subscriptions", "Number of filter subscriptions", stats.UnitDimensionless) Errors = stats.Int64("errors", "Number of errors", stats.UnitDimensionless) @@ -19,28 +21,38 @@ var ( ) var ( - MessageTypeView = &view.View{ - Name: "messages", - Measure: Messages, - Description: "The distribution of the messages received", - Aggregation: view.Count(), - TagKeys: []tag.Key{KeyType}, + PeersView = &view.View{ + Name: "gowaku_connected_peers", + Measure: Peers, + Description: "Number of connected peers", + Aggregation: view.Sum(), } - StoreMessageTypeView = &view.View{ - Name: "store_messages", + DialsView = &view.View{ + Name: "gowaku_peers_dials", + Measure: Dials, + Description: "Number of peer dials", + Aggregation: view.Count(), + } + MessageView = &view.View{ + Name: "gowaku_node_messages", + Measure: Messages, + Description: "The number of the messages received", + Aggregation: view.Count(), + } + StoreMessagesView = &view.View{ + Name: "gowaku_store_messages", Measure: StoreMessages, Description: "The distribution of the store protocol messages", Aggregation: view.LastValue(), - TagKeys: []tag.Key{KeyType}, } FilterSubscriptionsView = &view.View{ - Name: "filter_subscriptions", + Name: "gowaku_filter_subscriptions", Measure: FilterSubscriptions, Description: "The number of content filter subscriptions", Aggregation: view.LastValue(), } StoreErrorTypesView = &view.View{ - Name: "store_errors", + Name: "gowaku_store_errors", Measure: Errors, Description: "The distribution of the store protocol errors", Aggregation: view.Count(), diff --git a/waku/v2/node/connectedness.go b/waku/v2/node/connectedness.go index fbd643d2..4a72f4b3 100644 --- a/waku/v2/node/connectedness.go +++ b/waku/v2/node/connectedness.go @@ -1,16 +1,19 @@ package node import ( + "context" "fmt" "github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" ma "github.com/multiformats/go-multiaddr" + "github.com/status-im/go-waku/waku/v2/metrics" "github.com/status-im/go-waku/waku/v2/protocol/filter" "github.com/status-im/go-waku/waku/v2/protocol/lightpush" "github.com/status-im/go-waku/waku/v2/protocol/relay" "github.com/status-im/go-waku/waku/v2/protocol/store" + "go.opencensus.io/stats" ) // A map of peer IDs to supported protocols @@ -24,13 +27,15 @@ type ConnStatus struct { type ConnectionNotifier struct { h host.Host + ctx context.Context DisconnectChan chan peer.ID quit chan struct{} } -func NewConnectionNotifier(h host.Host) ConnectionNotifier { +func NewConnectionNotifier(ctx context.Context, h host.Host) ConnectionNotifier { return ConnectionNotifier{ h: h, + ctx: ctx, DisconnectChan: make(chan peer.ID, 100), quit: make(chan struct{}), } @@ -47,11 +52,13 @@ func (c ConnectionNotifier) ListenClose(n network.Network, m ma.Multiaddr) { func (c ConnectionNotifier) Connected(n network.Network, cc network.Conn) { // called when a connection opened log.Info(fmt.Sprintf("Peer %s connected", cc.RemotePeer())) + stats.Record(c.ctx, metrics.Peers.M(1)) } func (c ConnectionNotifier) Disconnected(n network.Network, cc network.Conn) { // called when a connection closed log.Info(fmt.Sprintf("Peer %s disconnected", cc.RemotePeer())) + stats.Record(c.ctx, metrics.Peers.M(-1)) c.DisconnectChan <- cc.RemotePeer() } diff --git a/waku/v2/node/wakunode2.go b/waku/v2/node/wakunode2.go index cecfef35..bc7cf9d9 100644 --- a/waku/v2/node/wakunode2.go +++ b/waku/v2/node/wakunode2.go @@ -122,7 +122,7 @@ func New(ctx context.Context, opts ...WakuNodeOption) (*WakuNode, error) { w.connStatusChan = params.connStatusChan } - w.connectionNotif = NewConnectionNotifier(host) + w.connectionNotif = NewConnectionNotifier(ctx, host) w.host.Network().Notify(w.connectionNotif) go w.connectednessListener() @@ -324,8 +324,12 @@ func (w *WakuNode) startStore() { func (w *WakuNode) addPeer(info *peer.AddrInfo, protocolID p2pproto.ID) error { log.Info(fmt.Sprintf("Adding peer %s to peerstore", info.ID.Pretty())) w.host.Peerstore().AddAddrs(info.ID, info.Addrs, peerstore.PermanentAddrTTL) - return w.host.Peerstore().AddProtocols(info.ID, string(protocolID)) + err := w.host.Peerstore().AddProtocols(info.ID, string(protocolID)) + if err != nil { + return err + } + return nil } func (w *WakuNode) AddPeer(address ma.Multiaddr, protocolID p2pproto.ID) (*peer.ID, error) { @@ -637,6 +641,8 @@ func (w *WakuNode) connect(ctx context.Context, info peer.AddrInfo) error { if err != nil { return err } + + stats.Record(ctx, metrics.Dials.M(1)) return nil } diff --git a/waku/v2/protocol/filter/waku_filter.go b/waku/v2/protocol/filter/waku_filter.go index b523e5d2..83c97210 100644 --- a/waku/v2/protocol/filter/waku_filter.go +++ b/waku/v2/protocol/filter/waku_filter.go @@ -93,14 +93,13 @@ func (wf *WakuFilter) onRequest(s network.Stream) { log.Info(fmt.Sprintf("%s: received request from %s", s.Conn().LocalPeer(), s.Conn().RemotePeer())) - stats.Record(wf.ctx, metrics.Messages.M(1)) - if filterRPCRequest.Push != nil && len(filterRPCRequest.Push.Messages) > 0 { // We're on a light node. // This is a message push coming from a full node. + wf.pushHandler(filterRPCRequest.RequestId, *filterRPCRequest.Push) log.Info("filter light node, received a message push. ", len(filterRPCRequest.Push.Messages), " messages") - wf.pushHandler(filterRPCRequest.RequestId, *filterRPCRequest.Push) + stats.Record(wf.ctx, metrics.Messages.M(int64(len(filterRPCRequest.Push.Messages)))) } else if filterRPCRequest.Request != nil { // We're on a full node. // This is a filter request coming from a light node.