From e4b0a97cc5dccfdccc4ad9214de25019b85bbc47 Mon Sep 17 00:00:00 2001 From: Adam Babik Date: Wed, 19 Feb 2020 15:36:16 +0100 Subject: [PATCH] add bridge metrics to Whisper and Waku (#1864) --- api/geth_backend.go | 2 +- node/get_status_node.go | 3 +++ waku/metrics.go | 16 ++++++++++++++++ waku/waku.go | 4 ++++ whisper/metrics.go | 16 ++++++++++++++++ whisper/whisper.go | 4 ++++ 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/api/geth_backend.go b/api/geth_backend.go index 3b273fda6..c987f4da3 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -935,7 +935,7 @@ func (b *GethStatusBackend) injectAccountIntoServices() error { return err } - if err := st.InitProtocol(identity, b.appDB); err != nil { + if err := st.InitProtocol(identity, b.appDB, logutils.ZapLogger()); err != nil { return err } } diff --git a/node/get_status_node.go b/node/get_status_node.go index 42a77cf98..42388f4ca 100644 --- a/node/get_status_node.go +++ b/node/get_status_node.go @@ -226,6 +226,7 @@ func (n *StatusNode) setupRPCClient() (err error) { func (n *StatusNode) setupBridge() error { if !n.config.BridgeConfig.Enabled { + log.Info("a Whisper-Waku bridge is disabled") return nil } var shh *whisper.Whisper @@ -240,6 +241,8 @@ func (n *StatusNode) setupBridge() error { n.bridge = bridge.New(shh, wak, logutils.ZapLogger()) n.bridge.Start() + log.Info("setup a Whisper-Waku bridge successfully") + return nil } diff --git a/waku/metrics.go b/waku/metrics.go index f1f08e131..994b5983b 100644 --- a/waku/metrics.go +++ b/waku/metrics.go @@ -57,6 +57,19 @@ var ( Name: "waku_rate_limits_exceeded_total", Help: "Number of times the Waku rate limits were exceeded", }, []string{"type"}) + // bridging + bridgeSent = prom.NewCounter(prom.CounterOpts{ + Name: "waku_bridge_sent_total", + Help: "Number of envelopes bridged from Waku", + }) + bridgeReceivedSucceed = prom.NewCounter(prom.CounterOpts{ + Name: "waku_bridge_received_success_total", + Help: "Number of envelopes bridged to Waku and successfully added", + }) + bridgeReceivedFailed = prom.NewCounter(prom.CounterOpts{ + Name: "waku_bridge_received_failure_total", + Help: "Number of envelopes bridged to Waku and failed to be added", + }) ) func init() { @@ -67,4 +80,7 @@ func init() { prom.MustRegister(envelopesSizeMeter) prom.MustRegister(rateLimitsProcessed) prom.MustRegister(rateLimitsExceeded) + prom.MustRegister(bridgeSent) + prom.MustRegister(bridgeReceivedSucceed) + prom.MustRegister(bridgeReceivedFailed) } diff --git a/waku/waku.go b/waku/waku.go index f2ddc435c..51d172874 100644 --- a/waku/waku.go +++ b/waku/waku.go @@ -375,12 +375,14 @@ func (w *Waku) readBridgeLoop() { case env := <-out: _, err := w.addAndBridge(env, false, true) if err != nil { + bridgeReceivedFailed.Inc() w.logger.Warn( "failed to add a bridged envelope", zap.Binary("ID", env.Hash().Bytes()), zap.Error(err), ) } else { + bridgeReceivedSucceed.Inc() w.logger.Debug("bridged envelope successfully", zap.Binary("ID", env.Hash().Bytes())) w.envelopeFeed.Send(EnvelopeEvent{ Event: EventEnvelopeReceived, @@ -1309,8 +1311,10 @@ func (w *Waku) addAndBridge(envelope *Envelope, isP2P bool, bridged bool) (bool, // In particular, if a node is a lightweight node, // it should not bridge any envelopes. if !isP2P && !bridged && w.bridge != nil { + log.Debug("bridging envelope from Waku", "hash", envelope.Hash().Hex()) _, in := w.bridge.Pipe() in <- envelope + bridgeSent.Inc() } } return true, nil diff --git a/whisper/metrics.go b/whisper/metrics.go index 09b3af10f..0f0b80ba3 100644 --- a/whisper/metrics.go +++ b/whisper/metrics.go @@ -39,6 +39,19 @@ var ( Name: "whisper_rate_limits_exceeded_total", Help: "Number of times the Waku rate limits were exceeded", }, []string{"type"}) + // bridging + bridgeSent = prom.NewCounter(prom.CounterOpts{ + Name: "whisper_bridge_sent_total", + Help: "Number of envelopes bridged from Whisper", + }) + bridgeReceivedSucceed = prom.NewCounter(prom.CounterOpts{ + Name: "whisper_bridge_received_success_total", + Help: "Number of envelopes bridged to Whisper and successfully added", + }) + bridgeReceivedFailed = prom.NewCounter(prom.CounterOpts{ + Name: "whisper_bridge_received_failure_total", + Help: "Number of envelopes bridged to Whisper and failed to be added", + }) ) func init() { @@ -49,4 +62,7 @@ func init() { prom.MustRegister(envelopesSizeMeter) prom.MustRegister(rateLimitsProcessed) prom.MustRegister(rateLimitsExceeded) + prom.MustRegister(bridgeSent) + prom.MustRegister(bridgeReceivedSucceed) + prom.MustRegister(bridgeReceivedFailed) } diff --git a/whisper/whisper.go b/whisper/whisper.go index f0c306fc6..22944e09d 100644 --- a/whisper/whisper.go +++ b/whisper/whisper.go @@ -301,12 +301,14 @@ func (whisper *Whisper) readBridgeLoop() { case env := <-out: _, err := whisper.addAndBridge(env, false, true) if err != nil { + bridgeReceivedFailed.Inc() log.Warn( "failed to add a bridged envelope", "ID", env.Hash().Bytes(), "err", err, ) } else { + bridgeReceivedSucceed.Inc() log.Debug( "bridged envelope successfully", "ID", env.Hash().Bytes(), @@ -1375,8 +1377,10 @@ func (whisper *Whisper) addAndBridge(envelope *Envelope, isP2P bool, bridged boo // In particular, if a node is a lightweight node, // it should not bridge any envelopes. if !isP2P && !bridged && whisper.bridge != nil { + log.Debug("bridging envelope from Whisper", "hash", envelope.Hash().Hex()) _, in := whisper.bridge.Pipe() in <- envelope + bridgeSent.Inc() } } return true, nil