From e683388b58a492e65e1f8dc0e667890941479d55 Mon Sep 17 00:00:00 2001 From: Will Miller Date: Fri, 11 Aug 2023 15:19:54 +0100 Subject: [PATCH] netem: add started log --- pkg/chaos/netem/netem.go | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/pkg/chaos/netem/netem.go b/pkg/chaos/netem/netem.go index 1f19292a..d4390e16 100644 --- a/pkg/chaos/netem/netem.go +++ b/pkg/chaos/netem/netem.go @@ -68,7 +68,7 @@ func newNetemCommand(client container.Client, gparams *chaos.GlobalParams, param // run network emulation command, stop netem on timeout or abort func runNetem(ctx context.Context, client container.Client, c *container.Container, netInterface string, cmd []string, ips []*net.IPNet, sports, dports []string, duration time.Duration, tcimage string, pull, dryRun bool) error { - log.WithFields(log.Fields{ + logger := log.WithFields(log.Fields{ "id": c.ID(), "name": c.Name(), "iface": netInterface, @@ -79,11 +79,13 @@ func runNetem(ctx context.Context, client container.Client, c *container.Contain "duration": duration, "tc-image": tcimage, "pull": pull, - }).Debug("running netem command") + }) + logger.Debug("running netem command") err := client.NetemContainer(ctx, c, netInterface, cmd, ips, sports, dports, duration, tcimage, pull, dryRun) if err != nil { return errors.Wrap(err, "netem failed") } + logger.Debug("netem command started") // create new context with timeout for canceling stopCtx, cancel := context.WithTimeout(context.Background(), duration) @@ -91,30 +93,14 @@ func runNetem(ctx context.Context, client container.Client, c *container.Contain // wait for specified duration and then stop netem (where it applied) or stop on ctx.Done() select { case <-ctx.Done(): - log.WithFields(log.Fields{ - "id": c.ID(), - "name": c.Name(), - "iface": netInterface, - "ips": ips, - "sports": sports, - "dports": dports, - "tc-image": tcimage, - }).Debug("stopping netem command on abort") + logger.Debug("stopping netem command on abort") // use different context to stop netem since parent context is canceled err = client.StopNetemContainer(context.Background(), c, netInterface, ips, sports, dports, tcimage, pull, dryRun) if err != nil { return errors.Wrap(err, "failed to stop netem container") } case <-stopCtx.Done(): - log.WithFields(log.Fields{ - "id": c.ID(), - "name": c.Name(), - "iface": netInterface, - "ips": ips, - "sports": sports, - "dports": dports, - "tc-image": tcimage, - }).Debug("stopping netem command on timout") + logger.Debug("stopping netem command on timout") // use parent context to stop netem in container err = client.StopNetemContainer(context.Background(), c, netInterface, ips, sports, dports, tcimage, pull, dryRun) if err != nil {