Fix usage of make to reserve capacity, not values

This commit is contained in:
Marco Munizaga 2022-08-11 10:52:49 -07:00
parent 2692b757e6
commit 65fb641b27
2 changed files with 25 additions and 2 deletions

View File

@ -322,14 +322,14 @@ func (r StatsTraceReporter) ConsumeEvent(evt rcmgr.TraceEvt) {
tags := []tag.Mutator{tag.Upsert(scopeTag, scopeName), tag.Upsert(resourceTag, resource)}
if evt.DeltaIn != 0 {
tagsWithDir := make([]tag.Mutator, 3)
tagsWithDir := make([]tag.Mutator, 0, 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 := make([]tag.Mutator, 3)
tagsWithDir := make([]tag.Mutator, 0, 3)
tagsWithDir = append(tagsWithDir, tag.Insert(directionTag, "outbound"))
tagsWithDir = append(tagsWithDir, tags...)
stats.RecordWithTags(ctx, tagsWithDir, blockedResources.M(int64(1)))

View File

@ -2,9 +2,11 @@ package obs_test
import (
"testing"
"time"
rcmgr "github.com/libp2p/go-libp2p-resource-manager"
"github.com/libp2p/go-libp2p-resource-manager/obs"
"go.opencensus.io/stats/view"
)
func TestTraceReporterStartAndClose(t *testing.T) {
@ -14,3 +16,24 @@ func TestTraceReporterStartAndClose(t *testing.T) {
}
defer rcmgr.Close()
}
func TestConsumeEvent(t *testing.T) {
evt := rcmgr.TraceEvt{
Type: rcmgr.TraceBlockAddStreamEvt,
Name: "conn-1",
DeltaOut: 1,
Time: time.Now().Format(time.RFC3339Nano),
}
err := view.Register(obs.DefaultViews...)
if err != nil {
t.Fatal(err)
}
str, err := obs.NewStatsTraceReporter()
if err != nil {
t.Fatal(err)
}
str.ConsumeEvent(evt)
}