Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trace logger events for Bandwidth toxic #437

Merged
merged 1 commit into from
Sep 9, 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
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