Skip to content

Commit 8e307bb

Browse files
committed
Add trace logger events for Bandwidth toxic
1 parent dc4b9e4 commit 8e307bb

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

cmd/server/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/prometheus/client_golang/prometheus"
1414
"github.com/rs/zerolog"
15+
"github.com/rs/zerolog/log"
1516

1617
"github.com/Shopify/toxiproxy/v2"
1718
"github.com/Shopify/toxiproxy/v2/collectors"
@@ -68,6 +69,7 @@ func run(cli cliArguments) {
6869
}
6970

7071
logger := setupLogger()
72+
log.Logger = logger
7173

7274
rand.Seed(cli.seed)
7375

scripts/test-e2e

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ go run ../test/e2e/endpoint.go 2>&1 | sed -e 's/^/[web] /' &
3737

3838
echo "=== Starting Toxiproxy"
3939

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

4242
echo "=== Wait when services are available"
4343

toxics/bandwidth.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package toxics
22

33
import (
4+
"fmt"
45
"time"
56

7+
"github.com/rs/zerolog/log"
8+
69
"github.com/Shopify/toxiproxy/v2/stream"
710
)
811

@@ -13,10 +16,17 @@ type BandwidthToxic struct {
1316
}
1417

1518
func (t *BandwidthToxic) Pipe(stub *ToxicStub) {
19+
logger := log.With().
20+
Str("component", "BandwidthToxic").
21+
Str("method", "Pipe").
22+
Str("toxic_type", "bandwidth").
23+
Str("addr", fmt.Sprintf("%p", t)).
24+
Logger()
1625
var sleep time.Duration = 0
1726
for {
1827
select {
1928
case <-stub.Interrupt:
29+
logger.Trace().Msg("BandwidthToxic was interrupted")
2030
return
2131
case p := <-stub.Input:
2232
if p == nil {
@@ -39,6 +49,7 @@ func (t *BandwidthToxic) Pipe(stub *ToxicStub) {
3949
p.Data = p.Data[t.Rate*100:]
4050
sleep -= 100 * time.Millisecond
4151
case <-stub.Interrupt:
52+
logger.Trace().Msg("BandwidthToxic was interrupted during writing data")
4253
stub.Output <- p // Don't drop any data on the floor
4354
return
4455
}
@@ -50,6 +61,7 @@ func (t *BandwidthToxic) Pipe(stub *ToxicStub) {
5061
sleep -= time.Since(start)
5162
stub.Output <- p
5263
case <-stub.Interrupt:
64+
logger.Trace().Msg("BandwidthToxic was interrupted during writing data")
5365
stub.Output <- p // Don't drop any data on the floor
5466
return
5567
}

0 commit comments

Comments
 (0)