Skip to content
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

clusterloader2: Avoid logging and awaiting waitgroup when chaosmonkey is disabled #3078

Merged
Show file tree
Hide file tree
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
23 changes: 12 additions & 11 deletions clusterloader2/pkg/chaos/monkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package chaos

import (
"fmt"
"strings"
"sync"

Expand All @@ -42,25 +41,27 @@ func NewMonkey(client clientset.Interface, provider provider.Provider) *Monkey {
// Init initializes Monkey with given config.
// When stopCh is closed, the Monkey will stop simulating failures.
func (m *Monkey) Init(config api.ChaosMonkeyConfig, stopCh <-chan struct{}) (*sync.WaitGroup, error) {
wg := sync.WaitGroup{}
if config.NodeFailure != nil {
nodeKiller, err := NewNodeKiller(*config.NodeFailure, m.client, config.ExcludedNodes, m.provider)
if err != nil {
return nil, err
}
m.nodeKiller = nodeKiller
wg.Add(1)
go m.nodeKiller.Run(stopCh, &wg)
if config.NodeFailure == nil {
return nil, nil
}

nodeKiller, err := NewNodeKiller(*config.NodeFailure, m.client, config.ExcludedNodes, m.provider)
if err != nil {
return nil, err
}
m.nodeKiller = nodeKiller

var wg sync.WaitGroup
wg.Add(1)
go m.nodeKiller.Run(stopCh, &wg)
return &wg, nil
}

// Summary logs Monkey execution
func (m *Monkey) Summary() string {
var sb strings.Builder
if m.nodeKiller != nil {
sb.WriteString(fmt.Sprintf("Summary of Chaos Monkey execution\n"))
sb.WriteString("Summary of Chaos Monkey execution\n")
sb.WriteString(m.nodeKiller.Summary())
}
return sb.String()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func (c *chaosMonkeyMeasurement) Execute(config *measurement.Config) ([]measurem
}
c.stopChannel = make(chan struct{})
c.chaosMonkey = chaos.NewMonkey(config.ClusterFramework.GetClientSets().GetClient(), config.CloudProvider)
c.chaosMonkeyWaitGroup, err = c.chaosMonkey.Init(api.ChaosMonkeyConfig{&c.NodeFailureConfig, c.killedNodes}, c.stopChannel)
chaosMonkeyConfig := api.ChaosMonkeyConfig{NodeFailure: &c.NodeFailureConfig, ExcludedNodes: c.killedNodes}
c.chaosMonkeyWaitGroup, err = c.chaosMonkey.Init(chaosMonkeyConfig, c.stopChannel)
if err != nil {
close(c.stopChannel)
return nil, fmt.Errorf("error while creating chaos monkey: %v", err)
Expand All @@ -79,7 +80,10 @@ func (c *chaosMonkeyMeasurement) Execute(config *measurement.Config) ([]measurem
klog.V(2).Info("Chaos monkey ended.")
}
c.killedNodes = c.chaosMonkey.KilledNodes()
klog.V(2).Infof(c.chaosMonkey.Summary())
summary := c.chaosMonkey.Summary()
if summary != "" {
klog.V(2).Info(summary)
}
// ChaosMonkey doesn't collect metrics and returns empty measurement.Summary.
return []measurement.Summary{}, nil
default:
Expand Down
5 changes: 4 additions & 1 deletion clusterloader2/pkg/test/simple_test_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ func (ste *simpleExecutor) ExecuteTest(ctx Context, conf *api.Config) *errors.Er
}
}
}
klog.V(2).Infof(ctx.GetChaosMonkey().Summary())
summary := ctx.GetChaosMonkey().Summary()
if summary != "" {
klog.V(2).Info(summary)
}
return errList
}

Expand Down