Skip to content

Commit 77b30e2

Browse files
authored
(chore): Adding user-friendly failsteps and removing non-litmus libs (litmuschaos#626)
* feat(failstep): Adding failstep in all experiment and removed non-litmus libs Signed-off-by: Shubham Chaudhary <[email protected]>
1 parent eb98d50 commit 77b30e2

File tree

218 files changed

+3939
-6187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

218 files changed

+3939
-6187
lines changed

.github/workflows/build.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
# Install golang
1313
- uses: actions/setup-go@v2
1414
with:
15-
go-version: 1.17
15+
go-version: 1.18
1616

1717
- uses: actions/checkout@v2
1818
with:
@@ -49,7 +49,7 @@ jobs:
4949
- run: snyk auth ${SNYK_TOKEN}
5050
- uses: actions/setup-go@v1
5151
with:
52-
go-version: '1.17'
52+
go-version: '1.18'
5353
- name: Snyk monitor
5454
run: snyk test
5555

@@ -60,7 +60,7 @@ jobs:
6060
# Install golang
6161
- uses: actions/setup-go@v2
6262
with:
63-
go-version: 1.17
63+
go-version: 1.18
6464

6565
- uses: actions/checkout@v2
6666
with:

.github/workflows/push.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
# Install golang
1414
- uses: actions/setup-go@v2
1515
with:
16-
go-version: 1.17
16+
go-version: 1.18
1717
- uses: actions/checkout@v2
1818

1919
#TODO: Add Dockerfile linting
@@ -43,7 +43,7 @@ jobs:
4343
# Install golang
4444
- uses: actions/setup-go@v2
4545
with:
46-
go-version: 1.17
46+
go-version: 1.18
4747
- uses: actions/checkout@v2
4848

4949
- name: Set up QEMU

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
# Install golang
1414
- uses: actions/setup-go@v2
1515
with:
16-
go-version: 1.17
16+
go-version: 1.18
1717
- uses: actions/checkout@v2
1818

1919
#TODO: Add Dockerfile linting
@@ -30,7 +30,7 @@ jobs:
3030
# Install golang
3131
- uses: actions/setup-go@v2
3232
with:
33-
go-version: 1.17
33+
go-version: 1.18
3434
- uses: actions/checkout@v2
3535

3636
- name: Set Tag

.github/workflows/run-e2e-on-pr-commits.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ jobs:
217217
# Install golang
218218
- uses: actions/setup-go@v2
219219
with:
220-
go-version: '1.17'
220+
go-version: '1.18'
221221

222222
- uses: actions/checkout@v2
223223
with:
@@ -260,7 +260,7 @@ jobs:
260260
# Install golang
261261
- uses: actions/setup-go@v2
262262
with:
263-
go-version: '1.17'
263+
go-version: '1.18'
264264

265265
- uses: actions/checkout@v2
266266
with:
@@ -302,7 +302,7 @@ jobs:
302302
# Install golang
303303
- uses: actions/setup-go@v2
304304
with:
305-
go-version: '1.17'
305+
go-version: '1.18'
306306

307307
- uses: actions/checkout@v2
308308
with:

build/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Multi-stage docker build
22
# Build stage
3-
FROM golang:1.17 AS builder
3+
FROM golang:1.18 AS builder
44

55
ARG TARGETOS=linux
66
ARG TARGETARCH

chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/litmuschaos/litmus-go/pkg/probe"
1414
"github.com/litmuschaos/litmus-go/pkg/types"
1515
"github.com/litmuschaos/litmus-go/pkg/utils/common"
16-
"github.com/pkg/errors"
16+
"github.com/palantir/stacktrace"
1717
)
1818

1919
// InjectChaosInSerialMode will inject the aws ssm chaos in serial mode that is one after other
@@ -46,29 +46,29 @@ func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai
4646
ec2IDList := strings.Fields(ec2ID)
4747
commandId, err := ssm.SendSSMCommand(experimentsDetails, ec2IDList)
4848
if err != nil {
49-
return errors.Errorf("fail to send ssm command, err: %v", err)
49+
return stacktrace.Propagate(err, "failed to send ssm command")
5050
}
5151
//prepare commands for abort recovery
5252
experimentsDetails.CommandIDs = append(experimentsDetails.CommandIDs, commandId)
5353

