Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
cleaner way to isolate
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed Nov 26, 2017
1 parent b3a9c83 commit b12e119
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
7 changes: 1 addition & 6 deletions chaos/chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,7 @@ func TestIsolateOneInstance(t *testing.T) {
}()

// now go ahead and isolate for 30s
isolate("metrictank4", "30s", "metrictank0", "metrictank1", "metrictank2", "metrictank3", "metrictank5")
isolate("metrictank0", "30s", "metrictank4")
isolate("metrictank1", "30s", "metrictank4")
isolate("metrictank2", "30s", "metrictank4")
isolate("metrictank3", "30s", "metrictank4")
isolate("metrictank5", "30s", "metrictank4")
isolate([]string{"metrictank4"}, []string{"metrictank0", "metrictank1", "metrictank2", "metrictank3", "metrictank5"}, "30s")

// collect results of the minute long experiment
mt4Results := <-mt4ResultsChan
Expand Down
23 changes: 21 additions & 2 deletions chaos/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,27 @@ func stop(name string) error {
return cmd.Run()
}

// isolate isolates traffic from the given docker container to all others matching the expression
func isolate(name, dur string, targets ...string) error {
// isolate isolates traffic between containers in setA and containers in setB
func isolate(setA, setB []string, dur string) error {
// note: isolateOut should return very fast (order of ms)
// so we can run all this in serial
for _, a := range setA {
err := isolateOut(a, dur, setB...)
if err != nil {
return err
}
}
for _, b := range setB {
err := isolateOut(b, dur, setA...)
if err != nil {
return err
}
}
return nil
}

// isolateOut isolates traffic from the given docker container to all others matching the expression
func isolateOut(name, dur string, targets ...string) error {
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{})
if err != nil {
return err
Expand Down

0 comments on commit b12e119

Please sign in to comment.