mirror of
https://github.com/libp2p/go-libp2p-resource-manager.git
synced 2025-03-24 08:10:55 +08:00
simplify metrics method names
This commit is contained in:
parent
6d91069894
commit
019fe3da54
56
metrics.go
56
metrics.go
@ -8,20 +8,20 @@ import (
|
||||
|
||||
// MetricsReporter is an interface for collecting metrics from resource manager actions
|
||||
type MetricsReporter interface {
|
||||
// BlockOpenConn is invoked when opening a connection is blocked
|
||||
BlockOpenConn(dir network.Direction, usefd bool)
|
||||
// BlockOpenStream is invoked when opening a stream is blocked
|
||||
BlockOpenStream(p peer.ID, dir network.Direction)
|
||||
// BlockSetPeer is invoked when attaching ac onnection to a peer is blocked
|
||||
BlockSetPeer(p peer.ID)
|
||||
// BlockSetProtocol is invoked when setting the protocol for a stream is blocked
|
||||
BlockSetProtocol(proto protocol.ID)
|
||||
// BlockedSetProtocolPeer is invoekd when setting the protocol for a stream is blocked at the per protocol peer scope
|
||||
BlockSetProtocolPeer(proto protocol.ID, p peer.ID)
|
||||
// BlockSetPService is invoked when setting the protocol for a stream is blocked
|
||||
BlockSetService(svc string)
|
||||
// BlockedSetServicePeer is invoekd when setting the service for a stream is blocked at the per service peer scope
|
||||
BlockSetServicePeer(svc string, p peer.ID)
|
||||
// BlockConn is invoked when opening a connection is blocked
|
||||
BlockConn(dir network.Direction, usefd bool)
|
||||
// BlockStream is invoked when opening a stream is blocked
|
||||
BlockStream(p peer.ID, dir network.Direction)
|
||||
// BlockPeer is invoked when attaching ac onnection to a peer is blocked
|
||||
BlockPeer(p peer.ID)
|
||||
// BlockProtocol is invoked when setting the protocol for a stream is blocked
|
||||
BlockProtocol(proto protocol.ID)
|
||||
// BlockedProtocolPeer is invoekd when setting the protocol for a stream is blocked at the per protocol peer scope
|
||||
BlockProtocolPeer(proto protocol.ID, p peer.ID)
|
||||
// BlockPService is invoked when setting the protocol for a stream is blocked
|
||||
BlockService(svc string)
|
||||
// BlockedServicePeer is invoekd when setting the service for a stream is blocked at the per service peer scope
|
||||
BlockServicePeer(svc string, p peer.ID)
|
||||
}
|
||||
|
||||
type metrics struct {
|
||||
@ -36,58 +36,58 @@ func WithMetrics(reporter MetricsReporter) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *metrics) BlockOpenConn(dir network.Direction, usefd bool) {
|
||||
func (m *metrics) BlockConn(dir network.Direction, usefd bool) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.reporter.BlockOpenConn(dir, usefd)
|
||||
m.reporter.BlockConn(dir, usefd)
|
||||
}
|
||||
|
||||
func (m *metrics) BlockOpenStream(p peer.ID, dir network.Direction) {
|
||||
func (m *metrics) BlockStream(p peer.ID, dir network.Direction) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.reporter.BlockOpenStream(p, dir)
|
||||
m.reporter.BlockStream(p, dir)
|
||||
}
|
||||
|
||||
func (m *metrics) BlockSetPeer(p peer.ID) {
|
||||
func (m *metrics) BlockPeer(p peer.ID) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.reporter.BlockSetPeer(p)
|
||||
m.reporter.BlockPeer(p)
|
||||
}
|
||||
|
||||
func (m *metrics) BlockSetProtocol(proto protocol.ID) {
|
||||
func (m *metrics) BlockProtocol(proto protocol.ID) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.reporter.BlockSetProtocol(proto)
|
||||
m.reporter.BlockProtocol(proto)
|
||||
}
|
||||
|
||||
func (m *metrics) BlockSetProtocolPeer(proto protocol.ID, p peer.ID) {
|
||||
func (m *metrics) BlockProtocolPeer(proto protocol.ID, p peer.ID) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.reporter.BlockSetProtocolPeer(proto, p)
|
||||
m.reporter.BlockProtocolPeer(proto, p)
|
||||
}
|
||||
|
||||
func (m *metrics) BlockSetService(svc string) {
|
||||
func (m *metrics) BlockService(svc string) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.reporter.BlockSetService(svc)
|
||||
m.reporter.BlockService(svc)
|
||||
}
|
||||
|
||||
func (m *metrics) BlockSetServicePeer(svc string, p peer.ID) {
|
||||
func (m *metrics) BlockServicePeer(svc string, p peer.ID) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.reporter.BlockSetServicePeer(svc, p)
|
||||
m.reporter.BlockServicePeer(svc, p)
|
||||
}
|
||||
|
14
rcmgr.go
14
rcmgr.go
@ -260,7 +260,7 @@ func (r *resourceManager) OpenConnection(dir network.Direction, usefd bool) (net
|
||||
|
||||
if err := conn.AddConn(dir, usefd); err != nil {
|
||||
conn.Done()
|
||||
r.metrics.BlockOpenConn(dir, usefd)
|
||||
r.metrics.BlockConn(dir, usefd)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ func (r *resourceManager) OpenStream(p peer.ID, dir network.Direction) (network.
|
||||
err := stream.AddStream(dir)
|
||||
if err != nil {
|
||||
stream.Done()
|
||||
r.metrics.BlockOpenStream(p, dir)
|
||||
r.metrics.BlockStream(p, dir)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -500,7 +500,7 @@ func (s *connectionScope) SetPeer(p peer.ID) error {
|
||||
if err := s.peer.ReserveForChild(stat); err != nil {
|
||||
s.peer.DecRef()
|
||||
s.peer = nil
|
||||
s.rcmgr.metrics.BlockSetPeer(p)
|
||||
s.rcmgr.metrics.BlockPeer(p)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -544,7 +544,7 @@ func (s *streamScope) SetProtocol(proto protocol.ID) error {
|
||||
if err := s.proto.ReserveForChild(stat); err != nil {
|
||||
s.proto.DecRef()
|
||||
s.proto = nil
|
||||
s.rcmgr.metrics.BlockSetProtocol(proto)
|
||||
s.rcmgr.metrics.BlockProtocol(proto)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -555,7 +555,7 @@ func (s *streamScope) SetProtocol(proto protocol.ID) error {
|
||||
s.proto = nil
|
||||
s.peerProtoScope.DecRef()
|
||||
s.peerProtoScope = nil
|
||||
s.rcmgr.metrics.BlockSetProtocolPeer(proto, s.peer.peer)
|
||||
s.rcmgr.metrics.BlockProtocolPeer(proto, s.peer.peer)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -604,7 +604,7 @@ func (s *streamScope) SetService(svc string) error {
|
||||
if err := s.svc.ReserveForChild(stat); err != nil {
|
||||
s.svc.DecRef()
|
||||
s.svc = nil
|
||||
s.rcmgr.metrics.BlockSetService(svc)
|
||||
s.rcmgr.metrics.BlockService(svc)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -616,7 +616,7 @@ func (s *streamScope) SetService(svc string) error {
|
||||
s.svc = nil
|
||||
s.peerSvcScope.DecRef()
|
||||
s.peerSvcScope = nil
|
||||
s.rcmgr.metrics.BlockSetServicePeer(svc, s.peer.peer)
|
||||
s.rcmgr.metrics.BlockServicePeer(svc, s.peer.peer)
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user