Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Fix usage of make to reserve capacity, not values #76

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions obs/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
23 changes: 23 additions & 0 deletions obs/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}