Skip to content

Commit 2797b6a

Browse files
authored
Merge branch 'master' into fixed-comma-split
2 parents 7813ef9 + a83f346 commit 2797b6a

File tree

9 files changed

+54
-39
lines changed

9 files changed

+54
-39
lines changed

chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7+
corev1 "k8s.io/api/core/v1"
78
"net/http"
89
"os"
910
"os/signal"
1011
"strings"
1112
"syscall"
1213
"time"
1314

14-
corev1 "k8s.io/api/core/v1"
15-
1615
"github.com/litmuschaos/litmus-go/pkg/clients"
1716
"github.com/litmuschaos/litmus-go/pkg/events"
1817
"github.com/litmuschaos/litmus-go/pkg/log"

chaoslib/litmus/stress-chaos/helper/stress-helper.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ var (
4545
const (
4646
// ProcessAlreadyFinished contains error code when process is finished
4747
ProcessAlreadyFinished = "os: process already finished"
48+
// ProcessAlreadyKilled contains error code when process is already killed
49+
ProcessAlreadyKilled = "no such process"
4850
)
4951

5052
// Helper injects the stress chaos
@@ -125,6 +127,8 @@ func prepareStressChaos(experimentsDetails *experimentTypes.ExperimentDetails, c
125127

126128
// launch the stress-ng process on the target container in paused mode
127129
cmd := exec.Command("/bin/bash", "-c", stressCommand)
130+
// enables the process group id
131+
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
128132
var buf bytes.Buffer
129133
cmd.Stdout = &buf
130134
err = cmd.Start()
@@ -183,16 +187,18 @@ func prepareStressChaos(experimentsDetails *experimentTypes.ExperimentDetails, c
183187
err, ok := err.(*exec.ExitError)
184188
if ok {
185189
status := err.Sys().(syscall.WaitStatus)
186-
if status.Signaled() && status.Signal() == syscall.SIGTERM {
190+
if status.Signaled() && status.Signal() == syscall.SIGKILL {
187191
// wait for the completion of abort handler
188192
time.Sleep(10 * time.Second)
189-
return errors.Errorf("process stopped with SIGTERM signal")
193+
return errors.Errorf("process stopped with SIGKILL signal")
190194
}
191195
}
192196
return errors.Errorf("process exited before the actual cleanup, err: %v", err)
193197
}
194198
log.Info("[Info]: Chaos injection completed")
195-
terminateProcess(cmd.Process.Pid)
199+
if err := terminateProcess(cmd.Process.Pid); err != nil {
200+
return err
201+
}
196202
if err = result.AnnotateChaosResult(resultDetails.Name, chaosDetails.ChaosNamespace, "reverted", "pod", experimentsDetails.TargetPods); err != nil {
197203
return err
198204
}
@@ -203,12 +209,11 @@ func prepareStressChaos(experimentsDetails *experimentTypes.ExperimentDetails, c
203209

204210
//terminateProcess will remove the stress process from the target container after chaos completion
205211
func terminateProcess(pid int) error {
206-
process, err := os.FindProcess(pid)
207-
if err != nil {
208-
return errors.Errorf("unreachable path, err: %v", err)
209-
}
210-
if err = process.Signal(syscall.SIGTERM); err != nil && err.Error() != ProcessAlreadyFinished {
211-
return errors.Errorf("error while killing process, err: %v", err)
212+
if err := syscall.Kill(-pid, syscall.SIGKILL); err != nil {
213+
if strings.Contains(err.Error(), ProcessAlreadyKilled) || strings.Contains(err.Error(), ProcessAlreadyFinished) {
214+
return nil
215+
}
216+
return err
212217
}
213218
log.Info("[Info]: Stress process removed successfully")
214219
return nil

pkg/probe/cmdprobe.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,12 @@ func triggerSourceOnChaosCmdProbe(probe v1alpha1.ProbeAttributes, execCommandDet
342342
duration = math.Maximum(0, duration-probe.RunProperties.InitialDelaySeconds)
343343
}
344344

345-
var endTime <-chan time.Time
346-
timeDelay := time.Duration(duration) * time.Second
345+
endTime := time.After(time.Duration(duration) * time.Second)
347346

348347
// it trigger the cmd probe for the entire duration of chaos and it fails, if any err encounter
349348
// it marked the error for the probes, if any
350349
loop:
351350
for {
352-
endTime = time.After(timeDelay)
353351
select {
354352
case <-endTime:
355353
log.Infof("[Chaos]: Time is up for the %v probe", probe.Name)

pkg/probe/httpprobe.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,12 @@ func triggerOnChaosHTTPProbe(probe v1alpha1.ProbeAttributes, clients clients.Cli
330330
duration = math.Maximum(0, duration-probe.RunProperties.InitialDelaySeconds)
331331
}
332332

333-
var endTime <-chan time.Time
334-
timeDelay := time.Duration(duration) * time.Second
333+
endTime := time.After(time.Duration(duration) * time.Second)
335334

336335
// it trigger the http probe for the entire duration of chaos and it fails, if any error encounter
337336
// it marked the error for the probes, if any
338337
loop:
339338
for {
340-
endTime = time.After(timeDelay)
341339
select {
342340
case <-endTime:
343341
log.Infof("[Chaos]: Time is up for the %v probe", probe.Name)

pkg/probe/k8sprobe.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,12 @@ func triggerOnChaosK8sProbe(probe v1alpha1.ProbeAttributes, clients clients.Clie
295295
duration = math.Maximum(0, duration-probe.RunProperties.InitialDelaySeconds)
296296
}
297297

298-
var endTime <-chan time.Time
299-
timeDelay := time.Duration(duration) * time.Second
298+
endTime := time.After(time.Duration(duration) * time.Second)
300299

301-
// it trigger the k8s probe for the entire duration of chaos and it fails, if any error encounter
300+
// it triggers the k8s probe for the entire duration of chaos and it fails, if any error encounter
302301
// marked the error for the probes, if any
303302
loop:
304303
for {
305-
endTime = time.After(timeDelay)
306304
select {
307305
case <-endTime:
308306
log.Infof("[Chaos]: Time is up for the %v probe", probe.Name)

pkg/probe/probe.go

+32-13
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,23 @@ func RunProbes(chaosDetails *types.ChaosDetails, clients clients.ClientSets, res
3232
}
3333

3434
switch strings.ToLower(phase) {
35-
//execute probes for the prechaos & duringchaos phase
36-
case "prechaos", "duringchaos":
35+
//execute probes for the prechaos phase
36+
case "prechaos":
3737
for _, probe := range probes {
38-
if err := execute(probe, chaosDetails, clients, resultDetails, phase); err != nil {
39-
return err
38+
switch strings.ToLower(probe.Mode) {
39+
case "sot", "edge", "continuous":
40+
if err := execute(probe, chaosDetails, clients, resultDetails, phase); err != nil {
41+
return err
42+
}
43+
}
44+
}
45+
//execute probes for the duringchaos phase
46+
case "duringchaos":
47+
for _, probe := range probes {
48+
if strings.ToLower(probe.Mode) == "onchaos" {
49+
if err := execute(probe, chaosDetails, clients, resultDetails, phase); err != nil {
50+
return err
51+
}
4052
}
4153
}
4254
default:
@@ -58,8 +70,11 @@ func RunProbes(chaosDetails *types.ChaosDetails, clients clients.ClientSets, res
5870
}
5971
// executes the eot and edge modes
6072
for _, probe := range probes {
61-
if err := execute(probe, chaosDetails, clients, resultDetails, phase); err != nil {
62-
return err
73+
switch strings.ToLower(probe.Mode) {
74+
case "eot", "edge":
75+
if err := execute(probe, chaosDetails, clients, resultDetails, phase); err != nil {
76+
return err
77+
}
6378
}
6479
}
6580
}
@@ -137,7 +152,6 @@ func InitializeProbesInChaosResultDetails(chaosDetails *types.ChaosDetails, clie
137152
tempProbe.Name = probe.Name
138153
tempProbe.Type = probe.Type
139154
tempProbe.Mode = probe.Mode
140-
tempProbe.Phase = "N/A"
141155
tempProbe.RunCount = 0
142156
tempProbe.Status = v1alpha1.ProbeStatus{
143157
Verdict: "Awaited",
@@ -204,12 +218,8 @@ func markedVerdictInEnd(err error, resultDetails *types.ResultDetails, probe v1a
204218
// counting the passed probes count to generate the score and mark the verdict as passed
205219
// for edge, probe is marked as Passed if passed in both pre/post chaos checks
206220
switch strings.ToLower(probe.Mode) {
207-
case "edge", "continuous":
208-
if phase != "PreChaos" {
209-
resultDetails.PassedProbeCount++
210-
}
211-
case "onchaos":
212-
if phase != "DuringChaos" {
221+
case "edge":
222+
if phase == "PostChaos" && getProbeVerdict(resultDetails, probe.Name, probe.Type) != v1alpha1.ProbeVerdictFailed {
213223
resultDetails.PassedProbeCount++
214224
}
215225
default:
@@ -313,3 +323,12 @@ func execute(probe v1alpha1.ProbeAttributes, chaosDetails *types.ChaosDetails, c
313323
}
314324
return nil
315325
}
326+
327+
func getProbeVerdict(resultDetails *types.ResultDetails, name, probeType string) v1alpha1.ProbeVerdict {
328+
for _, probe := range resultDetails.ProbeDetails {
329+
if probe.Name == name && probe.Type == probeType {
330+
return probe.Status.Verdict
331+
}
332+
}
333+
return v1alpha1.ProbeVerdictNA
334+
}

pkg/probe/promProbe.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,12 @@ func triggerOnChaosPromProbe(probe v1alpha1.ProbeAttributes, clients clients.Cli
264264
duration = math.Maximum(0, duration-probe.RunProperties.InitialDelaySeconds)
265265
}
266266

267-
var endTime <-chan time.Time
268-
timeDelay := time.Duration(duration) * time.Second
267+
endTime := time.After(time.Duration(duration) * time.Second)
269268

270269
// it trigger the prom probe for the entire duration of chaos and it fails, if any err encounter
271270
// it marked the error for the probes, if any
272271
loop:
273272
for {
274-
endTime = time.After(timeDelay)
275273
select {
276274
case <-endTime:
277275
log.Infof("[Chaos]: Time is up for the %v probe", probe.Name)

pkg/result/chaosresult.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func GetProbeStatus(resultDetails *types.ResultDetails) (bool, []v1alpha1.ProbeS
136136
probes.Mode = probe.Mode
137137
probes.Status = probe.Status
138138
probeStatus = append(probeStatus, probes)
139-
if probe.Phase == "Failed" {
139+
if probe.Status.Verdict == v1alpha1.ProbeVerdictFailed {
140140
isAllProbePassed = false
141141
}
142142
}
@@ -165,6 +165,7 @@ func updateResultAttributes(clients clients.ClientSets, chaosDetails *types.Chao
165165
if !isAllProbePassed {
166166
resultDetails.Verdict = "Fail"
167167
result.Status.ExperimentStatus.Verdict = "Fail"
168+
result.Status.ExperimentStatus.FailStep = "Probe execution result didn't met the passing criteria"
168169
}
169170
switch strings.ToLower(string(resultDetails.Verdict)) {
170171
case "pass":

pkg/types/types.go

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ type ProbeDetails struct {
5656
Name string
5757
Type string
5858
Mode string
59-
Phase string
6059
Status v1alpha1.ProbeStatus
6160
IsProbeFailedWithError error
6261
RunID string

0 commit comments

Comments
 (0)