Skip to content

Commit

Permalink
(chore): Adding user-friendly failsteps and removing non-litmus libs (#…
Browse files Browse the repository at this point in the history
…626)

* feat(failstep):  Adding failstep in all experiment and removed non-litmus libs

Signed-off-by: Shubham Chaudhary <[email protected]>
  • Loading branch information
ispeakc0de authored Dec 15, 2022
1 parent eb98d50 commit 77b30e2
Show file tree
Hide file tree
Showing 218 changed files with 3,939 additions and 6,187 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18

- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- run: snyk auth ${SNYK_TOKEN}
- uses: actions/setup-go@v1
with:
go-version: '1.17'
go-version: '1.18'
- name: Snyk monitor
run: snyk test

Expand All @@ -60,7 +60,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18

- uses: actions/checkout@v2
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18
- uses: actions/checkout@v2

#TODO: Add Dockerfile linting
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18
- uses: actions/checkout@v2

- name: Set up QEMU
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18
- uses: actions/checkout@v2

#TODO: Add Dockerfile linting
Expand All @@ -30,7 +30,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18
- uses: actions/checkout@v2

- name: Set Tag
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run-e2e-on-pr-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.18'

- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -260,7 +260,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.18'

- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -302,7 +302,7 @@ jobs:
# Install golang
- uses: actions/setup-go@v2
with:
go-version: '1.17'
go-version: '1.18'

- uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Multi-stage docker build
# Build stage
FROM golang:1.17 AS builder
FROM golang:1.18 AS builder

ARG TARGETOS=linux
ARG TARGETARCH
Expand Down
24 changes: 12 additions & 12 deletions chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/litmuschaos/litmus-go/pkg/probe"
"github.com/litmuschaos/litmus-go/pkg/types"
"github.com/litmuschaos/litmus-go/pkg/utils/common"
"github.com/pkg/errors"
"github.com/palantir/stacktrace"
)

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

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

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

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

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

// run the probes during chaos
if len(resultDetails.ProbeDetails) != 0 {
if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil {
return err
return stacktrace.Propagate(err, "failed to run probes")
}
}

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

Expand All @@ -159,14 +159,14 @@ func AbortWatcher(experimentsDetails *experimentTypes.ExperimentDetails, abort c
case len(experimentsDetails.CommandIDs) != 0:
for _, commandId := range experimentsDetails.CommandIDs {
if err := ssm.CancelCommand(commandId, experimentsDetails.Region); err != nil {
log.Errorf("[Abort]: fail to cancle command, recovery failed, err: %v", err)
log.Errorf("[Abort]: Failed to cancel command, recovery failed: %v", err)
}
}
default:
log.Info("[Abort]: No command found to cancle")
log.Info("[Abort]: No SSM Command found to cancel")
}
if err := ssm.SSMDeleteDocument(experimentsDetails.DocumentName, experimentsDetails.Region); err != nil {
log.Errorf("fail to delete ssm doc, err: %v", err)
log.Errorf("Failed to delete ssm document: %v", err)
}
log.Info("[Abort]: Chaos Revert Completed")
os.Exit(1)
Expand Down
20 changes: 11 additions & 9 deletions chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
package ssm

import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"

"github.com/litmuschaos/litmus-go/chaoslib/litmus/aws-ssm-chaos/lib"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/aws-ssm/aws-ssm-chaos/types"
"github.com/litmuschaos/litmus-go/pkg/cerrors"
clients "github.com/litmuschaos/litmus-go/pkg/clients"
"github.com/litmuschaos/litmus-go/pkg/cloud/aws/ssm"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/types"
"github.com/litmuschaos/litmus-go/pkg/utils/common"
"github.com/pkg/errors"
"github.com/palantir/stacktrace"
)

var (
err error
inject, abort chan os.Signal
)

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

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

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

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

switch strings.ToLower(experimentsDetails.Sequence) {
case "serial":
if err = lib.InjectChaosInSerialMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil {
return err
return stacktrace.Propagate(err, "could not run chaos in serial mode")
}
case "parallel":
if err = lib.InjectChaosInParallelMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil {
return err
return stacktrace.Propagate(err, "could not run chaos in parallel mode")
}
default:
return errors.Errorf("%v sequence is not supported", experimentsDetails.Sequence)
return cerrors.Error{ErrorCode: cerrors.ErrorTypeTargetSelection, Reason: fmt.Sprintf("'%s' sequence is not supported", experimentsDetails.Sequence)}
}

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

//Waiting for the ramp time after chaos injection
Expand Down
18 changes: 10 additions & 8 deletions chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package ssm

import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"

"github.com/litmuschaos/litmus-go/chaoslib/litmus/aws-ssm-chaos/lib"
experimentTypes "github.com/litmuschaos/litmus-go/pkg/aws-ssm/aws-ssm-chaos/types"
"github.com/litmuschaos/litmus-go/pkg/cerrors"
clients "github.com/litmuschaos/litmus-go/pkg/clients"
"github.com/litmuschaos/litmus-go/pkg/cloud/aws/ssm"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/types"
"github.com/litmuschaos/litmus-go/pkg/utils/common"
"github.com/pkg/errors"
"github.com/palantir/stacktrace"
)

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

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

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

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

switch strings.ToLower(experimentsDetails.Sequence) {
case "serial":
if err = lib.InjectChaosInSerialMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil {
return err
return stacktrace.Propagate(err, "could not run chaos in serial mode")
}
case "parallel":
if err = lib.InjectChaosInParallelMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil {
return err
return stacktrace.Propagate(err, "could not run chaos in parallel mode")
}
default:
return errors.Errorf("%v sequence is not supported", experimentsDetails.Sequence)
return cerrors.Error{ErrorCode: cerrors.ErrorTypeTargetSelection, Reason: fmt.Sprintf("'%s' sequence is not supported", experimentsDetails.Sequence)}
}

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

//Waiting for the ramp time after chaos injection
Expand Down
Loading

0 comments on commit 77b30e2

Please sign in to comment.