mirror of
https://github.com/libp2p/go-libp2p-resource-manager.git
synced 2025-01-26 12:20:20 +08:00
Fix usage of make to reserve capacity, not values
This commit is contained in:
parent
2692b757e6
commit
65fb641b27
@ -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)))
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user