8000 netem: add started log by w-miller · Pull Request #250 · alexei-led/pumba · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

netem: add started log #250

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

Merged
merged 1 commit into from
Sep 7, 2023
Merged
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
26 changes: 6 additions & 20 deletions pkg/chaos/netem/netem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -79,42 +79,28 @@ 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)
defer cancel()
// 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 {
Expand Down
0