From 8e307bb99c34bb1ce0a73ce24cfb39f67f6701d0 Mon Sep 17 00:00:00 2001 From: Michael Nikitochkin Date: Wed, 7 Sep 2022 12:26:15 +0200 Subject: [PATCH] Add trace logger events for Bandwidth toxic --- cmd/server/server.go | 2 ++ scripts/test-e2e | 2 +- toxics/bandwidth.go | 12 ++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/cmd/server/server.go b/cmd/server/server.go index 1d3c2e19..82f4ea00 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -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" @@ -68,6 +69,7 @@ func run(cli cliArguments) { } logger := setupLogger() + log.Logger = logger rand.Seed(cli.seed) diff --git a/scripts/test-e2e b/scripts/test-e2e index 590f4aee..c710a0e9 100755 --- a/scripts/test-e2e +++ b/scripts/test-e2e @@ -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" diff --git a/toxics/bandwidth.go b/toxics/bandwidth.go index 18b6f7a7..ede9fc31 100644 --- a/toxics/bandwidth.go +++ b/toxics/bandwidth.go @@ -1,8 +1,11 @@ package toxics import ( + "fmt" "time" + "github.com/rs/zerolog/log" + "github.com/Shopify/toxiproxy/v2/stream" ) @@ -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 { @@ -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 } @@ -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 }