Skip to content

Commit

Permalink
Add trace logger events for Bandwidth toxic
Browse files Browse the repository at this point in the history
  • Loading branch information
miry committed Sep 7, 2022
1 parent dc4b9e4 commit 8e307bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/Shopify/toxiproxy/v2"
"github.com/Shopify/toxiproxy/v2/collectors"
Expand Down Expand Up @@ -68,6 +69,7 @@ func run(cli cliArguments) {
}

logger := setupLogger()
log.Logger = logger

rand.Seed(cli.seed)

Expand Down
2 changes: 1 addition & 1 deletion scripts/test-e2e
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ go run ../test/e2e/endpoint.go 2>&1 | sed -e 's/^/[web] /' &

echo "=== Starting Toxiproxy"

LOG_LEVEL=debug $server -proxy-metrics -runtime-metrics 2>&1 | sed -e 's/^/[toxiproxy] /' &
LOG_LEVEL=trace $server -proxy-metrics -runtime-metrics 2>&1 | sed -e 's/^/[toxiproxy] /' &

echo "=== Wait when services are available"

Expand Down
12 changes: 12 additions & 0 deletions toxics/bandwidth.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package toxics

import (
"fmt"
"time"

"github.com/rs/zerolog/log"

"github.com/Shopify/toxiproxy/v2/stream"
)

Expand All @@ -13,10 +16,17 @@ type BandwidthToxic struct {
}

func (t *BandwidthToxic) Pipe(stub *ToxicStub) {
logger := log.With().
Str("component", "BandwidthToxic").
Str("method", "Pipe").
Str("toxic_type", "bandwidth").
Str("addr", fmt.Sprintf("%p", t)).
Logger()
var sleep time.Duration = 0
for {
select {
case <-stub.Interrupt:
logger.Trace().Msg("BandwidthToxic was interrupted")
return
case p := <-stub.Input:
if p == nil {
Expand All @@ -39,6 +49,7 @@ func (t *BandwidthToxic) Pipe(stub *ToxicStub) {
p.Data = p.Data[t.Rate*100:]
sleep -= 100 * time.Millisecond
case <-stub.Interrupt:
logger.Trace().Msg("BandwidthToxic was interrupted during writing data")
stub.Output <- p // Don't drop any data on the floor
return
}
Expand All @@ -50,6 +61,7 @@ func (t *BandwidthToxic) Pipe(stub *ToxicStub) {
sleep -= time.Since(start)
stub.Output <- p
case <-stub.Interrupt:
logger.Trace().Msg("BandwidthToxic was interrupted during writing data")
stub.Output <- p // Don't drop any data on the floor
return
}
Expand Down

0 comments on commit 8e307bb

Please sign in to comment.