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

Commit

Permalink
fix(metrics): update go-flow-metrics and fix tests for upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Nov 1, 2019
1 parent 91d2454 commit b1df0aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/gogo/protobuf v1.3.1
github.com/ipfs/go-cid v0.0.3
github.com/jbenet/goprocess v0.1.3
github.com/libp2p/go-flow-metrics v0.0.1
github.com/libp2p/go-flow-metrics v0.0.2
github.com/libp2p/go-msgio v0.0.4
github.com/libp2p/go-openssl v0.0.3
github.com/minio/sha256-simd v0.1.1
Expand All @@ -18,8 +18,4 @@ require (
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
)

//replace github.com/libp2p/go-flow-metrics v0.0.1 => github.com/kpp/go-flow-metrics v0.0.2-0.20191101005412-ce5ebda5e4a4 // Stebalien's version

replace github.com/libp2p/go-flow-metrics v0.0.1 => github.com/kpp/go-flow-metrics v0.0.2-0.20191031231915-edeb2d90f222 // kpp's version

go 1.12
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,15 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23 h1:FOOIBWrEkLgmlgGfMuZT83xIwfPDxEI2OHu6xUmJMFE=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kpp/go-flow-metrics v0.0.2-0.20191031231915-edeb2d90f222 h1:6Pnw+RUnFR7FY6wEQbqFj+aPrp7bMptn02jEAruMPLk=
github.com/kpp/go-flow-metrics v0.0.2-0.20191031231915-edeb2d90f222/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs=
github.com/kpp/go-flow-metrics v0.0.2-0.20191101005412-ce5ebda5e4a4 h1:wZFgH2qCaRIN+wb0B8e2HuI2JzdrLOMvVxU0cqvZB2g=
github.com/kpp/go-flow-metrics v0.0.2-0.20191101005412-ce5ebda5e4a4/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/libp2p/go-buffer-pool v0.0.1 h1:9Rrn/H46cXjaA2HQ5Y8lyhOS1NhTkZ4yuEs2r3Eechg=
github.com/libp2p/go-buffer-pool v0.0.1/go.mod h1:xtyIz9PMobb13WaxR6Zo1Pd1zXJKYg0a8KiIvDp3TzQ=
github.com/libp2p/go-flow-metrics v0.0.1 h1:0gxuFd2GuK7IIP5pKljLwps6TvcuYgvG7Atqi3INF5s=
github.com/libp2p/go-flow-metrics v0.0.1/go.mod h1:Iv1GH0sG8DtYN3SVJ2eG221wMiNpZxBdp967ls1g+k8=
github.com/libp2p/go-flow-metrics v0.0.2 h1:U5TvqfoyR6GVRM+bC15Ux1ltar1kbj6Zw6xOVR02CZs=
github.com/libp2p/go-flow-metrics v0.0.2/go.mod h1:HeoSNUrOJVK1jEpDqVEiUOIXqhbnS27omG0uWU5slZs=
github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA=
github.com/libp2p/go-msgio v0.0.4 h1:agEFehY3zWJFUHK6SEMR7UYmk2z6kC3oeCM7ybLhguA=
github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
Expand Down
28 changes: 22 additions & 6 deletions metrics/bandwidth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func round(bwc *BandwidthCounter, b *testing.B) {
b.StopTimer()
}

// Allow 7% errors for bw calculations.
const acceptableError = 0.07
// Allow 1% errors for bw calculations.
const acceptableError = 0.01

func TestBandwidthCounter(t *testing.T) {
bwc := NewBandwidthCounter()
Expand All @@ -62,12 +62,19 @@ func TestBandwidthCounter(t *testing.T) {
proto := protocol.ID(fmt.Sprintf("proto-%d", j))
go func() {
defer wg.Done()

// make sure the bandwidth counters are active
bwc.LogSentMessage(100)
bwc.LogRecvMessage(50)
bwc.LogSentMessageStream(100, proto, p)
bwc.LogRecvMessageStream(50, proto, p)

<-start

t := time.NewTicker(100 * time.Millisecond)
defer t.Stop()

for i := 0; i < 40; i++ {
for i := 0; i < 39; i++ {
bwc.LogSentMessage(100)
bwc.LogRecvMessage(50)
bwc.LogSentMessageStream(100, proto, p)
Expand Down Expand Up @@ -104,6 +111,7 @@ func TestBandwidthCounter(t *testing.T) {
}
}

time.Sleep(time.Second)
close(start)
time.Sleep(2*time.Second + 100*time.Millisecond)

Expand Down Expand Up @@ -149,17 +157,25 @@ func TestResetBandwidthCounter(t *testing.T) {
p := peer.ID("peer-0")
proto := protocol.ID("proto-0")

// We don't calculate bandwidth till we've been active for a second.
bwc.LogSentMessage(42)
bwc.LogRecvMessage(24)
bwc.LogSentMessageStream(100, proto, p)
bwc.LogRecvMessageStream(50, proto, p)

time.Sleep(1 * time.Second)
time.Sleep(1*time.Second + time.Millisecond)

bwc.LogSentMessage(42)
bwc.LogRecvMessage(24)
bwc.LogSentMessageStream(100, proto, p)
bwc.LogRecvMessageStream(50, proto, p)

time.Sleep(1*time.Second + time.Millisecond)

{
stats := bwc.GetBandwidthTotals()
assertEq(t, 42, stats.TotalOut)
assertEq(t, 24, stats.TotalIn)
assertEq(t, 84, stats.TotalOut)
assertEq(t, 48, stats.TotalIn)
}

{
Expand Down

0 comments on commit b1df0aa

Please sign in to comment.