@@ -13,6 +13,7 @@ import (
1313 "github.com/pkg/errors"
1414 "go.uber.org/zap"
1515
16+ "github.com/wavesplatform/gowaves/pkg/metrics"
1617 "github.com/wavesplatform/gowaves/pkg/node/fsm"
1718 "github.com/wavesplatform/gowaves/pkg/node/fsm/tasks"
1819 "github.com/wavesplatform/gowaves/pkg/node/messages"
@@ -155,8 +156,10 @@ func (a *Node) Run(
155156 ctx context.Context , p peer.Parent , internalMessageCh <- chan messages.InternalMessage ,
156157 networkMsgCh <- chan network.InfoMessage , syncPeer * network.SyncPeer ,
157158) {
159+ protoMessagesChan := chanLenProvider [peer.ProtoMessage ](p .MessageCh )
160+
158161 go a .runOutgoingConnections (ctx )
159- go a .runInternalMetrics (ctx , p . MessageCh )
162+ go a .runInternalMetrics (ctx , protoMessagesChan )
160163 go a .runIncomingConnections (ctx )
161164
162165 tasksCh := make (chan tasks.AsyncTask , 10 )
@@ -228,20 +231,25 @@ func (a *Node) runIncomingConnections(ctx context.Context) {
228231 }
229232}
230233
231- func (a * Node ) runInternalMetrics (ctx context.Context , ch chan peer.ProtoMessage ) {
234+ type lenProvider interface {
235+ Len () int
236+ }
237+
238+ type chanLenProvider [T any ] <- chan T
239+
240+ func (c chanLenProvider [T ]) Len () int { return len (c ) }
241+
242+ func (a * Node ) runInternalMetrics (ctx context.Context , protoMessagesChan lenProvider ) {
243+ ticker := time .NewTicker (metricInternalChannelSizeUpdateInterval )
244+ defer ticker .Stop ()
232245 for {
233- timer := time .NewTimer (metricInternalChannelSizeUpdateInterval )
234246 select {
235247 case <- ctx .Done ():
236- if ! timer .Stop () {
237- select {
238- case <- timer .C :
239- default :
240- }
241- }
242248 return
243- case <- timer .C :
244- metricInternalChannelSize .Set (float64 (len (ch )))
249+ case <- ticker .C :
250+ l := protoMessagesChan .Len ()
251+ metrics .FSMChannelLength (l )
252+ metricInternalChannelSize .Set (float64 (l ))
245253 }
246254 }
247255}
0 commit comments