some minor update (#76)

* remove workers in mem stress

Signed-off-by: xiang <xiang13225080@163.com>

* fix search

Signed-off-by: xiang <xiang13225080@163.com>

* fix test

Signed-off-by: xiang <xiang13225080@163.com>

* address comment

Signed-off-by: xiang <xiang13225080@163.com>
This commit is contained in:
WangXiang 2021-08-02 14:38:30 +08:00 committed by GitHub
parent f8e6aa3600
commit cbc5801ef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 16 deletions

View File

@ -153,7 +153,7 @@ func NetworkDuplicateCommand(dep fx.Option, options *core.NetworkCommand) *cobra
},
}
cmd.Flags().StringVar(&options.Percent, "percent", "1", "percentage of packets to corrupt (10 is 10%)")
cmd.Flags().StringVar(&options.Percent, "percent", "1", "percentage of packets to duplicate (10 is 10%)")
cmd.Flags().StringVarP(&options.Correlation, "correlation", "c", "0", "correlation is percentage (10 is 10%)")
cmd.Flags().StringVarP(&options.Device, "device", "d", "", "the network interface to impact")
cmd.Flags().StringVarP(&options.EgressPort, "egress-port", "e", "",

View File

@ -53,6 +53,7 @@ func NewStressCPUCommand(dep fx.Option, options *core.StressCommand) *cobra.Comm
Short: "continuously stress CPU out",
Run: func(*cobra.Command, []string) {
options.Action = core.StressCPUAction
options.CompleteDefaults()
utils.FxNewAppWithoutLog(dep, fx.Invoke(stressAttackF)).Run()
},
}
@ -70,11 +71,11 @@ func NewStressMemCommand(dep fx.Option, options *core.StressCommand) *cobra.Comm
Short: "continuously stress virtual memory out",
Run: func(*cobra.Command, []string) {
options.Action = core.StressMemAction
options.CompleteDefaults()
utils.FxNewAppWithoutLog(dep, fx.Invoke(stressAttackF)).Run()
},
}
cmd.Flags().IntVarP(&options.Workers, "workers", "w", 1, "Workers specifies N workers to apply the stressor.")
cmd.Flags().StringVarP(&options.Size, "size", "s", "", "Size specifies N bytes consumed per vm worker, default is the total available memory. One can specify the size as % of total available memory or in units of B, KB/KiB, MB/MiB, GB/GiB, TB/TiB..")
cmd.Flags().StringSliceVarP(&options.Options, "options", "o", []string{}, "extend stress-ng options.")

View File

@ -51,7 +51,7 @@ func NewSearchCommand() *cobra.Command {
cmd.Flags().StringVarP(&options.Status, "status", "s", "", "attack status, "+
"supported value: created, success, error, destroyed, revoked")
cmd.Flags().StringVarP(&options.Kind, "kind", "k", "", "attack kind, "+
"supported value: network, process")
"supported value: network, process, stress, disk, host, jvm")
cmd.Flags().Uint32VarP(&options.Offset, "offset", "o", 0, "starting to search attacks from offset")
cmd.Flags().Uint32VarP(&options.Limit, "limit", "l", 0, "limit the count of attacks")
cmd.Flags().BoolVar(&options.Asc, "asc", false, "order by CreateTime, "+

View File

@ -77,8 +77,21 @@ func (exp *Experiment) GetRequestCommand() (AttackConfig, error) {
return exp.cachedRequestCommand, nil
}
attackConfig := GetAttackByKind(exp.Kind)
if attackConfig == nil {
return nil, perr.Errorf("chaos experiment kind %s not found", exp.Kind)
}
if err := json.Unmarshal([]byte(exp.RecoverCommand), attackConfig); err != nil {
return nil, err
}
exp.cachedRequestCommand = *attackConfig
return *attackConfig, nil
}
func GetAttackByKind(kind string) *AttackConfig {
var attackConfig AttackConfig
switch exp.Kind {
switch kind {
case ProcessAttack:
attackConfig = &ProcessCommand{}
case NetworkAttack:
@ -89,13 +102,11 @@ func (exp *Experiment) GetRequestCommand() (AttackConfig, error) {
attackConfig = &StressCommand{}
case DiskAttack:
attackConfig = &DiskOption{}
case JVMAttack:
attackConfig = &JVMCommand{}
default:
return nil, perr.Errorf("chaos experiment kind %s not found", exp.Kind)
return nil
}
if err := json.Unmarshal([]byte(exp.RecoverCommand), attackConfig); err != nil {
return nil, err
}
exp.cachedRequestCommand = attackConfig
return attackConfig, nil
return &attackConfig
}

View File

@ -33,10 +33,8 @@ func (s SearchCommand) Validate() error {
}
if len(s.Kind) > 0 {
switch s.Kind {
case NetworkAttack, ProcessAttack:
break
default:
attack := GetAttackByKind(s.Kind)
if attack == nil {
return errors.Errorf("type %s not supported", s.Kind)
}
}

View File

@ -47,6 +47,12 @@ func (s *StressCommand) Validate() error {
return nil
}
func (s *StressCommand) CompleteDefaults() {
if s.Workers == 0 {
s.Workers = 1
}
}
func (s StressCommand) RecoverData() string {
data, _ := json.Marshal(s)

View File

@ -106,7 +106,7 @@ func (diskAttack) diskPayload(payload *core.DiskOption) error {
}
ddBlocks, err := utils.SplitBytesByProcessNum(byteSize, payload.PayloadProcessNum)
if err != nil {
log.Error(fmt.Sprintf("split size ,process num %d", payload.PayloadProcessNum), zap.Error(err))
log.Error(fmt.Sprintf("split size, process num %d", payload.PayloadProcessNum), zap.Error(err))
return err
}
if len(ddBlocks) == 0 {

View File

@ -40,7 +40,7 @@ timeout 5s tail --pid=$PID -f /dev/null
ps aux | grep stress-ng
# test mem stress
${bin_path}/chaosd attack stress mem -w 1 > mem.out
${bin_path}/chaosd attack stress mem --size 10M > mem.out
PID=`cat mem.out | grep "stress-ng" | sed 's/.*Pid=\([0-9]*\).*/\1/g'`