Filter out spans

This commit is contained in:
Marco Munizaga 2022-06-29 21:03:22 -07:00
parent e70da09acb
commit 5abae10710
3 changed files with 20 additions and 12 deletions

View File

@ -235,8 +235,8 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
// Not measuring this. I don't think it's useful. // Not measuring this. I don't think it's useful.
break break
} else { } else {
// There shouldn't be anything here. But we keep going so the metrics will tell us if we're wrong (scope="") // This could be a span
log.Debugf("unexpected event in stats: %s", evt.Name) break
} }
if evt.DeltaOut != 0 { if evt.DeltaOut != 0 {

View File

@ -478,11 +478,12 @@ func newStreamScope(dir network.Direction, limit Limit, peer *peerScope, rcmgr *
} }
func IsSystemScope(name string) bool { func IsSystemScope(name string) bool {
return strings.HasPrefix(name, "system") return name == "system"
} }
func IsTransientScope(name string) bool { func IsTransientScope(name string) bool {
return strings.HasPrefix(name, "transient") return strings.HasPrefix(name, "transient")
return name == "transient"
} }
func streamScopeName(streamId int64) string { func streamScopeName(streamId int64) string {
@ -490,7 +491,7 @@ func streamScopeName(streamId int64) string {
} }
func IsStreamScope(name string) bool { func IsStreamScope(name string) bool {
return strings.HasPrefix(name, "stream-") return strings.HasPrefix(name, "stream-") && !IsSpan(name)
} }
func connScopeName(streamId int64) string { func connScopeName(streamId int64) string {
@ -498,7 +499,7 @@ func connScopeName(streamId int64) string {
} }
func IsConnScope(name string) bool { func IsConnScope(name string) bool {
return strings.HasPrefix(name, "conn-") return strings.HasPrefix(name, "conn-") && !IsSpan(name)
} }
func peerScopeName(p peer.ID) string { func peerScopeName(p peer.ID) string {
@ -507,16 +508,16 @@ func peerScopeName(p peer.ID) string {
// ParsePeerScopeName returns "" if name is not a peerScopeName // ParsePeerScopeName returns "" if name is not a peerScopeName
func ParsePeerScopeName(name string) peer.ID { func ParsePeerScopeName(name string) peer.ID {
if !strings.HasPrefix(name, "peer:") { if !strings.HasPrefix(name, "peer:") || IsSpan(name) {
return peer.ID("") return ""
} }
parts := strings.SplitN(name, "peer:", 2) parts := strings.SplitN(name, "peer:", 2)
if len(parts) != 2 { if len(parts) != 2 {
return peer.ID("") return ""
} }
p, err := peer.Decode(parts[1]) p, err := peer.Decode(parts[1])
if err != nil { if err != nil {
return peer.ID("") return ""
} }
return p return p
} }
@ -524,14 +525,14 @@ func ParsePeerScopeName(name string) peer.ID {
// ParseServiceScopeName returns the service name if name is a serviceScopeName. // ParseServiceScopeName returns the service name if name is a serviceScopeName.
// Otherwise returns "" // Otherwise returns ""
func ParseServiceScopeName(name string) string { func ParseServiceScopeName(name string) string {
if strings.HasPrefix(name, "service:") { if strings.HasPrefix(name, "service:") && !IsSpan(name) {
if strings.Contains(name, "peer:") { if strings.Contains(name, "peer:") {
// This is a service peer scope // This is a service peer scope
return "" return ""
} }
parts := strings.SplitN(name, ":", 2) parts := strings.SplitN(name, ":", 2)
if len(parts) != 2 { if len(parts) != 2 {
return ("") return ""
} }
return parts[1] return parts[1]
@ -542,7 +543,7 @@ func ParseServiceScopeName(name string) string {
// ParseProtocolScopeName returns the service name if name is a serviceScopeName. // ParseProtocolScopeName returns the service name if name is a serviceScopeName.
// Otherwise returns "" // Otherwise returns ""
func ParseProtocolScopeName(name string) string { func ParseProtocolScopeName(name string) string {
if strings.HasPrefix(name, "protocol:") { if strings.HasPrefix(name, "protocol:") && !IsSpan(name) {
if strings.Contains(name, "peer:") { if strings.Contains(name, "peer:") {
// This is a protocol peer scope // This is a protocol peer scope
return "" return ""

View File

@ -2,6 +2,7 @@ package rcmgr
import ( import (
"fmt" "fmt"
"strings"
"sync" "sync"
"github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/network"
@ -73,6 +74,12 @@ func newResourceScopeSpan(owner *resourceScope, id int) *resourceScope {
return r return r
} }
// IsSpan will return true if this name was created by newResourceScopeSpan
func IsSpan(name string) bool {
return strings.Contains(name, ".span-")
return name == "transient"
}
// Resources implementation // Resources implementation
func (rc *resources) checkMemory(rsvp int64, prio uint8) error { func (rc *resources) checkMemory(rsvp int64, prio uint8) error {
// overflow check; this also has the side effect that we cannot reserve negative memory. // overflow check; this also has the side effect that we cannot reserve negative memory.