From 7dda49c55d1c2caccd6fc84f8587543ca4898308 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Fri, 8 Jul 2022 13:43:46 -0700 Subject: [PATCH 1/2] Record which direction the resource was blocked --- obs/stats.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/obs/stats.go b/obs/stats.go index 4ba2bf4..3160f6a 100644 --- a/obs/stats.go +++ b/obs/stats.go @@ -320,11 +320,13 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) { tags := []tag.Mutator{tag.Upsert(scopeTag, scopeName), tag.Upsert(resourceTag, resource)} if evt.DeltaIn != 0 { - stats.RecordWithTags(ctx, tags, blockedResources.M(int64(1))) + tagsWithDir := append([]tag.Mutator{tag.Insert(directionTag, "inbound")}, tags...) + stats.RecordWithTags(ctx, tagsWithDir, blockedResources.M(int64(1))) } if evt.DeltaOut != 0 { - stats.RecordWithTags(ctx, tags, blockedResources.M(int64(1))) + tagsWithDir := append([]tag.Mutator{tag.Insert(directionTag, "outbound")}, tags...) + stats.RecordWithTags(ctx, tagsWithDir, blockedResources.M(int64(1))) } if evt.Delta != 0 { From 3ecce6cc3430d946fb8466bba0585bcfcd275875 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 27 Jul 2022 04:28:44 -0700 Subject: [PATCH 2/2] Add size hint to slice to hopefully have the tag slice allocated on the stack --- obs/stats.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/obs/stats.go b/obs/stats.go index 3160f6a..e2d97f7 100644 --- a/obs/stats.go +++ b/obs/stats.go @@ -317,15 +317,21 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) { // Drop the connection or stream id scopeName = strings.SplitN(scopeName, "-", 2)[0] + // If something else gets added here, make sure to update the size hint + // below when we make `tagsWithDir`. tags := []tag.Mutator{tag.Upsert(scopeTag, scopeName), tag.Upsert(resourceTag, resource)} if evt.DeltaIn != 0 { - tagsWithDir := append([]tag.Mutator{tag.Insert(directionTag, "inbound")}, tags...) - stats.RecordWithTags(ctx, tagsWithDir, blockedResources.M(int64(1))) + tagsWithDir := make([]tag.Mutator, 3) + tagsWithDir = append(tagsWithDir, tag.Insert(directionTag, "inbound")) + tagsWithDir = append(tagsWithDir, tags...) + stats.RecordWithTags(ctx, tagsWithDir[0:], blockedResources.M(int64(1))) } if evt.DeltaOut != 0 { - tagsWithDir := append([]tag.Mutator{tag.Insert(directionTag, "outbound")}, tags...) + tagsWithDir := make([]tag.Mutator, 3) + tagsWithDir = append(tagsWithDir, tag.Insert(directionTag, "outbound")) + tagsWithDir = append(tagsWithDir, tags...) stats.RecordWithTags(ctx, tagsWithDir, blockedResources.M(int64(1))) }