5454
//wait for the ssm command to get in running state
5555
log.Info("[Wait]: Waiting for the ssm command to get in InProgress state")
5656
if err := ssm.WaitForCommandStatus("InProgress", commandId, ec2ID, experimentsDetails.Region, experimentsDetails.ChaosDuration+experimentsDetails.Timeout, experimentsDetails.Delay); err != nil {
57-
return errors.Errorf("fail to start ssm command, err: %v", err)
57+
return stacktrace.Propagate(err, "failed to start ssm command")
5858
}
5959
common.SetTargets(ec2ID, "injected", "EC2", chaosDetails)
6060

6161
// run the probes during chaos
6262
if len(resultDetails.ProbeDetails) != 0 && i == 0 {
6363
if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil {
64-
return err
64+
return stacktrace.Propagate(err, "failed to run probes")
6565
}
6666
}
6767

6868
//wait for the ssm command to get succeeded in the given chaos duration
6969
log.Info("[Wait]: Waiting for the ssm command to get completed")
7070
if err := ssm.WaitForCommandStatus("Success", commandId, ec2ID, experimentsDetails.Region, experimentsDetails.ChaosDuration+experimentsDetails.Timeout, experimentsDetails.Delay); err != nil {
71-
return errors.Errorf("fail to send ssm command, err: %v", err)
71+
return stacktrace.Propagate(err, "failed to send ssm command")
7272
}
7373
common.SetTargets(ec2ID, "reverted", "EC2", chaosDetails)
7474

@@ -110,7 +110,7 @@ func InjectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
110110
log.Info("[Chaos]: Starting the ssm command")
111111
commandId, err := ssm.SendSSMCommand(experimentsDetails, instanceIDList)
112112
if err != nil {
113-
return errors.Errorf("fail to send ssm command, err: %v", err)
113+
return stacktrace.Propagate(err, "failed to send ssm command")
114114
}
115115
//prepare commands for abort recovery
116116
experimentsDetails.CommandIDs = append(experimentsDetails.CommandIDs, commandId)
@@ -119,22 +119,22 @@ func InjectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet
119119
//wait for the ssm command to get in running state
120120
log.Info("[Wait]: Waiting for the ssm command to get in InProgress state")
121121
if err := ssm.WaitForCommandStatus("InProgress", commandId, ec2ID, experimentsDetails.Region, experimentsDetails.ChaosDuration+experimentsDetails.Timeout, experimentsDetails.Delay); err != nil {
122-
return errors.Errorf("fail to start ssm command, err: %v", err)
122+
return stacktrace.Propagate(err, "failed to start ssm command")
123123
}
124124
}
125125

126126
// run the probes during chaos
127127
if len(resultDetails.ProbeDetails) != 0 {
128128
if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil {
129-
return err
129+
return stacktrace.Propagate(err, "failed to run probes")
130130
}
131131
}
132132

133133
for _, ec2ID := range instanceIDList {
134134
//wait for the ssm command to get succeeded in the given chaos duration
135135
log.Info("[Wait]: Waiting for the ssm command to get completed")
136136
if err := ssm.WaitForCommandStatus("Success", commandId, ec2ID, experimentsDetails.Region, experimentsDetails.ChaosDuration+experimentsDetails.Timeout, experimentsDetails.Delay); err != nil {
137-
return errors.Errorf("fail to send ssm command, err: %v", err)
137+
return stacktrace.Propagate(err, "failed to send ssm command")
138138
}
139139
}
140140

@@ -159,14 +159,14 @@ func AbortWatcher(experimentsDetails *experimentTypes.ExperimentDetails, abort c
159159
case len(experimentsDetails.CommandIDs) != 0:
160160
for _, commandId := range experimentsDetails.CommandIDs {
161161
if err := ssm.CancelCommand(commandId, experimentsDetails.Region); err != nil {
162-
log.Errorf("[Abort]: fail to cancle command, recovery failed, err: %v", err)
162+
log.Errorf("[Abort]: Failed to cancel command, recovery failed: %v", err)
163163
}
164164
}
165165
default:
166-
log.Info("[Abort]: No command found to cancle")
166+
log.Info("[Abort]: No SSM Command found to cancel")
167167
}
168168
if err := ssm.SSMDeleteDocument(experimentsDetails.DocumentName, experimentsDetails.Region); err != nil {
169-
log.Errorf("fail to delete ssm doc, err: %v", err)
169+
log.Errorf("Failed to delete ssm document: %v", err)
170170
}
171171
log.Info("[Abort]: Chaos Revert Completed")
172172
os.Exit(1)

chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
package ssm
22

33
import (
4+
"fmt"
45
"os"
56
"os/signal"
67
"strings"
78
"syscall"
89

910
"github.com/litmuschaos/litmus-go/chaoslib/litmus/aws-ssm-chaos/lib"
1011
experimentTypes "github.com/litmuschaos/litmus-go/pkg/aws-ssm/aws-ssm-chaos/types"
12+
"github.com/litmuschaos/litmus-go/pkg/cerrors"
1113
clients "github.com/litmuschaos/litmus-go/pkg/clients"
1214
"github.com/litmuschaos/litmus-go/pkg/cloud/aws/ssm"
1315
"github.com/litmuschaos/litmus-go/pkg/log"
1416
"github.com/litmuschaos/litmus-go/pkg/types"
1517
"github.com/litmuschaos/litmus-go/pkg/utils/common"
16-
"github.com/pkg/errors"
18+
"github.com/palantir/stacktrace"
1719
)
1820

1921
var (
2022
err error
2123
inject, abort chan os.Signal
2224
)
2325

24-
//PrepareAWSSSMChaosByID contains the prepration and injection steps for the experiment
26+
// PrepareAWSSSMChaosByID contains the prepration and injection steps for the experiment
2527
func PrepareAWSSSMChaosByID(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
2628

2729
// inject channel is used to transmit signal notifications.
@@ -42,7 +44,7 @@ func PrepareAWSSSMChaosByID(experimentsDetails *experimentTypes.ExperimentDetail
4244

4345
//create and upload the ssm document on the given aws service monitoring docs
4446
if err = ssm.CreateAndUploadDocument(experimentsDetails.DocumentName, experimentsDetails.DocumentType, experimentsDetails.DocumentFormat, experimentsDetails.DocumentPath, experimentsDetails.Region); err != nil {
45-
return errors.Errorf("fail to create and upload ssm doc, err: %v", err)
47+
return stacktrace.Propagate(err, "could not create and upload the ssm document")
4648
}
4749
experimentsDetails.IsDocsUploaded = true
4850
log.Info("[Info]: SSM docs uploaded successfully")
@@ -52,27 +54,27 @@ func PrepareAWSSSMChaosByID(experimentsDetails *experimentTypes.ExperimentDetail
5254

5355
//get the instance id or list of instance ids
5456
instanceIDList := strings.Split(experimentsDetails.EC2InstanceID, ",")
55-
if len(instanceIDList) == 0 {
56-
return errors.Errorf("no instance id found for chaos injection")
57+
if experimentsDetails.EC2InstanceID == "" || len(instanceIDList) == 0 {
58+
return cerrors.Error{ErrorCode: cerrors.ErrorTypeTargetSelection, Reason: "no instance id found for chaos injection"}
5759
}
5860

5961
switch strings.ToLower(experimentsDetails.Sequence) {
6062
case "serial":
6163
if err = lib.InjectChaosInSerialMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil {
62-
return err
64+
return stacktrace.Propagate(err, "could not run chaos in serial mode")
6365
}
6466
case "parallel":
6567
if err = lib.InjectChaosInParallelMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil {
66-
return err
68+
return stacktrace.Propagate(err, "could not run chaos in parallel mode")
6769
}
6870
default:
69-
return errors.Errorf("%v sequence is not supported", experimentsDetails.Sequence)
71+
return cerrors.Error{ErrorCode: cerrors.ErrorTypeTargetSelection, Reason: fmt.Sprintf("'%s' sequence is not supported", experimentsDetails.Sequence)}
7072
}
7173

7274
//Delete the ssm document on the given aws service monitoring docs
7375
err = ssm.SSMDeleteDocument(experimentsDetails.DocumentName, experimentsDetails.Region)
7476
if err != nil {
75-
return errors.Errorf("fail to delete ssm doc, err: %v", err)
77+
return stacktrace.Propagate(err, "failed to delete ssm doc")
7678
}
7779

7880
//Waiting for the ramp time after chaos injection

chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
package ssm
22

33
import (
4+
"fmt"
45
"os"
56
"os/signal"
67
"strings"
78
"syscall"
89

910
"github.com/litmuschaos/litmus-go/chaoslib/litmus/aws-ssm-chaos/lib"
1011
experimentTypes "github.com/litmuschaos/litmus-go/pkg/aws-ssm/aws-ssm-chaos/types"
12+
"github.com/litmuschaos/litmus-go/pkg/cerrors"
1113
clients "github.com/litmuschaos/litmus-go/pkg/clients"
1214
"github.com/litmuschaos/litmus-go/pkg/cloud/aws/ssm"
1315
"github.com/litmuschaos/litmus-go/pkg/log"
1416
"github.com/litmuschaos/litmus-go/pkg/types"
1517
"github.com/litmuschaos/litmus-go/pkg/utils/common"
16-
"github.com/pkg/errors"
18+
"github.com/palantir/stacktrace"
1719
)
1820

19-
//PrepareAWSSSMChaosByTag contains the prepration and injection steps for the experiment
21+
// PrepareAWSSSMChaosByTag contains the prepration and injection steps for the experiment
2022
func PrepareAWSSSMChaosByTag(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
2123

2224
// inject channel is used to transmit signal notifications.
@@ -37,7 +39,7 @@ func PrepareAWSSSMChaosByTag(experimentsDetails *experimentTypes.ExperimentDetai
3739

3840
//create and upload the ssm document on the given aws service monitoring docs
3941
if err = ssm.CreateAndUploadDocument(experimentsDetails.DocumentName, experimentsDetails.DocumentType, experimentsDetails.DocumentFormat, experimentsDetails.DocumentPath, experimentsDetails.Region); err != nil {
40-
return errors.Errorf("fail to create and upload ssm doc, err: %v", err)
42+
return stacktrace.Propagate(err, "could not create and upload the ssm document")
4143
}
4244
experimentsDetails.IsDocsUploaded = true
4345
log.Info("[Info]: SSM docs uploaded successfully")
@@ -48,26 +50,26 @@ func PrepareAWSSSMChaosByTag(experimentsDetails *experimentTypes.ExperimentDetai
4850
log.Infof("[Chaos]:Number of Instance targeted: %v", len(instanceIDList))
4951

5052
if len(instanceIDList) == 0 {
51-
return errors.Errorf("no instance id found for chaos injection")
53+
return cerrors.Error{ErrorCode: cerrors.ErrorTypeTargetSelection, Reason: "no instance id found for chaos injection"}
5254
}
5355

5456
switch strings.ToLower(experimentsDetails.Sequence) {
5557
case "serial":
5658
if err = lib.InjectChaosInSerialMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil {
57-
return err
59+
return stacktrace.Propagate(err, "could not run chaos in serial mode")
5860
}
5961
case "parallel":
6062
if err = lib.InjectChaosInParallelMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil {
61-
return err
63+
return stacktrace.Propagate(err, "could not run chaos in parallel mode")
6264
}
6365
default:
64-
return errors.Errorf("%v sequence is not supported", experimentsDetails.Sequence)
66+
return cerrors.Error{ErrorCode: cerrors.ErrorTypeTargetSelection, Reason: fmt.Sprintf("'%s' sequence is not supported", experimentsDetails.Sequence)}
6567
}
6668

6769
//Delete the ssm document on the given aws service monitoring docs
6870
err = ssm.SSMDeleteDocument(experimentsDetails.DocumentName, experimentsDetails.Region)
6971
if err != nil {
70-
return errors.Errorf("fail to delete ssm doc, err: %v", err)
72+
return stacktrace.Propagate(err, "failed to delete ssm doc")
7173
}
7274

7375
//Waiting for the ramp time after chaos injection

0 commit comments

Comments
 (0)