From 1eaeda9af3efcc1bdb9a204ac621448be78853c0 Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Sat, 29 Jun 2024 23:48:25 +0900 Subject: [PATCH 01/12] feat: add otel & tracing for distributed tracing Signed-off-by: namkyu1999 --- bin/experiment/experiment.go | 22 +++- bin/helper/helper.go | 21 +++- build/Dockerfile | 2 +- chaoslib/litmus/pod-delete/lib/pod-delete.go | 12 +- .../pod-delete/experiment/pod-delete.go | 6 +- go.mod | 50 +++++--- go.sum | 114 +++++++++++++----- pkg/clients/clientset.go | 2 + pkg/probe/probe.go | 3 + pkg/telemetry/otel.go | 94 +++++++++++++++ pkg/telemetry/tracing.go | 36 ++++++ 11 files changed, 298 insertions(+), 64 deletions(-) create mode 100644 pkg/telemetry/otel.go create mode 100644 pkg/telemetry/tracing.go diff --git a/bin/experiment/experiment.go b/bin/experiment/experiment.go index 1a0be860f..32f62ea3f 100755 --- a/bin/experiment/experiment.go +++ b/bin/experiment/experiment.go @@ -1,6 +1,8 @@ package main import ( + "context" + "errors" "flag" // Uncomment to load all auth plugins // _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -59,9 +61,9 @@ import ( k6Loadgen "github.com/litmuschaos/litmus-go/experiments/load/k6-loadgen/experiment" springBootFaults "github.com/litmuschaos/litmus-go/experiments/spring-boot/spring-boot-faults/experiment" vmpoweroff "github.com/litmuschaos/litmus-go/experiments/vmware/vm-poweroff/experiment" - - "github.com/litmuschaos/litmus-go/pkg/clients" + cli "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/sirupsen/logrus" ) @@ -75,8 +77,22 @@ func init() { } func main() { + ctx := context.Background() + // Set up Observability. + shutdown, err := telemetry.InitOTelSDK(ctx, true) + if err != nil { + return + } + // Handle shutdown properly so nothing leaks. + defer func() { + err = errors.Join(err, shutdown(ctx)) + }() + + ctx = telemetry.GetTraceParentContext() + clients := cli.ClientSets{Context: ctx} - clients := clients.ClientSets{} + span := telemetry.StartTracing(clients, "ExecuteExperiment") + defer span.End() // parse the experiment name experimentName := flag.String("name", "pod-delete", "name of the chaos experiment") diff --git a/bin/helper/helper.go b/bin/helper/helper.go index 3958123c5..dd0aaa394 100644 --- a/bin/helper/helper.go +++ b/bin/helper/helper.go @@ -1,6 +1,8 @@ package main import ( + "context" + "errors" "flag" // Uncomment to load all auth plugins // _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -17,8 +19,9 @@ import ( networkChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/helper" dnsChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-dns-chaos/helper" stressChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/stress-chaos/helper" + "github.com/litmuschaos/litmus-go/pkg/telemetry" - "github.com/litmuschaos/litmus-go/pkg/clients" + cli "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/sirupsen/logrus" ) @@ -33,8 +36,22 @@ func init() { } func main() { + ctx := context.Background() + // Set up Observability. + shutdown, err := telemetry.InitOTelSDK(ctx, false) + if err != nil { + return + } + // Handle shutdown properly so nothing leaks. + defer func() { + err = errors.Join(err, shutdown(ctx)) + }() + + ctx = telemetry.GetTraceParentContext() + clients := cli.ClientSets{Context: ctx} - clients := clients.ClientSets{} + span := telemetry.StartTracing(clients, "ExecuteExperimentHelper") + defer span.End() // parse the helper name helperName := flag.String("name", "", "name of the helper pod") diff --git a/build/Dockerfile b/build/Dockerfile index e4ed59276..5aee190cd 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,6 +1,6 @@ # Multi-stage docker build # Build stage -FROM golang:1.18 AS builder +FROM golang:1.22 AS builder ARG TARGETOS=linux ARG TARGETARCH diff --git a/chaoslib/litmus/pod-delete/lib/pod-delete.go b/chaoslib/litmus/pod-delete/lib/pod-delete.go index a513beb31..f66981a91 100644 --- a/chaoslib/litmus/pod-delete/lib/pod-delete.go +++ b/chaoslib/litmus/pod-delete/lib/pod-delete.go @@ -8,23 +8,25 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" - "github.com/litmuschaos/litmus-go/pkg/workloads" - "github.com/palantir/stacktrace" - - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-delete/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" "github.com/litmuschaos/litmus-go/pkg/status" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" + "github.com/litmuschaos/litmus-go/pkg/workloads" + "github.com/palantir/stacktrace" "github.com/sirupsen/logrus" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// PreparePodDelete contains the prepration steps before chaos injection +// PreparePodDelete contains the preparation steps before chaos injection func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodDeleteChaos") + defer span.End() //Waiting for the ramp time before chaos injection if experimentsDetails.RampTime != 0 { diff --git a/experiments/generic/pod-delete/experiment/pod-delete.go b/experiments/generic/pod-delete/experiment/pod-delete.go index a5801ffef..7fcf048f9 100644 --- a/experiments/generic/pod-delete/experiment/pod-delete.go +++ b/experiments/generic/pod-delete/experiment/pod-delete.go @@ -1,6 +1,8 @@ package experiment import ( + "os" + "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-delete/lib" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -14,12 +16,10 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/sirupsen/logrus" - "os" ) // PodDelete inject the pod-delete chaos func PodDelete(clients clients.ClientSets) { - experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} eventsDetails := types.EventDetails{} @@ -58,7 +58,7 @@ func PodDelete(clients clients.ClientSets) { return } - // generating the event in chaosresult to marked the verdict as awaited + // generating the event in chaosresult to mark the verdict as awaited msg := "experiment: " + experimentsDetails.ExperimentName + ", Result: Awaited" types.SetResultEventAttributes(&eventsDetails, types.AwaitedVerdict, msg, "Normal", &resultDetails) if err := events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosResult"); err != nil { diff --git a/go.mod b/go.mod index 6fb4ea6f1..6fcc44871 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,11 @@ module github.com/litmuschaos/litmus-go -go 1.18 +go 1.22.0 require ( github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 - github.com/Azure/azure-sdk-for-go v56.1.0+incompatible - github.com/Azure/go-autorest/autorest v0.11.18 + github.com/Azure/azure-sdk-for-go v68.0.0+incompatible + github.com/Azure/go-autorest/autorest v0.11.29 github.com/Azure/go-autorest/autorest/azure/auth v0.5.7 github.com/aws/aws-sdk-go v1.38.59 github.com/containerd/cgroups v1.0.1 @@ -15,11 +15,15 @@ require ( github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.1.1 - github.com/stretchr/testify v1.7.0 + github.com/stretchr/testify v1.9.0 + go.opentelemetry.io/otel v1.27.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 + go.opentelemetry.io/otel/sdk v1.27.0 google.golang.org/api v0.48.0 gopkg.in/yaml.v2 v2.4.0 - k8s.io/api v0.26.0 - k8s.io/apimachinery v0.26.0 + k8s.io/api v0.30.1 + k8s.io/apimachinery v0.30.1 k8s.io/client-go v12.0.0+incompatible k8s.io/klog v1.0.0 ) @@ -27,28 +31,31 @@ require ( require ( cloud.google.com/go v0.83.0 // indirect github.com/Azure/go-autorest v14.2.0+incompatible // indirect - github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect + github.com/Azure/go-autorest/autorest/adal v0.9.22 // indirect github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect github.com/Azure/go-autorest/autorest/to v0.3.1-0.20191028180845-3492b2aff503 // indirect github.com/Azure/go-autorest/autorest/validation v0.2.1-0.20191028180845-3492b2aff503 // indirect github.com/Azure/go-autorest/logger v0.2.1 // indirect github.com/Azure/go-autorest/tracing v0.6.0 // indirect + github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/cilium/ebpf v0.6.2 // indirect github.com/coreos/go-systemd/v22 v22.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dimchansky/utfbom v1.1.1 // indirect github.com/docker/go-units v0.4.0 // indirect - github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect - github.com/go-logr/logr v1.2.3 // indirect + github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/stdr v1.2.2 // indirect github.com/godbus/dbus/v5 v5.0.4 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/protobuf v1.5.2 // indirect - github.com/google/go-cmp v0.5.6 // indirect + github.com/golang/protobuf v1.5.4 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.1.0 // indirect github.com/googleapis/gax-go/v2 v2.0.5 // indirect github.com/googleapis/gnostic v0.5.5 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect @@ -61,17 +68,20 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/pflag v1.0.5 // indirect go.opencensus.io v0.23.0 // indirect - golang.org/x/crypto v0.16.0 // indirect - golang.org/x/net v0.19.0 // indirect - golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c // indirect - golang.org/x/sys v0.15.0 // indirect - golang.org/x/term v0.15.0 // indirect - golang.org/x/text v0.14.0 // indirect + go.opentelemetry.io/otel/metric v1.27.0 // indirect + go.opentelemetry.io/otel/trace v1.27.0 // indirect + go.opentelemetry.io/proto/otlp v1.2.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/oauth2 v0.20.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/term v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect - google.golang.org/appengine v1.6.7 // indirect + google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto v0.0.0-20210604141403-392c879c8b08 // indirect - google.golang.org/grpc v1.38.0 // indirect - google.golang.org/protobuf v1.26.0 // indirect + google.golang.org/grpc v1.64.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/klog/v2 v2.80.1 // indirect diff --git a/go.sum b/go.sum index 9b928037f..61663d25c 100644 --- a/go.sum +++ b/go.sum @@ -41,21 +41,21 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= -github.com/Azure/azure-sdk-for-go v56.1.0+incompatible h1:Ofcecdw3F1ZqnpDEZcLzH9Hq0P4Y5Si8+EioXJSamJs= -github.com/Azure/azure-sdk-for-go v56.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= +github.com/Azure/azure-sdk-for-go v68.0.0+incompatible h1:fcYLmCpyNYRnvJbPerq7U0hS+6+I79yEDJBqVNcqUzU= +github.com/Azure/azure-sdk-for-go v68.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs= github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI= github.com/Azure/go-autorest/autorest v0.11.12/go.mod h1:eipySxLmqSyC5s5k1CLupqet0PSENBEDP93LQ9a8QYw= github.com/Azure/go-autorest/autorest v0.11.17/go.mod h1:eipySxLmqSyC5s5k1CLupqet0PSENBEDP93LQ9a8QYw= -github.com/Azure/go-autorest/autorest v0.11.18 h1:90Y4srNYrwOtAgVo3ndrQkTYn6kf1Eg/AjTFJ8Is2aM= -github.com/Azure/go-autorest/autorest v0.11.18/go.mod h1:dSiJPy22c3u0OtOKDNttNgqpNFY/GeWa7GH/Pz56QRA= +github.com/Azure/go-autorest/autorest v0.11.29 h1:I4+HL/JDvErx2LjyzaVxllw2lRDB5/BT2Bm4g20iqYw= +github.com/Azure/go-autorest/autorest v0.11.29/go.mod h1:ZtEzC4Jy2JDrZLxvWs8LrBWEBycl1hbT1eknI8MtfAs= github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0= github.com/Azure/go-autorest/autorest/adal v0.9.5/go.mod h1:B7KF7jKIeC9Mct5spmyCB/A8CG/sEz1vwIRGv/bbw7A= github.com/Azure/go-autorest/autorest/adal v0.9.11/go.mod h1:nBKAnTomx8gDtl+3ZCJv2v0KACFHWTB2drffI1B68Pk= -github.com/Azure/go-autorest/autorest/adal v0.9.13 h1:Mp5hbtOePIzM8pJVRa3YLrWWmZtoxRXqUEzCfJt3+/Q= -github.com/Azure/go-autorest/autorest/adal v0.9.13/go.mod h1:W/MM4U6nLxnIskrw4UwWzlHfGjwUS50aOsc/I3yuU8M= +github.com/Azure/go-autorest/autorest/adal v0.9.22 h1:/GblQdIudfEM3AWWZ0mrYJQSd7JS4S/Mbzh6F0ov0Xc= +github.com/Azure/go-autorest/autorest/adal v0.9.22/go.mod h1:XuAbAEUv2Tta//+voMI038TrJBqjKam0me7qR+L8Cmk= github.com/Azure/go-autorest/autorest/azure/auth v0.5.7 h1:8DQB8yl7aLQuP+nuR5e2RO6454OvFlSTXXaNHshc16s= github.com/Azure/go-autorest/autorest/azure/auth v0.5.7/go.mod h1:AkzUsqkrdmNhfP2i54HqINVQopw0CLDnvHpJ88Zz1eI= github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 h1:dMOmEJfkLKW/7JsokJqkyoYSgmR08hi9KrhjZb+JALY= @@ -65,8 +65,9 @@ github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8K github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74= github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0= -github.com/Azure/go-autorest/autorest/mocks v0.4.1 h1:K0laFcLE6VLTOwNgSxaGbUcLPuGXlNkbVvq4cW4nIHk= github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k= +github.com/Azure/go-autorest/autorest/mocks v0.4.2 h1:PGN4EDXnuQbojHbU0UWoNvmu9AGVwYHG9/fkDYhtAfw= +github.com/Azure/go-autorest/autorest/mocks v0.4.2/go.mod h1:Vy7OitM9Kei0i1Oj+LvyAWMXJHeKH1MVlzFugfVrmyU= github.com/Azure/go-autorest/autorest/to v0.3.1-0.20191028180845-3492b2aff503 h1:2McfZNaDqGPjv2pddK547PENIk4HV+NT7gvqRq4L0us= github.com/Azure/go-autorest/autorest/to v0.3.1-0.20191028180845-3492b2aff503/go.mod h1:MgwOyqaIuKdG4TL/2ywSsIWKAfJfgHDo8ObuUk3t5sA= github.com/Azure/go-autorest/autorest/validation v0.2.1-0.20191028180845-3492b2aff503 h1:RBrGlrkPWapMcLp1M6ywCqyYKOAT5ERI6lYFvGKOThE= @@ -103,6 +104,8 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= +github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= +github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -165,8 +168,6 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= -github.com/form3tech-oss/jwt-go v3.2.3+incompatible h1:7ZaBxOI7TMoYBfyA3cQHErNNyAWIKUMIwqxEtgHOs5c= -github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY= github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -186,8 +187,11 @@ github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7 github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= -github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/zapr v0.4.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk= github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= @@ -206,6 +210,9 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -238,8 +245,9 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= -github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -254,8 +262,9 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -295,6 +304,8 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -349,8 +360,9 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxv github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -452,6 +464,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= @@ -488,8 +502,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -501,6 +516,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= @@ -513,10 +529,26 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= +go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= +go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 h1:R9DE4kQ4k+YtfLI2ULwX82VtNQ2J8yZmA7ZIF/D+7Mc= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0/go.mod h1:OQFyQVrDlbe+R7xrEyDr/2Wr67Ol0hRUgsfA+V5A95s= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ= +go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= +go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak= +go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI= +go.opentelemetry.io/otel/sdk v1.27.0/go.mod h1:Ha9vbLwJE6W86YstIywK2xFfPjbWlCuwPtMkKdz/Y4A= +go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw= +go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4= +go.opentelemetry.io/proto/otlp v1.2.0 h1:pVeZGk7nXDC9O2hncA6nHldxEjm6LByfA2aN8IOkz94= +go.opentelemetry.io/proto/otlp v1.2.0/go.mod h1:gGpR8txAl5M03pDhMC79G6SdqNV26naRm/KDsgaHD8A= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= @@ -532,8 +564,11 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -570,6 +605,7 @@ golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hM golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -616,8 +652,11 @@ golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLd golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -629,8 +668,9 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c h1:pkQiBZBvdos9qq4wBAHqlzuZHEXo07pqV06ef90u1WI= golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= +golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -642,6 +682,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -703,14 +744,20 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210817190340-bfb29a6856f2/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= -golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -719,8 +766,11 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -786,10 +836,10 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gomodules.xyz/jsonpatch/v2 v2.2.0/go.mod h1:WXp+iVDkoLQqPudfQ9GBlwB2eZ5DKOnjQZCYdOS8GPY= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= @@ -822,8 +872,9 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= @@ -889,8 +940,9 @@ google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.37.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/grpc v1.37.1/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= -google.golang.org/grpc v1.38.0 h1:/9BgsAsa5nWe26HqOlvlgJnqBuktYOLCgjCPqsa56W0= google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= @@ -903,14 +955,16 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/pkg/clients/clientset.go b/pkg/clients/clientset.go index 5cc252638..6d7cfee22 100644 --- a/pkg/clients/clientset.go +++ b/pkg/clients/clientset.go @@ -1,6 +1,7 @@ package clients import ( + "context" "flag" chaosClient "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1" @@ -20,6 +21,7 @@ type ClientSets struct { LitmusClient *chaosClient.LitmuschaosV1alpha1Client KubeConfig *rest.Config DynamicClient dynamic.Interface + Context context.Context } // GenerateClientSetFromKubeConfig will generation both ClientSets (k8s, and Litmus) as well as the KubeConfig diff --git a/pkg/probe/probe.go b/pkg/probe/probe.go index 909bdaeca..4ca818b40 100644 --- a/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -13,6 +13,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/palantir/stacktrace" "github.com/sirupsen/logrus" @@ -24,6 +25,8 @@ var err error // RunProbes contains the steps to trigger the probes // It contains steps to trigger all three probes: k8sprobe, httpprobe, cmdprobe func RunProbes(chaosDetails *types.ChaosDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, phase string, eventsDetails *types.EventDetails) error { + span := telemetry.StartTracing(clients, "RunProbes") + defer span.End() // get the probes details from the chaosengine probes, err := getProbesFromChaosEngine(chaosDetails, clients) diff --git a/pkg/telemetry/otel.go b/pkg/telemetry/otel.go new file mode 100644 index 000000000..b5339c71f --- /dev/null +++ b/pkg/telemetry/otel.go @@ -0,0 +1,94 @@ +package telemetry + +import ( + "context" + "errors" + "os" + + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/sdk/resource" + "go.opentelemetry.io/otel/sdk/trace" + semconv "go.opentelemetry.io/otel/semconv/v1.25.0" +) + +const ( + OTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT" + OTELExperimentJobServiceName = "chaos_experiment_job" + OTELExperimentJobHelperServiceName = "chaos_experiment_job_helper" +) + +func InitOTelSDK(ctx context.Context, isExperiment bool) (shutdown func(context.Context) error, err error) { + var shutdownFuncs []func(context.Context) error + + shutdown = func(ctx context.Context) error { + var err error + for _, fn := range shutdownFuncs { + err = errors.Join(err, fn(ctx)) + } + shutdownFuncs = nil + return err + } + + handleErr := func(inErr error) { + err = errors.Join(inErr, shutdown(ctx)) + } + + tracerProvider, err := newTracerProvider(ctx, isExperiment) + if err != nil { + handleErr(err) + return + } + + prop := newPropagator() + otel.SetTextMapPropagator(prop) + + shutdownFuncs = append(shutdownFuncs, tracerProvider.Shutdown) + otel.SetTracerProvider(tracerProvider) + + // TODO: need to add metrics & logging provider + return +} + +func newPropagator() propagation.TextMapPropagator { + return propagation.NewCompositeTextMapPropagator( + propagation.TraceContext{}, + propagation.Baggage{}, + ) +} + +func newTracerProvider(ctx context.Context, isExperiment bool) (*trace.TracerProvider, error) { + endpoint := os.Getenv(OTELExporterOTLPEndpoint) + serviceName := OTELExperimentJobHelperServiceName + if isExperiment { + serviceName = OTELExperimentJobServiceName + + } + res, err := resource.New(ctx, + resource.WithAttributes( + semconv.ServiceNameKey.String(serviceName), + ), + ) + traceExporter, err := otlptrace.New( + ctx, + otlptracegrpc.NewClient( + // TODO: add secure option + otlptracegrpc.WithInsecure(), + otlptracegrpc.WithEndpoint(endpoint), + ), + ) + if err != nil { + return nil, err + } + + batchSpanProcessor := trace.NewBatchSpanProcessor(traceExporter) + tracerProvider := trace.NewTracerProvider( + trace.WithSampler(trace.AlwaysSample()), + trace.WithResource(res), + trace.WithSpanProcessor(batchSpanProcessor), + ) + + return tracerProvider, nil +} diff --git a/pkg/telemetry/tracing.go b/pkg/telemetry/tracing.go new file mode 100644 index 000000000..2ada6f0e2 --- /dev/null +++ b/pkg/telemetry/tracing.go @@ -0,0 +1,36 @@ +package telemetry + +import ( + "context" + "encoding/json" + "os" + + "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/log" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" +) + +const ( + TracerName = "litmuschaos.io/litmus-go" + TraceParent = "TRACE_PARENT" +) + +func StartTracing(clients clients.ClientSets, spanName string) trace.Span { + ctx, span := otel.Tracer(TracerName).Start(clients.Context, spanName) + clients.Context = ctx + return span +} + +func GetTraceParentContext() context.Context { + traceParent := os.Getenv(TraceParent) + + pro := otel.GetTextMapPropagator() + carrier := make(map[string]string) + if err := json.Unmarshal([]byte(traceParent), &carrier); err != nil { + log.Fatal(err.Error()) + } + + return pro.Extract(context.Background(), propagation.MapCarrier(carrier)) +} From 1414368be7cf9600747cfa026e353ac3338e63de Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Tue, 2 Jul 2024 12:18:04 +0900 Subject: [PATCH 02/12] feat: add tracing codes to chaslib Signed-off-by: namkyu1999 --- .../lib/ssm/aws-ssm-chaos-by-id.go | 5 +++- .../lib/ssm/aws-ssm-chaos-by-tag.go | 5 +++- .../azure-disk-loss/lib/azure-disk-loss.go | 5 +++- .../lib/azure-instance-stop.go | 5 +++- .../container-kill/lib/container-kill.go | 14 ++++++++--- chaoslib/litmus/disk-fill/lib/disk-fill.go | 14 ++++++++--- .../lib/docker-service-kill.go | 7 +++++- .../lib/ebs-loss-by-id/lib/ebs-loss-by-id.go | 5 +++- .../ebs-loss-by-tag/lib/ebs-loss-by-tag.go | 5 +++- .../lib/ec2-terminate-by-id.go | 5 +++- .../lib/ec2-terminate-by-tag.go | 5 +++- .../lib/gcp-vm-disk-loss-by-label.go | 5 +++- .../gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go | 5 +++- .../lib/gcp-vm-instance-stop-by-label.go | 5 +++- .../lib/gcp-vm-instance-stop.go | 5 +++- .../litmus/http-chaos/lib/header/header.go | 5 +++- chaoslib/litmus/http-chaos/lib/http-chaos.go | 12 +++++++--- .../litmus/http-chaos/lib/latency/latency.go | 5 +++- .../http-chaos/lib/modify-body/modify-body.go | 5 +++- chaoslib/litmus/http-chaos/lib/reset/reset.go | 5 +++- .../http-chaos/lib/statuscode/status-code.go | 8 +++++-- chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go | 7 ++++++ .../lib/pod-delete.go | 5 +++- .../lib/kubelet-service-kill.go | 7 +++++- .../lib/corruption/corruption.go | 5 +++- .../lib/duplication/duplication.go | 5 +++- .../network-chaos/lib/latency/latency.go | 5 +++- .../litmus/network-chaos/lib/loss/loss.go | 5 +++- .../litmus/network-chaos/lib/network-chaos.go | 12 +++++++--- .../litmus/node-cpu-hog/lib/node-cpu-hog.go | 7 +++++- chaoslib/litmus/node-drain/lib/node-drain.go | 10 +++++--- .../node-io-stress/lib/node-io-stress.go | 9 ++++--- .../node-memory-hog/lib/node-memory-hog.go | 7 +++++- .../litmus/node-restart/lib/node-restart.go | 7 +++++- chaoslib/litmus/node-taint/lib/node-taint.go | 10 +++++--- .../pod-autoscaler/lib/pod-autoscaler.go | 10 +++++--- .../pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go | 11 +++++---- .../litmus/pod-dns-chaos/lib/pod-dns-chaos.go | 16 +++++++++---- .../pod-fio-stress/lib/pod-fio-stress.go | 5 +++- .../lib/pod-memory-hog-exec.go | 5 +++- .../lib/pod-network-partition.go | 3 +++ .../lib/redfish-node-restart.go | 5 +++- .../lib/spring-boot-chaos.go | 4 ++++ .../litmus/stress-chaos/lib/stress-chaos.go | 15 ++++++++---- .../litmus/vm-poweroff/lib/vm-poweroff.go | 6 +++-- pkg/telemetry/tracing.go | 24 +++++++++++++++++++ 46 files changed, 270 insertions(+), 70 deletions(-) diff --git a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go index 0eb99d158..9ad3c6d0a 100644 --- a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go +++ b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go @@ -10,9 +10,10 @@ import ( "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/clients" "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ssm" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -25,6 +26,8 @@ var ( // 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 { + span := telemetry.StartTracing(clients, "InjectAWSSSMChaosByIDChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go index 99884e697..f323ac08c 100644 --- a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go +++ b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go @@ -10,9 +10,10 @@ import ( "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/clients" "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ssm" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -20,6 +21,8 @@ import ( // 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 { + span := telemetry.StartTracing(clients, "InjectAWSSSMChaosByTagChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go b/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go index aa2c16ee8..6fe2686db 100644 --- a/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go +++ b/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go @@ -11,12 +11,13 @@ import ( "github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute" experimentTypes "github.com/litmuschaos/litmus-go/pkg/azure/disk-loss/types" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" diskStatus "github.com/litmuschaos/litmus-go/pkg/cloud/azure/disk" instanceStatus "github.com/litmuschaos/litmus-go/pkg/cloud/azure/instance" "github.com/litmuschaos/litmus-go/pkg/events" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/litmuschaos/litmus-go/pkg/utils/retry" @@ -30,6 +31,8 @@ var ( // PrepareChaos contains the prepration and injection steps for the experiment func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectAzureDiskLossChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go b/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go index 8b3950da7..7bdfc9ecc 100644 --- a/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go +++ b/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go @@ -10,12 +10,13 @@ import ( experimentTypes "github.com/litmuschaos/litmus-go/pkg/azure/instance-stop/types" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" azureCommon "github.com/litmuschaos/litmus-go/pkg/cloud/azure/common" azureStatus "github.com/litmuschaos/litmus-go/pkg/cloud/azure/instance" "github.com/litmuschaos/litmus-go/pkg/events" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -28,6 +29,8 @@ var ( // PrepareAzureStop will initialize instanceNameList and start chaos injection based on sequence method selected func PrepareAzureStop(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectAzureInstanceStopChaos") + defer span.End() // inject channel is used to transmit signal notifications inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/container-kill/lib/container-kill.go b/chaoslib/litmus/container-kill/lib/container-kill.go index 028e1301e..95ee47c83 100644 --- a/chaoslib/litmus/container-kill/lib/container-kill.go +++ b/chaoslib/litmus/container-kill/lib/container-kill.go @@ -3,13 +3,15 @@ package lib import ( "context" "fmt" + "os" "strconv" "strings" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/container-kill/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" @@ -24,6 +26,8 @@ import ( // PrepareContainerKill contains the preparation steps before chaos injection func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectContainerKillChaos") + defer span.End() var err error // Get the target pod details for the chaos execution @@ -188,6 +192,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { + span := telemetry.StartTracing(clients, "CreateContainerKillHelperPod") + defer span.End() privilegedEnable := false if experimentsDetails.ContainerRuntime == "crio" { @@ -231,7 +237,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name container-kill", }, Resources: chaosDetails.Resources, - Env: getPodEnv(experimentsDetails, targets), + Env: getPodEnv(clients.Context, experimentsDetails, targets), VolumeMounts: []apiv1.VolumeMount{ { Name: "cri-socket", @@ -259,7 +265,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie } // getPodEnv derive all the env required for the helper pod -func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets string) []apiv1.EnvVar { +func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targets string) []apiv1.EnvVar { var envDetails common.ENVDetails envDetails.SetEnv("TARGETS", targets). @@ -275,6 +281,8 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets st SetEnv("STATUS_CHECK_TIMEOUT", strconv.Itoa(experimentsDetails.Timeout)). SetEnv("EXPERIMENT_NAME", experimentsDetails.ExperimentName). SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") return envDetails.ENV diff --git a/chaoslib/litmus/disk-fill/lib/disk-fill.go b/chaoslib/litmus/disk-fill/lib/disk-fill.go index 6c261bab2..a712ca3e0 100644 --- a/chaoslib/litmus/disk-fill/lib/disk-fill.go +++ b/chaoslib/litmus/disk-fill/lib/disk-fill.go @@ -3,13 +3,15 @@ package lib import ( "context" "fmt" + "os" "strconv" "strings" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" @@ -25,6 +27,8 @@ import ( // PrepareDiskFill contains the preparation steps before chaos injection func PrepareDiskFill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectDiskFillChaos") + defer span.End() var err error // It will contain all the pod & container details required for exec command @@ -197,6 +201,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, appNodeName, runID string) error { + span := telemetry.StartTracing(clients, "CreateDiskFillHelperPod") + defer span.End() privilegedEnable := true terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) @@ -239,7 +245,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name disk-fill", }, Resources: chaosDetails.Resources, - Env: getPodEnv(experimentsDetails, targets), + Env: getPodEnv(clients.Context, experimentsDetails, targets), VolumeMounts: []apiv1.VolumeMount{ { Name: "socket-path", @@ -267,7 +273,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie } // getPodEnv derive all the env required for the helper pod -func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets string) []apiv1.EnvVar { +func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targets string) []apiv1.EnvVar { var envDetails common.ENVDetails envDetails.SetEnv("TARGETS", targets). @@ -283,6 +289,8 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets st SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). SetEnv("SOCKET_PATH", experimentsDetails.SocketPath). SetEnv("CONTAINER_RUNTIME", experimentsDetails.ContainerRuntime). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") return envDetails.ENV diff --git a/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go b/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go index 6dd00f342..49df6a15a 100644 --- a/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go +++ b/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go @@ -6,9 +6,10 @@ import ( "strconv" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/docker-service-kill/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -24,6 +25,8 @@ import ( // PrepareDockerServiceKill contains prepration steps before chaos injection func PrepareDockerServiceKill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectDockerServiceKillChaos") + defer span.End() var err error if experimentsDetails.TargetNode == "" { @@ -111,6 +114,8 @@ func PrepareDockerServiceKill(experimentsDetails *experimentTypes.ExperimentDeta // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, appNodeName string) error { + span := telemetry.StartTracing(clients, "CreateDockerServiceKillHelperPod") + defer span.End() privileged := true terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go index b21a24de4..6b3f12fa6 100644 --- a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go +++ b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go @@ -9,9 +9,10 @@ import ( ebsloss "github.com/litmuschaos/litmus-go/chaoslib/litmus/ebs-loss/lib" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/kube-aws/ebs-loss/types" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -24,6 +25,8 @@ var ( // PrepareEBSLossByID contains the prepration and injection steps for the experiment func PrepareEBSLossByID(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectEBSLossByIDChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go index 0b2039c3e..4eb9addf6 100644 --- a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go +++ b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go @@ -9,9 +9,10 @@ import ( ebsloss "github.com/litmuschaos/litmus-go/chaoslib/litmus/ebs-loss/lib" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/kube-aws/ebs-loss/types" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -24,6 +25,8 @@ var ( // PrepareEBSLossByTag contains the prepration and injection steps for the experiment func PrepareEBSLossByTag(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectEBSLossByTagChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go b/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go index 2472b9467..c9978907a 100644 --- a/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go +++ b/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go @@ -9,12 +9,13 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" awslib "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ec2" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/kube-aws/ec2-terminate-by-id/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -27,6 +28,8 @@ var ( // PrepareEC2TerminateByID contains the prepration and injection steps for the experiment func PrepareEC2TerminateByID(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectEC2TerminateByIDChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go b/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go index 25e1b3a00..1332fc39c 100644 --- a/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go +++ b/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go @@ -9,12 +9,13 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" awslib "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ec2" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/kube-aws/ec2-terminate-by-tag/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -25,6 +26,8 @@ var inject, abort chan os.Signal // PrepareEC2TerminateByTag contains the prepration and injection steps for the experiment func PrepareEC2TerminateByTag(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectEC2TerminateByTagChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go b/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go index fb6dff6b7..6648f052f 100644 --- a/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go +++ b/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go @@ -9,12 +9,13 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/cloud/gcp" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/gcp/gcp-vm-disk-loss/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -28,6 +29,8 @@ var ( // PrepareDiskVolumeLossByLabel contains the prepration and injection steps for the experiment func PrepareDiskVolumeLossByLabel(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectDiskVolumeLossByLabelChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go b/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go index 38f06901e..3941b6f8a 100644 --- a/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go +++ b/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go @@ -10,11 +10,12 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/clients" - gcp "github.com/litmuschaos/litmus-go/pkg/cloud/gcp" + "github.com/litmuschaos/litmus-go/pkg/cloud/gcp" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/gcp/gcp-vm-disk-loss/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -29,6 +30,8 @@ var ( // PrepareDiskVolumeLoss contains the prepration and injection steps for the experiment func PrepareDiskVolumeLoss(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectVMDiskLossChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go b/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go index ca5eb4c0c..b7e8fb149 100644 --- a/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go +++ b/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go @@ -9,12 +9,13 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" gcplib "github.com/litmuschaos/litmus-go/pkg/cloud/gcp" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/gcp/gcp-vm-instance-stop/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -25,6 +26,8 @@ var inject, abort chan os.Signal // PrepareVMStopByLabel executes the experiment steps by injecting chaos into target VM instances func PrepareVMStopByLabel(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectVMInstanceStopByLabelChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go b/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go index 2cbcfdba4..b3569cf71 100644 --- a/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go +++ b/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go @@ -9,12 +9,13 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" gcplib "github.com/litmuschaos/litmus-go/pkg/cloud/gcp" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/gcp/gcp-vm-instance-stop/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -28,6 +29,8 @@ var ( // PrepareVMStop contains the prepration and injection steps for the experiment func PrepareVMStop(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectVMInstanceStopChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/http-chaos/lib/header/header.go b/chaoslib/litmus/http-chaos/lib/header/header.go index 60e63ec81..95bef093a 100644 --- a/chaoslib/litmus/http-chaos/lib/header/header.go +++ b/chaoslib/litmus/http-chaos/lib/header/header.go @@ -2,15 +2,18 @@ package header import ( http_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/sirupsen/logrus" ) // PodHttpModifyHeaderChaos contains the steps to prepare and inject http modify header chaos func PodHttpModifyHeaderChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodHTTPModifyHeaderChaos") + defer span.End() log.InfoWithValues("[Info]: The chaos tunables are:", logrus.Fields{ "Target Port": experimentsDetails.TargetServicePort, diff --git a/chaoslib/litmus/http-chaos/lib/http-chaos.go b/chaoslib/litmus/http-chaos/lib/http-chaos.go index 9bf398091..3c90b0715 100644 --- a/chaoslib/litmus/http-chaos/lib/http-chaos.go +++ b/chaoslib/litmus/http-chaos/lib/http-chaos.go @@ -3,13 +3,15 @@ package lib import ( "context" "fmt" + "os" "strconv" "strings" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" @@ -187,6 +189,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID, args string) error { + span := telemetry.StartTracing(clients, "InjectHTTPChaosHelperPod") + defer span.End() privilegedEnable := true terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) @@ -229,7 +233,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name http-chaos", }, Resources: chaosDetails.Resources, - Env: getPodEnv(experimentsDetails, targets, args), + Env: getPodEnv(clients.Context, experimentsDetails, targets, args), VolumeMounts: []apiv1.VolumeMount{ { Name: "cri-socket", @@ -263,7 +267,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie } // getPodEnv derive all the env required for the helper pod -func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets, args string) []apiv1.EnvVar { +func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targets, args string) []apiv1.EnvVar { var envDetails common.ENVDetails envDetails.SetEnv("TARGETS", targets). @@ -279,6 +283,8 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets, a SetEnv("TARGET_SERVICE_PORT", strconv.Itoa(experimentsDetails.TargetServicePort)). SetEnv("PROXY_PORT", strconv.Itoa(experimentsDetails.ProxyPort)). SetEnv("TOXICITY", strconv.Itoa(experimentsDetails.Toxicity)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") return envDetails.ENV diff --git a/chaoslib/litmus/http-chaos/lib/latency/latency.go b/chaoslib/litmus/http-chaos/lib/latency/latency.go index cb96672ce..24df1a4f2 100644 --- a/chaoslib/litmus/http-chaos/lib/latency/latency.go +++ b/chaoslib/litmus/http-chaos/lib/latency/latency.go @@ -4,15 +4,18 @@ import ( "strconv" http_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/sirupsen/logrus" ) // PodHttpLatencyChaos contains the steps to prepare and inject http latency chaos func PodHttpLatencyChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodHTTPLatencyChaos") + defer span.End() log.InfoWithValues("[Info]: The chaos tunables are:", logrus.Fields{ "Target Port": experimentsDetails.TargetServicePort, diff --git a/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go b/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go index bce1d26f1..7a5980c6f 100644 --- a/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go +++ b/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go @@ -6,15 +6,18 @@ import ( "strings" http_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/sirupsen/logrus" ) // PodHttpModifyBodyChaos contains the steps to prepare and inject http modify body chaos func PodHttpModifyBodyChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodHTTPModifyBodyChaos") + defer span.End() // responseBodyMaxLength defines the max length of response body string to be printed. It is taken as // the min of length of body and 120 characters to avoid printing large response body. diff --git a/chaoslib/litmus/http-chaos/lib/reset/reset.go b/chaoslib/litmus/http-chaos/lib/reset/reset.go index 8a0f7691e..3b10245cb 100644 --- a/chaoslib/litmus/http-chaos/lib/reset/reset.go +++ b/chaoslib/litmus/http-chaos/lib/reset/reset.go @@ -4,15 +4,18 @@ import ( "strconv" http_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/sirupsen/logrus" ) // PodHttpResetPeerChaos contains the steps to prepare and inject http reset peer chaos func PodHttpResetPeerChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodHTTPResetPeerChaos") + defer span.End() log.InfoWithValues("[Info]: The chaos tunables are:", logrus.Fields{ "Target Port": experimentsDetails.TargetServicePort, diff --git a/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go b/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go index be541f7f1..9c00c0ae9 100644 --- a/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go +++ b/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go @@ -2,16 +2,18 @@ package statuscode import ( "fmt" - "github.com/litmuschaos/litmus-go/pkg/cerrors" "math" "math/rand" "strconv" "strings" "time" + "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" + http_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib" body "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib/modify-body" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/types" @@ -27,6 +29,8 @@ var acceptedStatusCodes = []string{ // PodHttpStatusCodeChaos contains the steps to prepare and inject http status code chaos func PodHttpStatusCodeChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodHTTPStatusCodeChaos") + defer span.End() // responseBodyMaxLength defines the max length of response body string to be printed. It is taken as // the min of length of body and 120 characters to avoid printing large response body. diff --git a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go index aa33f4528..0ed8420b4 100644 --- a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go +++ b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go @@ -12,6 +12,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" "github.com/litmuschaos/litmus-go/pkg/status" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/litmuschaos/litmus-go/pkg/utils/stringutils" @@ -69,6 +70,9 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, // PrepareChaos contains the preparation steps before chaos injection func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectK6LoadGenChaos") + defer span.End() + // Waiting for the ramp time before chaos injection if experimentsDetails.RampTime != 0 { log.Infof("[Ramp]: Waiting for the %vs ramp time before injecting chaos", experimentsDetails.RampTime) @@ -90,6 +94,9 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, runID string) error { + span := telemetry.StartTracing(clients, "CreateK6LoadGenHelperPod") + defer span.End() + const volumeName = "script-volume" const mountPath = "/mnt" helperPod := &corev1.Pod{ diff --git a/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go b/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go index 9a78b1896..98420c431 100644 --- a/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go +++ b/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go @@ -8,10 +8,11 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/workloads" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/kafka/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -25,6 +26,8 @@ import ( // PreparePodDelete contains the prepration steps before chaos injection func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectKafkaPodDeleteChaos") + defer span.End() //Waiting for the ramp time before chaos injection if experimentsDetails.ChaoslibDetail.RampTime != 0 { diff --git a/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go b/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go index 8de74c5ce..283d7ac12 100644 --- a/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go +++ b/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go @@ -6,9 +6,10 @@ import ( "strconv" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/kubelet-service-kill/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -24,6 +25,8 @@ import ( // PrepareKubeletKill contains prepration steps before chaos injection func PrepareKubeletKill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectKubeletServiceKillChaos") + defer span.End() var err error if experimentsDetails.TargetNode == "" { @@ -113,6 +116,8 @@ func PrepareKubeletKill(experimentsDetails *experimentTypes.ExperimentDetails, c // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, appNodeName string) error { + span := telemetry.StartTracing(clients, "CreateKubeletServiceKillHelperPod") + defer span.End() privileged := true terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/network-chaos/lib/corruption/corruption.go b/chaoslib/litmus/network-chaos/lib/corruption/corruption.go index c63d7d600..cd855dac1 100644 --- a/chaoslib/litmus/network-chaos/lib/corruption/corruption.go +++ b/chaoslib/litmus/network-chaos/lib/corruption/corruption.go @@ -2,13 +2,16 @@ package corruption import ( network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" ) // PodNetworkCorruptionChaos contains the steps to prepare and inject chaos func PodNetworkCorruptionChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodNetworkCorruptionChaos") + defer span.End() args := "corrupt " + experimentsDetails.NetworkPacketCorruptionPercentage return network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) diff --git a/chaoslib/litmus/network-chaos/lib/duplication/duplication.go b/chaoslib/litmus/network-chaos/lib/duplication/duplication.go index 8e6753fa1..0d42d2ab4 100644 --- a/chaoslib/litmus/network-chaos/lib/duplication/duplication.go +++ b/chaoslib/litmus/network-chaos/lib/duplication/duplication.go @@ -2,13 +2,16 @@ package duplication import ( network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" ) // PodNetworkDuplicationChaos contains the steps to prepare and inject chaos func PodNetworkDuplicationChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodNetworkDuplicationChaos") + defer span.End() args := "duplicate " + experimentsDetails.NetworkPacketDuplicationPercentage return network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) diff --git a/chaoslib/litmus/network-chaos/lib/latency/latency.go b/chaoslib/litmus/network-chaos/lib/latency/latency.go index 1e3fc08f0..790f7cffc 100644 --- a/chaoslib/litmus/network-chaos/lib/latency/latency.go +++ b/chaoslib/litmus/network-chaos/lib/latency/latency.go @@ -4,13 +4,16 @@ import ( "strconv" network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" ) // PodNetworkLatencyChaos contains the steps to prepare and inject chaos func PodNetworkLatencyChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodNetworkLatencyChaos") + defer span.End() args := "delay " + strconv.Itoa(experimentsDetails.NetworkLatency) + "ms " + strconv.Itoa(experimentsDetails.Jitter) + "ms" return network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) diff --git a/chaoslib/litmus/network-chaos/lib/loss/loss.go b/chaoslib/litmus/network-chaos/lib/loss/loss.go index b90949386..424f1c9a3 100644 --- a/chaoslib/litmus/network-chaos/lib/loss/loss.go +++ b/chaoslib/litmus/network-chaos/lib/loss/loss.go @@ -2,13 +2,16 @@ package loss import ( network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" ) // PodNetworkLossChaos contains the steps to prepare and inject chaos func PodNetworkLossChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodNetworkLossChaos") + defer span.End() args := "loss " + experimentsDetails.NetworkPacketLossPercentage return network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) diff --git a/chaoslib/litmus/network-chaos/lib/network-chaos.go b/chaoslib/litmus/network-chaos/lib/network-chaos.go index 2b302fc22..31dfffaf0 100644 --- a/chaoslib/litmus/network-chaos/lib/network-chaos.go +++ b/chaoslib/litmus/network-chaos/lib/network-chaos.go @@ -4,14 +4,16 @@ import ( "context" "fmt" "net" + "os" "strconv" "strings" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" k8serrors "k8s.io/apimachinery/pkg/api/errors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" @@ -197,6 +199,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets string, nodeName, runID, args string) error { + span := telemetry.StartTracing(clients, "CreateNetworkChaosHelperPod") + defer span.End() privilegedEnable := true terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) @@ -239,7 +243,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name network-chaos", }, Resources: chaosDetails.Resources, - Env: getPodEnv(experimentsDetails, targets, args), + Env: getPodEnv(clients.Context, experimentsDetails, targets, args), VolumeMounts: []apiv1.VolumeMount{ { Name: "cri-socket", @@ -273,7 +277,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie } // getPodEnv derive all the env required for the helper pod -func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets string, args string) []apiv1.EnvVar { +func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targets string, args string) []apiv1.EnvVar { var envDetails common.ENVDetails envDetails.SetEnv("TARGETS", targets). @@ -291,6 +295,8 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets st SetEnv("DESTINATION_IPS_SERVICE_MESH", destIpsSvcMesh). SetEnv("SOURCE_PORTS", experimentsDetails.SourcePorts). SetEnv("DESTINATION_PORTS", experimentsDetails.DestinationPorts). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") return envDetails.ENV diff --git a/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go b/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go index b19bbfcc7..cacbbb9b4 100644 --- a/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go +++ b/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go @@ -7,9 +7,10 @@ import ( "strings" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-cpu-hog/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -25,6 +26,8 @@ import ( // PrepareNodeCPUHog contains preparation steps before chaos injection func PrepareNodeCPUHog(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectNodeCPUHogChaos") + defer span.End() //set up the tunables if provided in range setChaosTunables(experimentsDetails) @@ -229,6 +232,8 @@ func setCPUCapacity(experimentsDetails *experimentTypes.ExperimentDetails, appNo // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets) error { + span := telemetry.StartTracing(clients, "CreateNodeCPUHogHelperPod") + defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-drain/lib/node-drain.go b/chaoslib/litmus/node-drain/lib/node-drain.go index 13aaa2883..dc9a59b34 100644 --- a/chaoslib/litmus/node-drain/lib/node-drain.go +++ b/chaoslib/litmus/node-drain/lib/node-drain.go @@ -3,8 +3,6 @@ package lib import ( "context" "fmt" - "github.com/litmuschaos/litmus-go/pkg/cerrors" - "github.com/palantir/stacktrace" "os" "os/exec" "os/signal" @@ -13,7 +11,11 @@ import ( "syscall" "time" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/palantir/stacktrace" + + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-drain/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -33,6 +35,8 @@ var ( // PrepareNodeDrain contains the preparation steps before chaos injection func PrepareNodeDrain(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectNodeDrainChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/node-io-stress/lib/node-io-stress.go b/chaoslib/litmus/node-io-stress/lib/node-io-stress.go index 34dc6d4cb..1c3b1dbab 100644 --- a/chaoslib/litmus/node-io-stress/lib/node-io-stress.go +++ b/chaoslib/litmus/node-io-stress/lib/node-io-stress.go @@ -7,9 +7,10 @@ import ( "strings" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-io-stress/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -25,7 +26,8 @@ import ( // PrepareNodeIOStress contains preparation steps before chaos injection func PrepareNodeIOStress(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - + span := telemetry.StartTracing(clients, "InjectNodeIOStressChaos") + defer span.End() //set up the tunables if provided in range setChaosTunables(experimentsDetails) @@ -206,7 +208,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets) error { - + span := telemetry.StartTracing(clients, "CreateNodeIOStressHelperPod") + defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) helperPod := &apiv1.Pod{ diff --git a/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go b/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go index 9431c109e..ebe0a8cd5 100644 --- a/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go +++ b/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go @@ -7,9 +7,10 @@ import ( "strings" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-memory-hog/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -26,6 +27,8 @@ import ( // PrepareNodeMemoryHog contains preparation steps before chaos injection func PrepareNodeMemoryHog(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectNodeMemoryHogChaos") + defer span.End() //set up the tunables if provided in range setChaosTunables(experimentsDetails) @@ -313,6 +316,8 @@ func calculateMemoryConsumption(experimentsDetails *experimentTypes.ExperimentDe // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets, MemoryConsumption string) error { + span := telemetry.StartTracing(clients, "CreateNodeMemoryHogHelperPod") + defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-restart/lib/node-restart.go b/chaoslib/litmus/node-restart/lib/node-restart.go index 98ffdd157..074d502d5 100644 --- a/chaoslib/litmus/node-restart/lib/node-restart.go +++ b/chaoslib/litmus/node-restart/lib/node-restart.go @@ -7,9 +7,10 @@ import ( "strings" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-restart/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -39,6 +40,8 @@ const ( // PrepareNodeRestart contains preparation steps before chaos injection func PrepareNodeRestart(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectNodeRestartChaos") + defer span.End() //Select the node if experimentsDetails.TargetNode == "" { @@ -131,6 +134,8 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, chao // This method is attaching emptyDir along with secret volume, and copy data from secret // to the emptyDir, because secret is mounted as readonly and with 777 perms and it can't be changed // because of: https://github.com/kubernetes/kubernetes/issues/57923 + span := telemetry.StartTracing(clients, "CreateNodeRestartHelperPod") + defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-taint/lib/node-taint.go b/chaoslib/litmus/node-taint/lib/node-taint.go index aa4046a9a..72453894a 100644 --- a/chaoslib/litmus/node-taint/lib/node-taint.go +++ b/chaoslib/litmus/node-taint/lib/node-taint.go @@ -3,15 +3,17 @@ package lib import ( "context" "fmt" - "github.com/litmuschaos/litmus-go/pkg/cerrors" - "github.com/palantir/stacktrace" "os" "os/signal" "strings" "syscall" "time" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/palantir/stacktrace" + + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-taint/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -30,6 +32,8 @@ var ( // PrepareNodeTaint contains the preparation steps before chaos injection func PrepareNodeTaint(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectNodeTaintChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go b/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go index 18a650cc7..2161d75fe 100644 --- a/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go +++ b/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go @@ -3,15 +3,17 @@ package lib import ( "context" "fmt" - "github.com/litmuschaos/litmus-go/pkg/cerrors" - "github.com/palantir/stacktrace" "os" "os/signal" "strings" "syscall" "time" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/palantir/stacktrace" + + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-autoscaler/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/math" @@ -33,6 +35,8 @@ var ( // PreparePodAutoscaler contains the preparation steps and chaos injection steps func PreparePodAutoscaler(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodAutoScalerChaos") + defer span.End() //Waiting for the ramp time before chaos injection if experimentsDetails.RampTime != 0 { diff --git a/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go b/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go index eaeac5d03..8fa4eba6f 100644 --- a/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go +++ b/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go @@ -2,15 +2,17 @@ package lib import ( "fmt" - "github.com/litmuschaos/litmus-go/pkg/cerrors" - "github.com/palantir/stacktrace" "os" "os/signal" "strings" "syscall" "time" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/palantir/stacktrace" + + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-cpu-hog-exec/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -27,7 +29,8 @@ var inject chan os.Signal // PrepareCPUExecStress contains the chaos preparation and injection steps func PrepareCPUExecStress(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - + span := telemetry.StartTracing(clients, "InjectCPUExecStressChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) // Catch and relay certain signal(s) to inject channel. diff --git a/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go b/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go index 34f0560ef..fe81c0d3c 100644 --- a/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go +++ b/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go @@ -3,13 +3,15 @@ package lib import ( "context" "fmt" + "os" "strconv" "strings" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-dns-chaos/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" @@ -25,7 +27,8 @@ import ( // PrepareAndInjectChaos contains the preparation & injection steps func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - + span := telemetry.StartTracing(clients, "InjectPodDNSChaos") + defer span.End() // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail == nil { @@ -193,7 +196,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { - + span := telemetry.StartTracing(clients, "CreatePodDNSChaosHelperPod") + defer span.End() privilegedEnable := true terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) @@ -235,7 +239,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name dns-chaos", }, Resources: chaosDetails.Resources, - Env: getPodEnv(experimentsDetails, targets), + Env: getPodEnv(clients.Context, experimentsDetails, targets), VolumeMounts: []apiv1.VolumeMount{ { Name: "cri-socket", @@ -263,7 +267,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie } // getPodEnv derive all the env required for the helper pod -func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets string) []apiv1.EnvVar { +func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targets string) []apiv1.EnvVar { var envDetails common.ENVDetails envDetails.SetEnv("TARGETS", targets). @@ -279,6 +283,8 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets st SetEnv("MATCH_SCHEME", experimentsDetails.MatchScheme). SetEnv("CHAOS_TYPE", experimentsDetails.ChaosType). SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") return envDetails.ENV diff --git a/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go b/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go index 52275c324..5586a6d5d 100644 --- a/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go +++ b/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go @@ -10,9 +10,10 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/result" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-fio-stress/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -26,6 +27,8 @@ import ( // PrepareChaos contains the chaos preparation and injection steps func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPidFIOStressChaos") + defer span.End() //Waiting for the ramp time before chaos injection if experimentsDetails.RampTime != 0 { diff --git a/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go b/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go index 677f44fd7..ac56694c9 100644 --- a/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go +++ b/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go @@ -10,9 +10,10 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-memory-hog-exec/types" "github.com/litmuschaos/litmus-go/pkg/log" @@ -29,6 +30,8 @@ var inject chan os.Signal // PrepareMemoryExecStress contains the chaos preparation and injection steps func PrepareMemoryExecStress(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodMemoryHogChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go b/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go index 63db37274..7292c33e3 100644 --- a/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go +++ b/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go @@ -10,6 +10,7 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -33,6 +34,8 @@ var ( // PrepareAndInjectChaos contains the prepration & injection steps func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectPodNetworkPartitionChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) diff --git a/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go b/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go index 659179b55..a010f049a 100644 --- a/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go +++ b/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go @@ -6,10 +6,11 @@ import ( redfishLib "github.com/litmuschaos/litmus-go/pkg/baremetal/redfish" experimentTypes "github.com/litmuschaos/litmus-go/pkg/baremetal/redfish-node-restart/types" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" @@ -48,6 +49,8 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, // PrepareChaos contains the chaos prepration and injection steps func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectRedfishNodeRestartChaos") + defer span.End() //Waiting for the ramp time before chaos injection if experimentsDetails.RampTime != 0 { diff --git a/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go b/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go index cb5bbb485..3e22a58fb 100644 --- a/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go +++ b/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go @@ -12,6 +12,7 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" corev1 "k8s.io/api/core/v1" @@ -52,6 +53,9 @@ func SetTargetPodList(experimentsDetails *experimentTypes.ExperimentDetails, cli // PrepareChaos contains the preparation steps before chaos injection func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + span := telemetry.StartTracing(clients, "InjectSpringBootChaos") + defer span.End() + // Waiting for the ramp time before chaos injection if experimentsDetails.RampTime != 0 { log.Infof("[Ramp]: Waiting for the %vs ramp time before injecting chaos", experimentsDetails.RampTime) diff --git a/chaoslib/litmus/stress-chaos/lib/stress-chaos.go b/chaoslib/litmus/stress-chaos/lib/stress-chaos.go index 308a275dd..73ef6b458 100644 --- a/chaoslib/litmus/stress-chaos/lib/stress-chaos.go +++ b/chaoslib/litmus/stress-chaos/lib/stress-chaos.go @@ -3,13 +3,15 @@ package lib import ( "context" "fmt" + "os" "strconv" "strings" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/stress-chaos/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" @@ -24,7 +26,8 @@ import ( // PrepareAndInjectStressChaos contains the prepration & injection steps for the stress experiments. func PrepareAndInjectStressChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - + span := telemetry.StartTracing(clients, "InjectStressChaos") + defer span.End() var err error //Set up the tunables if provided in range SetChaosTunables(experimentsDetails) @@ -214,6 +217,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { + span := telemetry.StartTracing(clients, "CreateStressHelperPod") + defer span.End() privilegedEnable := true terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) @@ -265,7 +270,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name stress-chaos", }, Resources: chaosDetails.Resources, - Env: getPodEnv(experimentsDetails, targets), + Env: getPodEnv(clients.Context, experimentsDetails, targets), VolumeMounts: []apiv1.VolumeMount{ { Name: "socket-path", @@ -303,7 +308,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie } // getPodEnv derive all the env required for the helper pod -func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets string) []apiv1.EnvVar { +func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targets string) []apiv1.EnvVar { var envDetails common.ENVDetails envDetails.SetEnv("TARGETS", targets). @@ -323,6 +328,8 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, targets st SetEnv("VOLUME_MOUNT_PATH", experimentsDetails.VolumeMountPath). SetEnv("STRESS_TYPE", experimentsDetails.StressType). SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") return envDetails.ENV diff --git a/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go b/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go index e30557880..97f59a9bb 100644 --- a/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go +++ b/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go @@ -9,11 +9,12 @@ import ( "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/cloud/vmware" "github.com/litmuschaos/litmus-go/pkg/events" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" experimentTypes "github.com/litmuschaos/litmus-go/pkg/vmware/vm-poweroff/types" @@ -24,7 +25,8 @@ var inject, abort chan os.Signal // InjectVMPowerOffChaos injects the chaos in serial or parallel mode func InjectVMPowerOffChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, cookie string) error { - + span := telemetry.StartTracing(clients, "InjectVMPowerOffChaos") + defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) // Catch and relay certain signal(s) to inject channel. diff --git a/pkg/telemetry/tracing.go b/pkg/telemetry/tracing.go index 2ada6f0e2..39bbe57f8 100644 --- a/pkg/telemetry/tracing.go +++ b/pkg/telemetry/tracing.go @@ -34,3 +34,27 @@ func GetTraceParentContext() context.Context { return pro.Extract(context.Background(), propagation.MapCarrier(carrier)) } + +// GetMarshalledSpanFromContext Extract spanContext from the context and return it as json encoded string +func GetMarshalledSpanFromContext(ctx context.Context) string { + carrier := make(map[string]string) + pro := otel.GetTextMapPropagator() + + pro.Inject(ctx, propagation.MapCarrier(carrier)) + + if len(carrier) == 0 { + log.Error("spanContext not present in the context, unable to marshall") + return "" + } + + marshalled, err := json.Marshal(carrier) + if err != nil { + log.Error(err.Error()) + return "" + } + if len(marshalled) >= 1024 { + log.Error("marshalled span context is too large, unable to marshall") + return "" + } + return string(marshalled) +} From 803ab5053e1673a37c858e2e3e481feb5f3d850a Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Thu, 29 Aug 2024 14:52:03 +0900 Subject: [PATCH 03/12] fix: misc Signed-off-by: namkyu1999 --- pkg/telemetry/otel.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/telemetry/otel.go b/pkg/telemetry/otel.go index b5339c71f..1bd4c3045 100644 --- a/pkg/telemetry/otel.go +++ b/pkg/telemetry/otel.go @@ -64,7 +64,6 @@ func newTracerProvider(ctx context.Context, isExperiment bool) (*trace.TracerPro serviceName := OTELExperimentJobHelperServiceName if isExperiment { serviceName = OTELExperimentJobServiceName - } res, err := resource.New(ctx, resource.WithAttributes( From e9be0ecb60c3ba23d9be8bba768053078f5b387a Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Thu, 29 Aug 2024 21:55:46 +0900 Subject: [PATCH 04/12] fix: make otel optional Signed-off-by: namkyu1999 --- bin/experiment/experiment.go | 21 ++++++++++++------- bin/helper/helper.go | 20 +++++++++++------- .../container-kill/lib/container-kill.go | 3 ++- chaoslib/litmus/disk-fill/lib/disk-fill.go | 3 ++- chaoslib/litmus/http-chaos/lib/http-chaos.go | 3 ++- .../litmus/network-chaos/lib/network-chaos.go | 3 ++- .../litmus/pod-dns-chaos/lib/pod-dns-chaos.go | 3 ++- .../litmus/stress-chaos/lib/stress-chaos.go | 3 ++- pkg/telemetry/otel.go | 9 +++----- pkg/utils/utils.go | 4 ++++ 10 files changed, 44 insertions(+), 28 deletions(-) diff --git a/bin/experiment/experiment.go b/bin/experiment/experiment.go index 32f62ea3f..a10a4fa4d 100755 --- a/bin/experiment/experiment.go +++ b/bin/experiment/experiment.go @@ -4,6 +4,8 @@ import ( "context" "errors" "flag" + "os" + // Uncomment to load all auth plugins // _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -64,6 +66,7 @@ import ( cli "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/sirupsen/logrus" ) @@ -78,17 +81,19 @@ func init() { func main() { ctx := context.Background() + // Set up Observability. - shutdown, err := telemetry.InitOTelSDK(ctx, true) - if err != nil { - return + if otelExporterEndpoint := os.Getenv(utils.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" { + shutdown, err := telemetry.InitOTelSDK(ctx, true, otelExporterEndpoint) + if err != nil { + return + } + defer func() { + err = errors.Join(err, shutdown(ctx)) + }() + ctx = telemetry.GetTraceParentContext() } - // Handle shutdown properly so nothing leaks. - defer func() { - err = errors.Join(err, shutdown(ctx)) - }() - ctx = telemetry.GetTraceParentContext() clients := cli.ClientSets{Context: ctx} span := telemetry.StartTracing(clients, "ExecuteExperiment") diff --git a/bin/helper/helper.go b/bin/helper/helper.go index dd0aaa394..8198a26a2 100644 --- a/bin/helper/helper.go +++ b/bin/helper/helper.go @@ -4,6 +4,8 @@ import ( "context" "errors" "flag" + "os" + // Uncomment to load all auth plugins // _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -20,6 +22,7 @@ import ( dnsChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-dns-chaos/helper" stressChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/stress-chaos/helper" "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/litmuschaos/litmus-go/pkg/utils" cli "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/log" @@ -38,16 +41,17 @@ func init() { func main() { ctx := context.Background() // Set up Observability. - shutdown, err := telemetry.InitOTelSDK(ctx, false) - if err != nil { - return + if otelExporterEndpoint := os.Getenv(utils.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" { + shutdown, err := telemetry.InitOTelSDK(ctx, true, otelExporterEndpoint) + if err != nil { + return + } + defer func() { + err = errors.Join(err, shutdown(ctx)) + }() + ctx = telemetry.GetTraceParentContext() } - // Handle shutdown properly so nothing leaks. - defer func() { - err = errors.Join(err, shutdown(ctx)) - }() - ctx = telemetry.GetTraceParentContext() clients := cli.ClientSets{Context: ctx} span := telemetry.StartTracing(clients, "ExecuteExperimentHelper") diff --git a/chaoslib/litmus/container-kill/lib/container-kill.go b/chaoslib/litmus/container-kill/lib/container-kill.go index 95ee47c83..29fa2eb54 100644 --- a/chaoslib/litmus/container-kill/lib/container-kill.go +++ b/chaoslib/litmus/container-kill/lib/container-kill.go @@ -9,6 +9,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -281,7 +282,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("STATUS_CHECK_TIMEOUT", strconv.Itoa(experimentsDetails.Timeout)). SetEnv("EXPERIMENT_NAME", experimentsDetails.ExperimentName). SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/chaoslib/litmus/disk-fill/lib/disk-fill.go b/chaoslib/litmus/disk-fill/lib/disk-fill.go index a712ca3e0..8a1889d72 100644 --- a/chaoslib/litmus/disk-fill/lib/disk-fill.go +++ b/chaoslib/litmus/disk-fill/lib/disk-fill.go @@ -9,6 +9,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -289,7 +290,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). SetEnv("SOCKET_PATH", experimentsDetails.SocketPath). SetEnv("CONTAINER_RUNTIME", experimentsDetails.ContainerRuntime). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/chaoslib/litmus/http-chaos/lib/http-chaos.go b/chaoslib/litmus/http-chaos/lib/http-chaos.go index 3c90b0715..ed11b9b8d 100644 --- a/chaoslib/litmus/http-chaos/lib/http-chaos.go +++ b/chaoslib/litmus/http-chaos/lib/http-chaos.go @@ -9,6 +9,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -283,7 +284,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("TARGET_SERVICE_PORT", strconv.Itoa(experimentsDetails.TargetServicePort)). SetEnv("PROXY_PORT", strconv.Itoa(experimentsDetails.ProxyPort)). SetEnv("TOXICITY", strconv.Itoa(experimentsDetails.Toxicity)). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/chaoslib/litmus/network-chaos/lib/network-chaos.go b/chaoslib/litmus/network-chaos/lib/network-chaos.go index 31dfffaf0..5350b9a83 100644 --- a/chaoslib/litmus/network-chaos/lib/network-chaos.go +++ b/chaoslib/litmus/network-chaos/lib/network-chaos.go @@ -10,6 +10,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -295,7 +296,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("DESTINATION_IPS_SERVICE_MESH", destIpsSvcMesh). SetEnv("SOURCE_PORTS", experimentsDetails.SourcePorts). SetEnv("DESTINATION_PORTS", experimentsDetails.DestinationPorts). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go b/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go index fe81c0d3c..35ac7244e 100644 --- a/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go +++ b/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go @@ -9,6 +9,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -283,7 +284,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("MATCH_SCHEME", experimentsDetails.MatchScheme). SetEnv("CHAOS_TYPE", experimentsDetails.ChaosType). SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/chaoslib/litmus/stress-chaos/lib/stress-chaos.go b/chaoslib/litmus/stress-chaos/lib/stress-chaos.go index 73ef6b458..15daad327 100644 --- a/chaoslib/litmus/stress-chaos/lib/stress-chaos.go +++ b/chaoslib/litmus/stress-chaos/lib/stress-chaos.go @@ -9,6 +9,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" + "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -328,7 +329,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("VOLUME_MOUNT_PATH", experimentsDetails.VolumeMountPath). SetEnv("STRESS_TYPE", experimentsDetails.StressType). SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/pkg/telemetry/otel.go b/pkg/telemetry/otel.go index 1bd4c3045..99416b436 100644 --- a/pkg/telemetry/otel.go +++ b/pkg/telemetry/otel.go @@ -3,7 +3,6 @@ package telemetry import ( "context" "errors" - "os" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" @@ -15,12 +14,11 @@ import ( ) const ( - OTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT" OTELExperimentJobServiceName = "chaos_experiment_job" OTELExperimentJobHelperServiceName = "chaos_experiment_job_helper" ) -func InitOTelSDK(ctx context.Context, isExperiment bool) (shutdown func(context.Context) error, err error) { +func InitOTelSDK(ctx context.Context, isExperiment bool, endpoint string) (shutdown func(context.Context) error, err error) { var shutdownFuncs []func(context.Context) error shutdown = func(ctx context.Context) error { @@ -36,7 +34,7 @@ func InitOTelSDK(ctx context.Context, isExperiment bool) (shutdown func(context. err = errors.Join(inErr, shutdown(ctx)) } - tracerProvider, err := newTracerProvider(ctx, isExperiment) + tracerProvider, err := newTracerProvider(ctx, isExperiment, endpoint) if err != nil { handleErr(err) return @@ -59,8 +57,7 @@ func newPropagator() propagation.TextMapPropagator { ) } -func newTracerProvider(ctx context.Context, isExperiment bool) (*trace.TracerProvider, error) { - endpoint := os.Getenv(OTELExporterOTLPEndpoint) +func newTracerProvider(ctx context.Context, isExperiment bool, endpoint string) (*trace.TracerProvider, error) { serviceName := OTELExperimentJobHelperServiceName if isExperiment { serviceName = OTELExperimentJobServiceName diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index afa7a9560..7d1ef5fc9 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -2,6 +2,10 @@ package utils import "net/url" +const ( + OTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT" +) + func HttpTimeout(err error) bool { httpErr := err.(*url.Error) if httpErr != nil { From a6a77d1466f20edfcca23a153bec2a4c1528178c Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Mon, 16 Sep 2024 13:13:32 +0900 Subject: [PATCH 05/12] fix: skip if litmus-go not received trace_parent Signed-off-by: namkyu1999 --- bin/experiment/experiment.go | 3 +-- bin/helper/helper.go | 6 ++---- chaoslib/litmus/container-kill/lib/container-kill.go | 3 +-- chaoslib/litmus/disk-fill/lib/disk-fill.go | 3 +-- chaoslib/litmus/http-chaos/lib/http-chaos.go | 3 +-- chaoslib/litmus/network-chaos/lib/network-chaos.go | 3 +-- chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go | 3 +-- chaoslib/litmus/stress-chaos/lib/stress-chaos.go | 3 +-- pkg/telemetry/otel.go | 1 + pkg/telemetry/tracing.go | 4 ++++ pkg/utils/utils.go | 4 ---- 11 files changed, 14 insertions(+), 22 deletions(-) diff --git a/bin/experiment/experiment.go b/bin/experiment/experiment.go index a10a4fa4d..e45f32615 100755 --- a/bin/experiment/experiment.go +++ b/bin/experiment/experiment.go @@ -66,7 +66,6 @@ import ( cli "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/telemetry" - "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/sirupsen/logrus" ) @@ -83,7 +82,7 @@ func main() { ctx := context.Background() // Set up Observability. - if otelExporterEndpoint := os.Getenv(utils.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" { + if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" { shutdown, err := telemetry.InitOTelSDK(ctx, true, otelExporterEndpoint) if err != nil { return diff --git a/bin/helper/helper.go b/bin/helper/helper.go index 8198a26a2..a3fa7d1e1 100644 --- a/bin/helper/helper.go +++ b/bin/helper/helper.go @@ -21,11 +21,9 @@ import ( networkChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/helper" dnsChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-dns-chaos/helper" stressChaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/stress-chaos/helper" - "github.com/litmuschaos/litmus-go/pkg/telemetry" - "github.com/litmuschaos/litmus-go/pkg/utils" - cli "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/log" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/sirupsen/logrus" ) @@ -41,7 +39,7 @@ func init() { func main() { ctx := context.Background() // Set up Observability. - if otelExporterEndpoint := os.Getenv(utils.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" { + if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" { shutdown, err := telemetry.InitOTelSDK(ctx, true, otelExporterEndpoint) if err != nil { return diff --git a/chaoslib/litmus/container-kill/lib/container-kill.go b/chaoslib/litmus/container-kill/lib/container-kill.go index 29fa2eb54..95ee47c83 100644 --- a/chaoslib/litmus/container-kill/lib/container-kill.go +++ b/chaoslib/litmus/container-kill/lib/container-kill.go @@ -9,7 +9,6 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" - "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -282,7 +281,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("STATUS_CHECK_TIMEOUT", strconv.Itoa(experimentsDetails.Timeout)). SetEnv("EXPERIMENT_NAME", experimentsDetails.ExperimentName). SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/chaoslib/litmus/disk-fill/lib/disk-fill.go b/chaoslib/litmus/disk-fill/lib/disk-fill.go index 8a1889d72..a712ca3e0 100644 --- a/chaoslib/litmus/disk-fill/lib/disk-fill.go +++ b/chaoslib/litmus/disk-fill/lib/disk-fill.go @@ -9,7 +9,6 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" - "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -290,7 +289,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). SetEnv("SOCKET_PATH", experimentsDetails.SocketPath). SetEnv("CONTAINER_RUNTIME", experimentsDetails.ContainerRuntime). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/chaoslib/litmus/http-chaos/lib/http-chaos.go b/chaoslib/litmus/http-chaos/lib/http-chaos.go index ed11b9b8d..3c90b0715 100644 --- a/chaoslib/litmus/http-chaos/lib/http-chaos.go +++ b/chaoslib/litmus/http-chaos/lib/http-chaos.go @@ -9,7 +9,6 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" - "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -284,7 +283,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("TARGET_SERVICE_PORT", strconv.Itoa(experimentsDetails.TargetServicePort)). SetEnv("PROXY_PORT", strconv.Itoa(experimentsDetails.ProxyPort)). SetEnv("TOXICITY", strconv.Itoa(experimentsDetails.Toxicity)). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/chaoslib/litmus/network-chaos/lib/network-chaos.go b/chaoslib/litmus/network-chaos/lib/network-chaos.go index 5350b9a83..31dfffaf0 100644 --- a/chaoslib/litmus/network-chaos/lib/network-chaos.go +++ b/chaoslib/litmus/network-chaos/lib/network-chaos.go @@ -10,7 +10,6 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" - "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" k8serrors "k8s.io/apimachinery/pkg/api/errors" @@ -296,7 +295,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("DESTINATION_IPS_SERVICE_MESH", destIpsSvcMesh). SetEnv("SOURCE_PORTS", experimentsDetails.SourcePorts). SetEnv("DESTINATION_PORTS", experimentsDetails.DestinationPorts). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go b/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go index 35ac7244e..fe81c0d3c 100644 --- a/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go +++ b/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go @@ -9,7 +9,6 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" - "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -284,7 +283,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("MATCH_SCHEME", experimentsDetails.MatchScheme). SetEnv("CHAOS_TYPE", experimentsDetails.ChaosType). SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/chaoslib/litmus/stress-chaos/lib/stress-chaos.go b/chaoslib/litmus/stress-chaos/lib/stress-chaos.go index 15daad327..73ef6b458 100644 --- a/chaoslib/litmus/stress-chaos/lib/stress-chaos.go +++ b/chaoslib/litmus/stress-chaos/lib/stress-chaos.go @@ -9,7 +9,6 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" - "github.com/litmuschaos/litmus-go/pkg/utils" "github.com/palantir/stacktrace" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -329,7 +328,7 @@ func getPodEnv(ctx context.Context, experimentsDetails *experimentTypes.Experime SetEnv("VOLUME_MOUNT_PATH", experimentsDetails.VolumeMountPath). SetEnv("STRESS_TYPE", experimentsDetails.StressType). SetEnv("INSTANCE_ID", experimentsDetails.InstanceID). - SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(utils.OTELExporterOTLPEndpoint)). + SetEnv("OTEL_EXPORTER_OTLP_ENDPOINT", os.Getenv(telemetry.OTELExporterOTLPEndpoint)). SetEnv("TRACE_PARENT", telemetry.GetMarshalledSpanFromContext(ctx)). SetEnvFromDownwardAPI("v1", "metadata.name") diff --git a/pkg/telemetry/otel.go b/pkg/telemetry/otel.go index 99416b436..2b30c9fd5 100644 --- a/pkg/telemetry/otel.go +++ b/pkg/telemetry/otel.go @@ -16,6 +16,7 @@ import ( const ( OTELExperimentJobServiceName = "chaos_experiment_job" OTELExperimentJobHelperServiceName = "chaos_experiment_job_helper" + OTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT" ) func InitOTelSDK(ctx context.Context, isExperiment bool, endpoint string) (shutdown func(context.Context) error, err error) { diff --git a/pkg/telemetry/tracing.go b/pkg/telemetry/tracing.go index 39bbe57f8..3787178fc 100644 --- a/pkg/telemetry/tracing.go +++ b/pkg/telemetry/tracing.go @@ -26,6 +26,10 @@ func StartTracing(clients clients.ClientSets, spanName string) trace.Span { func GetTraceParentContext() context.Context { traceParent := os.Getenv(TraceParent) + if traceParent == "" { + return context.Background() + } + pro := otel.GetTextMapPropagator() carrier := make(map[string]string) if err := json.Unmarshal([]byte(traceParent), &carrier); err != nil { diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 7d1ef5fc9..afa7a9560 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -2,10 +2,6 @@ package utils import "net/url" -const ( - OTELExporterOTLPEndpoint = "OTEL_EXPORTER_OTLP_ENDPOINT" -) - func HttpTimeout(err error) bool { httpErr := err.(*url.Error) if httpErr != nil { From 723fb5962d7dfed896a7fbbf523b4b17de52c2b6 Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Mon, 16 Sep 2024 16:54:38 +0900 Subject: [PATCH 06/12] fix: Set context.Context as a parameter in each function Signed-off-by: namkyu1999 --- bin/experiment/experiment.go | 101 +++++++++--------- bin/helper/helper.go | 5 +- .../litmus/aws-ssm-chaos/lib/ssm-chaos.go | 11 +- .../lib/ssm/aws-ssm-chaos-by-id.go | 10 +- .../lib/ssm/aws-ssm-chaos-by-tag.go | 10 +- .../azure-disk-loss/lib/azure-disk-loss.go | 18 ++-- .../lib/azure-instance-stop.go | 18 ++-- .../container-kill/helper/container-kill.go | 7 +- .../container-kill/lib/container-kill.go | 29 ++--- chaoslib/litmus/disk-fill/lib/disk-fill.go | 27 ++--- .../lib/docker-service-kill.go | 13 +-- .../lib/ebs-loss-by-id/lib/ebs-loss-by-id.go | 10 +- .../ebs-loss-by-tag/lib/ebs-loss-by-tag.go | 10 +- chaoslib/litmus/ebs-loss/lib/ebs-loss.go | 11 +- .../lib/ec2-terminate-by-id.go | 18 ++-- .../lib/ec2-terminate-by-tag.go | 18 ++-- .../lib/gcp-vm-disk-loss-by-label.go | 18 ++-- .../gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go | 18 ++-- .../lib/gcp-vm-instance-stop-by-label.go | 18 ++-- .../lib/gcp-vm-instance-stop.go | 18 ++-- .../litmus/http-chaos/lib/header/header.go | 9 +- chaoslib/litmus/http-chaos/lib/http-chaos.go | 25 ++--- .../litmus/http-chaos/lib/latency/latency.go | 8 +- .../http-chaos/lib/modify-body/modify-body.go | 8 +- chaoslib/litmus/http-chaos/lib/reset/reset.go | 8 +- .../http-chaos/lib/statuscode/status-code.go | 8 +- chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go | 17 +-- .../lib/pod-delete.go | 17 +-- .../lib/kubelet-service-kill.go | 13 +-- .../lib/corruption/corruption.go | 9 +- .../lib/duplication/duplication.go | 9 +- .../network-chaos/lib/latency/latency.go | 8 +- .../litmus/network-chaos/lib/loss/loss.go | 9 +- .../litmus/network-chaos/lib/network-chaos.go | 25 ++--- .../litmus/node-cpu-hog/lib/node-cpu-hog.go | 25 ++--- chaoslib/litmus/node-drain/lib/node-drain.go | 7 +- .../node-io-stress/lib/node-io-stress.go | 25 ++--- .../node-memory-hog/lib/node-memory-hog.go | 25 ++--- .../litmus/node-restart/lib/node-restart.go | 13 +-- chaoslib/litmus/node-taint/lib/node-taint.go | 7 +- .../pod-autoscaler/lib/pod-autoscaler.go | 25 ++--- .../pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go | 22 ++-- chaoslib/litmus/pod-delete/lib/pod-delete.go | 17 +-- .../litmus/pod-dns-chaos/lib/pod-dns-chaos.go | 27 ++--- .../pod-fio-stress/lib/pod-fio-stress.go | 22 ++-- .../lib/pod-memory-hog-exec.go | 22 ++-- .../lib/pod-network-partition.go | 7 +- .../lib/redfish-node-restart.go | 12 ++- .../lib/spring-boot-chaos.go | 28 ++--- .../litmus/stress-chaos/lib/stress-chaos.go | 27 ++--- .../litmus/vm-poweroff/lib/vm-poweroff.go | 18 ++-- .../experiment/aws-ssm-chaos-by-id.go | 11 +- .../experiment/aws-ssm-chaos-by-tag.go | 11 +- .../experiment/azure-disk-loss.go | 11 +- .../experiment/azure-instance-stop.go | 11 +- .../experiment/redfish-node-restart.go | 11 +- .../pod-delete/experiment/pod-delete.go | 11 +- .../experiment/gcp-vm-disk-loss-by-label.go | 11 +- .../experiment/gcp-vm-disk-loss.go | 11 +- .../gcp-vm-instance-stop-by-label.go | 11 +- .../experiment/gcp-vm-instance-stop.go | 9 +- .../experiment/container-kill.go | 11 +- .../generic/disk-fill/experiment/disk-fill.go | 14 +-- .../experiment/docker-service-kill.go | 11 +- .../experiment/kubelet-service-kill.go | 11 +- .../node-cpu-hog/experiment/node-cpu-hog.go | 11 +- .../node-drain/experiment/node-drain.go | 9 +- .../experiment/node-io-stress.go | 11 +- .../experiment/node-memory-hog.go | 11 +- .../node-restart/experiment/node-restart.go | 11 +- .../node-taint/experiment/node-taint.go | 11 +- .../experiment/pod-autoscaler.go | 11 +- .../experiment/pod-cpu-hog-exec.go | 11 +- .../pod-cpu-hog/experiment/pod-cpu-hog.go | 11 +- .../pod-delete/experiment/pod-delete.go | 9 +- .../pod-dns-error/experiment/pod-dns-error.go | 9 +- .../pod-dns-spoof/experiment/pod-dns-spoof.go | 9 +- .../experiment/pod-fio-stress.go | 11 +- .../experiment/pod-http-latency.go | 11 +- .../experiment/pod-http-modify-body.go | 11 +- .../experiment/pod-http-modify-header.go | 11 +- .../experiment/pod-http-reset-peer.go | 11 +- .../experiment/pod-http-status-code.go | 11 +- .../pod-io-stress/experiment/pod-io-stress.go | 11 +- .../experiment/pod-memory-hog-exec.go | 11 +- .../experiment/pod-memory-hog.go | 11 +- .../experiment/pod-network-corruption.go | 11 +- .../experiment/pod-network-duplication.go | 11 +- .../experiment/pod-network-latency.go | 11 +- .../experiment/pod-network-loss.go | 11 +- .../experiment/pod-network-partition.go | 11 +- .../experiment/kafka-broker-pod-failure.go | 11 +- .../experiment/ebs-loss-by-id.go | 11 +- .../experiment/ebs-loss-by-tag.go | 11 +- .../experiment/ec2-terminate-by-id.go | 11 +- .../experiment/ec2-terminate-tag.go | 11 +- .../load/k6-loadgen/experiment/k6-loadgen.go | 11 +- .../experiment/spring-boot-faults.go | 9 +- .../vm-poweroff/experiment/vm-poweroff.go | 11 +- pkg/clients/clientset.go | 2 - pkg/probe/probe.go | 5 +- pkg/telemetry/tracing.go | 8 -- 102 files changed, 773 insertions(+), 651 deletions(-) diff --git a/bin/experiment/experiment.go b/bin/experiment/experiment.go index e45f32615..64b351671 100755 --- a/bin/experiment/experiment.go +++ b/bin/experiment/experiment.go @@ -67,6 +67,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel" ) func init() { @@ -93,9 +94,9 @@ func main() { ctx = telemetry.GetTraceParentContext() } - clients := cli.ClientSets{Context: ctx} + clients := cli.ClientSets{} - span := telemetry.StartTracing(clients, "ExecuteExperiment") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "ExecuteExperiment") defer span.End() // parse the experiment name @@ -112,101 +113,101 @@ func main() { // invoke the corresponding experiment based on the (-name) flag switch *experimentName { case "container-kill": - containerKill.ContainerKill(clients) + containerKill.ContainerKill(ctx, clients) case "disk-fill": - diskFill.DiskFill(clients) + diskFill.DiskFill(ctx, clients) case "kafka-broker-pod-failure": - kafkaBrokerPodFailure.KafkaBrokerPodFailure(clients) + kafkaBrokerPodFailure.KafkaBrokerPodFailure(ctx, clients) case "kubelet-service-kill": - kubeletServiceKill.KubeletServiceKill(clients) + kubeletServiceKill.KubeletServiceKill(ctx, clients) case "docker-service-kill": - dockerServiceKill.DockerServiceKill(clients) + dockerServiceKill.DockerServiceKill(ctx, clients) case "node-cpu-hog": - nodeCPUHog.NodeCPUHog(clients) + nodeCPUHog.NodeCPUHog(ctx, clients) case "node-drain": - nodeDrain.NodeDrain(clients) + nodeDrain.NodeDrain(ctx, clients) case "node-io-stress": - nodeIOStress.NodeIOStress(clients) + nodeIOStress.NodeIOStress(ctx, clients) case "node-memory-hog": - nodeMemoryHog.NodeMemoryHog(clients) + nodeMemoryHog.NodeMemoryHog(ctx, clients) case "node-taint": - nodeTaint.NodeTaint(clients) + nodeTaint.NodeTaint(ctx, clients) case "pod-autoscaler": - podAutoscaler.PodAutoscaler(clients) + podAutoscaler.PodAutoscaler(ctx, clients) case "pod-cpu-hog-exec": - podCPUHogExec.PodCPUHogExec(clients) + podCPUHogExec.PodCPUHogExec(ctx, clients) case "pod-delete": - podDelete.PodDelete(clients) + podDelete.PodDelete(ctx, clients) case "pod-io-stress": - podIOStress.PodIOStress(clients) + podIOStress.PodIOStress(ctx, clients) case "pod-memory-hog-exec": - podMemoryHogExec.PodMemoryHogExec(clients) + podMemoryHogExec.PodMemoryHogExec(ctx, clients) case "pod-network-corruption": - podNetworkCorruption.PodNetworkCorruption(clients) + podNetworkCorruption.PodNetworkCorruption(ctx, clients) case "pod-network-duplication": - podNetworkDuplication.PodNetworkDuplication(clients) + podNetworkDuplication.PodNetworkDuplication(ctx, clients) case "pod-network-latency": - podNetworkLatency.PodNetworkLatency(clients) + podNetworkLatency.PodNetworkLatency(ctx, clients) case "pod-network-loss": - podNetworkLoss.PodNetworkLoss(clients) + podNetworkLoss.PodNetworkLoss(ctx, clients) case "pod-network-partition": - podNetworkPartition.PodNetworkPartition(clients) + podNetworkPartition.PodNetworkPartition(ctx, clients) case "pod-memory-hog": - podMemoryHog.PodMemoryHog(clients) + podMemoryHog.PodMemoryHog(ctx, clients) case "pod-cpu-hog": - podCPUHog.PodCPUHog(clients) + podCPUHog.PodCPUHog(ctx, clients) case "cassandra-pod-delete": - cassandraPodDelete.CasssandraPodDelete(clients) + cassandraPodDelete.CasssandraPodDelete(ctx, clients) case "aws-ssm-chaos-by-id": - awsSSMChaosByID.AWSSSMChaosByID(clients) + awsSSMChaosByID.AWSSSMChaosByID(ctx, clients) case "aws-ssm-chaos-by-tag": - awsSSMChaosByTag.AWSSSMChaosByTag(clients) + awsSSMChaosByTag.AWSSSMChaosByTag(ctx, clients) case "ec2-terminate-by-id": - ec2TerminateByID.EC2TerminateByID(clients) + ec2TerminateByID.EC2TerminateByID(ctx, clients) case "ec2-terminate-by-tag": - ec2TerminateByTag.EC2TerminateByTag(clients) + ec2TerminateByTag.EC2TerminateByTag(ctx, clients) case "ebs-loss-by-id": - ebsLossByID.EBSLossByID(clients) + ebsLossByID.EBSLossByID(ctx, clients) case "ebs-loss-by-tag": - ebsLossByTag.EBSLossByTag(clients) + ebsLossByTag.EBSLossByTag(ctx, clients) case "node-restart": - nodeRestart.NodeRestart(clients) + nodeRestart.NodeRestart(ctx, clients) case "pod-dns-error": - podDNSError.PodDNSError(clients) + podDNSError.PodDNSError(ctx, clients) case "pod-dns-spoof": - podDNSSpoof.PodDNSSpoof(clients) + podDNSSpoof.PodDNSSpoof(ctx, clients) case "pod-http-latency": - podHttpLatency.PodHttpLatency(clients) + podHttpLatency.PodHttpLatency(ctx, clients) case "pod-http-status-code": - podHttpStatusCode.PodHttpStatusCode(clients) + podHttpStatusCode.PodHttpStatusCode(ctx, clients) case "pod-http-modify-header": - podHttpModifyHeader.PodHttpModifyHeader(clients) + podHttpModifyHeader.PodHttpModifyHeader(ctx, clients) case "pod-http-modify-body": - podHttpModifyBody.PodHttpModifyBody(clients) + podHttpModifyBody.PodHttpModifyBody(ctx, clients) case "pod-http-reset-peer": - podHttpResetPeer.PodHttpResetPeer(clients) + podHttpResetPeer.PodHttpResetPeer(ctx, clients) case "vm-poweroff": - vmpoweroff.VMPoweroff(clients) + vmpoweroff.VMPoweroff(ctx, clients) case "azure-instance-stop": - azureInstanceStop.AzureInstanceStop(clients) + azureInstanceStop.AzureInstanceStop(ctx, clients) case "azure-disk-loss": - azureDiskLoss.AzureDiskLoss(clients) + azureDiskLoss.AzureDiskLoss(ctx, clients) case "gcp-vm-disk-loss": - gcpVMDiskLoss.VMDiskLoss(clients) + gcpVMDiskLoss.VMDiskLoss(ctx, clients) case "pod-fio-stress": - podFioStress.PodFioStress(clients) + podFioStress.PodFioStress(ctx, clients) case "gcp-vm-instance-stop": - gcpVMInstanceStop.VMInstanceStop(clients) + gcpVMInstanceStop.VMInstanceStop(ctx, clients) case "redfish-node-restart": - redfishNodeRestart.NodeRestart(clients) + redfishNodeRestart.NodeRestart(ctx, clients) case "gcp-vm-instance-stop-by-label": - gcpVMInstanceStopByLabel.GCPVMInstanceStopByLabel(clients) + gcpVMInstanceStopByLabel.GCPVMInstanceStopByLabel(ctx, clients) case "gcp-vm-disk-loss-by-label": - gcpVMDiskLossByLabel.GCPVMDiskLossByLabel(clients) + gcpVMDiskLossByLabel.GCPVMDiskLossByLabel(ctx, clients) case "spring-boot-cpu-stress", "spring-boot-memory-stress", "spring-boot-exceptions", "spring-boot-app-kill", "spring-boot-faults", "spring-boot-latency": - springBootFaults.Experiment(clients, *experimentName) + springBootFaults.Experiment(ctx, clients, *experimentName) case "k6-loadgen": - k6Loadgen.Experiment(clients) + k6Loadgen.Experiment(ctx, clients) default: log.Errorf("Unsupported -name %v, please provide the correct value of -name args", *experimentName) return diff --git a/bin/helper/helper.go b/bin/helper/helper.go index a3fa7d1e1..eac6971f0 100644 --- a/bin/helper/helper.go +++ b/bin/helper/helper.go @@ -25,6 +25,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel" ) func init() { @@ -50,9 +51,9 @@ func main() { ctx = telemetry.GetTraceParentContext() } - clients := cli.ClientSets{Context: ctx} + clients := cli.ClientSets{} - span := telemetry.StartTracing(clients, "ExecuteExperimentHelper") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "ExecuteExperimentHelper") defer span.End() // parse the helper name diff --git a/chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go b/chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go index 9205e7f53..6c90e0ae0 100644 --- a/chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go +++ b/chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go @@ -1,12 +1,13 @@ package lib import ( + "context" "os" "strings" "time" experimentTypes "github.com/litmuschaos/litmus-go/pkg/aws-ssm/aws-ssm-chaos/types" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ssm" "github.com/litmuschaos/litmus-go/pkg/events" "github.com/litmuschaos/litmus-go/pkg/log" @@ -17,7 +18,7 @@ import ( ) // InjectChaosInSerialMode will inject the aws ssm chaos in serial mode that is one after other -func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, inject chan os.Signal) error { +func InjectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, inject chan os.Signal) error { select { case <-inject: @@ -60,7 +61,7 @@ func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } @@ -85,7 +86,7 @@ func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // InjectChaosInParallelMode will inject the aws ssm chaos in parallel mode that is all at once -func InjectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, inject chan os.Signal) error { +func InjectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, inject chan os.Signal) error { select { case <-inject: @@ -125,7 +126,7 @@ func InjectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } diff --git a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go index 9ad3c6d0a..a0b708208 100644 --- a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go +++ b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go @@ -1,6 +1,7 @@ package ssm import ( + "context" "fmt" "os" "os/signal" @@ -17,6 +18,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) var ( @@ -25,8 +27,8 @@ var ( ) // 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 { - span := telemetry.StartTracing(clients, "InjectAWSSSMChaosByIDChaos") +func PrepareAWSSSMChaosByID(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSChaosByIDChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -63,11 +65,11 @@ func PrepareAWSSSMChaosByID(experimentsDetails *experimentTypes.ExperimentDetail switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = lib.InjectChaosInSerialMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil { + if err = lib.InjectChaosInSerialMode(ctx, experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil { 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 { + if err = lib.InjectChaosInParallelMode(ctx, experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: diff --git a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go index f323ac08c..7fdade038 100644 --- a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go +++ b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go @@ -1,6 +1,7 @@ package ssm import ( + "context" "fmt" "os" "os/signal" @@ -17,11 +18,12 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) // 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 { - span := telemetry.StartTracing(clients, "InjectAWSSSMChaosByTagChaos") +func PrepareAWSSSMChaosByTag(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSSSMChaosByTagChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -58,11 +60,11 @@ func PrepareAWSSSMChaosByTag(experimentsDetails *experimentTypes.ExperimentDetai switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = lib.InjectChaosInSerialMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil { + if err = lib.InjectChaosInSerialMode(ctx, experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil { 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 { + if err = lib.InjectChaosInParallelMode(ctx, experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails, inject); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: diff --git a/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go b/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go index 6fe2686db..342149990 100644 --- a/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go +++ b/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -22,6 +23,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/litmuschaos/litmus-go/pkg/utils/retry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) var ( @@ -30,8 +32,8 @@ var ( ) // PrepareChaos contains the prepration and injection steps for the experiment -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectAzureDiskLossChaos") +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAzureDiskLossChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -82,11 +84,11 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, instanceNamesWithDiskNames, attachedDisksWithInstance, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, instanceNamesWithDiskNames, attachedDisksWithInstance, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, instanceNamesWithDiskNames, attachedDisksWithInstance, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, instanceNamesWithDiskNames, attachedDisksWithInstance, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -103,7 +105,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients } // injectChaosInParallelMode will inject the Azure disk loss chaos in parallel mode that is all at once -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesWithDiskNames map[string][]string, attachedDisksWithInstance map[string]*[]compute.DataDisk, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesWithDiskNames map[string][]string, attachedDisksWithInstance map[string]*[]compute.DataDisk, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -142,7 +144,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet } // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } @@ -181,7 +183,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet } // injectChaosInSerialMode will inject the Azure disk loss chaos in serial mode that is one after other -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesWithDiskNames map[string][]string, attachedDisksWithInstance map[string]*[]compute.DataDisk, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesWithDiskNames map[string][]string, attachedDisksWithInstance map[string]*[]compute.DataDisk, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -217,7 +219,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai // run the probes during chaos // the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } diff --git a/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go b/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go index 7bdfc9ecc..b9c70bc23 100644 --- a/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go +++ b/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -20,6 +21,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) var ( @@ -28,8 +30,8 @@ var ( ) // PrepareAzureStop will initialize instanceNameList and start chaos injection based on sequence method selected -func PrepareAzureStop(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectAzureInstanceStopChaos") +func PrepareAzureStop(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAzureInstanceStopChaos") defer span.End() // inject channel is used to transmit signal notifications @@ -58,11 +60,11 @@ func PrepareAzureStop(experimentsDetails *experimentTypes.ExperimentDetails, cli switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, instanceNameList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, instanceNameList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, instanceNameList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, instanceNameList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -78,7 +80,7 @@ func PrepareAzureStop(experimentsDetails *experimentTypes.ExperimentDetails, cli } // injectChaosInSerialMode will inject the Azure instance termination in serial mode that is one after the other -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, instanceNameList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceNameList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: // stopping the chaos execution, if abort signal received @@ -122,7 +124,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai // Run the probes during chaos // the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } @@ -156,7 +158,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode will inject the Azure instance termination in parallel mode that is all at once -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, instanceNameList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceNameList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: // Stopping the chaos execution, if abort signal received @@ -201,7 +203,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // Run probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } diff --git a/chaoslib/litmus/container-kill/helper/container-kill.go b/chaoslib/litmus/container-kill/helper/container-kill.go index 0a18bfa41..6ea335467 100644 --- a/chaoslib/litmus/container-kill/helper/container-kill.go +++ b/chaoslib/litmus/container-kill/helper/container-kill.go @@ -4,13 +4,14 @@ import ( "bytes" "context" "fmt" + "os/exec" + "strconv" + "time" + "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/result" "github.com/palantir/stacktrace" "github.com/sirupsen/logrus" - "os/exec" - "strconv" - "time" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" diff --git a/chaoslib/litmus/container-kill/lib/container-kill.go b/chaoslib/litmus/container-kill/lib/container-kill.go index 95ee47c83..52c3151a6 100644 --- a/chaoslib/litmus/container-kill/lib/container-kill.go +++ b/chaoslib/litmus/container-kill/lib/container-kill.go @@ -10,6 +10,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/container-kill/types" @@ -25,8 +26,8 @@ import ( ) // PrepareContainerKill contains the preparation steps before chaos injection -func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectContainerKillChaos") +func PrepareContainerKill(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectContainerKillChaos") defer span.End() var err error @@ -35,7 +36,7 @@ func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails, if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail == nil { return cerrors.Error{ErrorCode: cerrors.ErrorTypeTargetSelection, Reason: "provide one of the appLabel or TARGET_PODS"} } - //Setup the tunables if provided in range + //Set up the tunables if provided in range SetChaosTunables(experimentsDetails) log.InfoWithValues("[Info]: The tunables are:", logrus.Fields{ @@ -71,11 +72,11 @@ func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails, experimentsDetails.IsTargetContainerProvided = experimentsDetails.TargetContainer != "" switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -91,10 +92,10 @@ func PrepareContainerKill(experimentsDetails *experimentTypes.ExperimentDetails, } // injectChaosInSerialMode kill the container of all target application serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -109,7 +110,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai runID := stringutils.GetRunID() - if err := createHelperPod(experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer), pod.Spec.NodeName, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer), pod.Spec.NodeName, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -141,10 +142,10 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode kill the container of all target application in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -158,7 +159,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet targetsPerNode = append(targetsPerNode, fmt.Sprintf("%s:%s:%s", k.Name, k.Namespace, k.TargetContainer)) } - if err := createHelperPod(experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } } @@ -191,8 +192,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { - span := telemetry.StartTracing(clients, "CreateContainerKillHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateContainerKillHelperPod") defer span.End() privilegedEnable := false @@ -237,7 +238,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name container-kill", }, Resources: chaosDetails.Resources, - Env: getPodEnv(clients.Context, experimentsDetails, targets), + Env: getPodEnv(ctx, experimentsDetails, targets), VolumeMounts: []apiv1.VolumeMount{ { Name: "cri-socket", diff --git a/chaoslib/litmus/disk-fill/lib/disk-fill.go b/chaoslib/litmus/disk-fill/lib/disk-fill.go index a712ca3e0..11c9aff30 100644 --- a/chaoslib/litmus/disk-fill/lib/disk-fill.go +++ b/chaoslib/litmus/disk-fill/lib/disk-fill.go @@ -10,6 +10,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/types" @@ -26,8 +27,8 @@ import ( ) // PrepareDiskFill contains the preparation steps before chaos injection -func PrepareDiskFill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectDiskFillChaos") +func PrepareDiskFill(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectDiskFillChaos") defer span.End() var err error @@ -76,11 +77,11 @@ func PrepareDiskFill(experimentsDetails *experimentTypes.ExperimentDetails, clie experimentsDetails.IsTargetContainerProvided = experimentsDetails.TargetContainer != "" switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetPodList, clients, chaosDetails, execCommandDetails, resultDetails, eventsDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetPodList, clients, chaosDetails, execCommandDetails, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetPodList, clients, chaosDetails, execCommandDetails, resultDetails, eventsDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetPodList, clients, chaosDetails, execCommandDetails, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -96,11 +97,11 @@ func PrepareDiskFill(experimentsDetails *experimentTypes.ExperimentDetails, clie } // injectChaosInSerialMode fill the ephemeral storage of all target application serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, execCommandDetails exec.PodDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, execCommandDetails exec.PodDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -114,7 +115,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } runID := stringutils.GetRunID() - if err := createHelperPod(experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer), pod.Spec.NodeName, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer), pod.Spec.NodeName, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -148,12 +149,12 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode fill the ephemeral storage of of all target application in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, execCommandDetails exec.PodDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, execCommandDetails exec.PodDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { var err error // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -167,7 +168,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet targetsPerNode = append(targetsPerNode, fmt.Sprintf("%s:%s:%s", k.Name, k.Namespace, k.TargetContainer)) } - if err := createHelperPod(experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } } @@ -200,8 +201,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, appNodeName, runID string) error { - span := telemetry.StartTracing(clients, "CreateDiskFillHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, appNodeName, runID string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateDiskFillHelperPod") defer span.End() privilegedEnable := true @@ -245,7 +246,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name disk-fill", }, Resources: chaosDetails.Resources, - Env: getPodEnv(clients.Context, experimentsDetails, targets), + Env: getPodEnv(ctx, experimentsDetails, targets), VolumeMounts: []apiv1.VolumeMount{ { Name: "socket-path", diff --git a/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go b/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go index 49df6a15a..74b04c512 100644 --- a/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go +++ b/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go @@ -8,6 +8,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -24,8 +25,8 @@ import ( ) // PrepareDockerServiceKill contains prepration steps before chaos injection -func PrepareDockerServiceKill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectDockerServiceKillChaos") +func PrepareDockerServiceKill(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectDockerServiceKillChaos") defer span.End() var err error @@ -62,7 +63,7 @@ func PrepareDockerServiceKill(experimentsDetails *experimentTypes.ExperimentDeta } // Creating the helper pod to perform docker-service-kill - if err = createHelperPod(experimentsDetails, clients, chaosDetails, experimentsDetails.TargetNode); err != nil { + if err = createHelperPod(ctx, experimentsDetails, clients, chaosDetails, experimentsDetails.TargetNode); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -77,7 +78,7 @@ func PrepareDockerServiceKill(experimentsDetails *experimentTypes.ExperimentDeta // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { common.DeleteAllHelperPodBasedOnJobCleanupPolicy(appLabel, chaosDetails, clients) return err } @@ -113,8 +114,8 @@ func PrepareDockerServiceKill(experimentsDetails *experimentTypes.ExperimentDeta } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, appNodeName string) error { - span := telemetry.StartTracing(clients, "CreateDockerServiceKillHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, appNodeName string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateDockerServiceKillHelperPod") defer span.End() privileged := true diff --git a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go index 6b3f12fa6..a3b48ca1e 100644 --- a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go +++ b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -16,6 +17,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) var ( @@ -24,8 +26,8 @@ var ( ) // PrepareEBSLossByID contains the prepration and injection steps for the experiment -func PrepareEBSLossByID(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectEBSLossByIDChaos") +func PrepareEBSLossByID(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectEBSLossByIDChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -60,11 +62,11 @@ func PrepareEBSLossByID(experimentsDetails *experimentTypes.ExperimentDetails, c switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = ebsloss.InjectChaosInSerialMode(experimentsDetails, volumeIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = ebsloss.InjectChaosInSerialMode(ctx, experimentsDetails, volumeIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = ebsloss.InjectChaosInParallelMode(experimentsDetails, volumeIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = ebsloss.InjectChaosInParallelMode(ctx, experimentsDetails, volumeIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: diff --git a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go index 4eb9addf6..ea8342909 100644 --- a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go +++ b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -16,6 +17,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) var ( @@ -24,8 +26,8 @@ var ( ) // PrepareEBSLossByTag contains the prepration and injection steps for the experiment -func PrepareEBSLossByTag(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectEBSLossByTagChaos") +func PrepareEBSLossByTag(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectEBSLossByTagChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -58,11 +60,11 @@ func PrepareEBSLossByTag(experimentsDetails *experimentTypes.ExperimentDetails, switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = ebsloss.InjectChaosInSerialMode(experimentsDetails, targetEBSVolumeIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = ebsloss.InjectChaosInSerialMode(ctx, experimentsDetails, targetEBSVolumeIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = ebsloss.InjectChaosInParallelMode(experimentsDetails, targetEBSVolumeIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = ebsloss.InjectChaosInParallelMode(ctx, experimentsDetails, targetEBSVolumeIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: diff --git a/chaoslib/litmus/ebs-loss/lib/ebs-loss.go b/chaoslib/litmus/ebs-loss/lib/ebs-loss.go index 8fd39c06b..3d21a6b72 100644 --- a/chaoslib/litmus/ebs-loss/lib/ebs-loss.go +++ b/chaoslib/litmus/ebs-loss/lib/ebs-loss.go @@ -1,12 +1,13 @@ package lib import ( + "context" "fmt" "os" "time" "github.com/litmuschaos/litmus-go/pkg/cerrors" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" ebs "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ebs" "github.com/litmuschaos/litmus-go/pkg/events" experimentTypes "github.com/litmuschaos/litmus-go/pkg/kube-aws/ebs-loss/types" @@ -18,7 +19,7 @@ import ( ) // InjectChaosInSerialMode will inject the ebs loss chaos in serial mode which means one after other -func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetEBSVolumeIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func InjectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetEBSVolumeIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -56,7 +57,7 @@ func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai // run the probes during chaos // the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } @@ -95,7 +96,7 @@ func InjectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // InjectChaosInParallelMode will inject the chaos in parallel mode that means all at once -func InjectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetEBSVolumeIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func InjectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetEBSVolumeIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { var ec2InstanceIDList, deviceList []string @@ -152,7 +153,7 @@ func InjectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } diff --git a/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go b/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go index c9978907a..8f30a7c24 100644 --- a/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go +++ b/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -19,6 +20,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) var ( @@ -27,8 +29,8 @@ var ( ) // PrepareEC2TerminateByID contains the prepration and injection steps for the experiment -func PrepareEC2TerminateByID(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectEC2TerminateByIDChaos") +func PrepareEC2TerminateByID(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectEC2TerminateByIDChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -58,11 +60,11 @@ func PrepareEC2TerminateByID(experimentsDetails *experimentTypes.ExperimentDetai switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -78,7 +80,7 @@ func PrepareEC2TerminateByID(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInSerialMode will inject the ec2 instance termination in serial mode that is one after other -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -119,7 +121,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai // run the probes during chaos // the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } @@ -150,7 +152,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode will inject the ec2 instance termination in parallel mode that is all at once -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -192,7 +194,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } diff --git a/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go b/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go index 71f47c0ae..06efa86c1 100644 --- a/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go +++ b/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -20,13 +21,14 @@ import ( "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel" ) var inject, abort chan os.Signal // PrepareEC2TerminateByTag contains the prepration and injection steps for the experiment -func PrepareEC2TerminateByTag(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectEC2TerminateByTagChaos") +func PrepareEC2TerminateByTag(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectEC2TerminateByTagChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -53,11 +55,11 @@ func PrepareEC2TerminateByTag(experimentsDetails *experimentTypes.ExperimentDeta switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err := injectChaosInSerialMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := injectChaosInSerialMode(ctx, experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err := injectChaosInParallelMode(experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := injectChaosInParallelMode(ctx, experimentsDetails, instanceIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -73,7 +75,7 @@ func PrepareEC2TerminateByTag(experimentsDetails *experimentTypes.ExperimentDeta } // injectChaosInSerialMode will inject the ce2 instance termination in serial mode that is one after other -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -114,7 +116,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai // run the probes during chaos // the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } @@ -145,7 +147,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode will inject the ce2 instance termination in parallel mode that is all at once -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -185,7 +187,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } diff --git a/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go b/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go index 6648f052f..7b5ec29be 100644 --- a/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go +++ b/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -19,6 +20,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "google.golang.org/api/compute/v1" ) @@ -28,8 +30,8 @@ var ( ) // PrepareDiskVolumeLossByLabel contains the prepration and injection steps for the experiment -func PrepareDiskVolumeLossByLabel(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectDiskVolumeLossByLabelChaos") +func PrepareDiskVolumeLossByLabel(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectDiskVolumeLossByLabelChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -66,11 +68,11 @@ func PrepareDiskVolumeLossByLabel(computeService *compute.Service, experimentsDe switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(computeService, experimentsDetails, diskVolumeNamesList, experimentsDetails.TargetDiskInstanceNamesList, experimentsDetails.Zones, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, computeService, experimentsDetails, diskVolumeNamesList, experimentsDetails.TargetDiskInstanceNamesList, experimentsDetails.Zones, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(computeService, experimentsDetails, diskVolumeNamesList, experimentsDetails.TargetDiskInstanceNamesList, experimentsDetails.Zones, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, computeService, experimentsDetails, diskVolumeNamesList, experimentsDetails.TargetDiskInstanceNamesList, experimentsDetails.Zones, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -88,7 +90,7 @@ func PrepareDiskVolumeLossByLabel(computeService *compute.Service, experimentsDe } // injectChaosInSerialMode will inject the disk loss chaos in serial mode which means one after the other -func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, instanceNamesList []string, zone string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, instanceNamesList []string, zone string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -121,7 +123,7 @@ func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails // run the probes during chaos // the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -163,7 +165,7 @@ func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails } // injectChaosInParallelMode will inject the disk loss chaos in parallel mode that means all at once -func injectChaosInParallelMode(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, instanceNamesList []string, zone string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, instanceNamesList []string, zone string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -199,7 +201,7 @@ func injectChaosInParallelMode(computeService *compute.Service, experimentsDetai // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go b/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go index 3941b6f8a..e3bd1f817 100644 --- a/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go +++ b/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -20,6 +21,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" "github.com/pkg/errors" + "go.opentelemetry.io/otel" "google.golang.org/api/compute/v1" ) @@ -29,8 +31,8 @@ var ( ) // PrepareDiskVolumeLoss contains the prepration and injection steps for the experiment -func PrepareDiskVolumeLoss(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectVMDiskLossChaos") +func PrepareDiskVolumeLoss(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMDiskLossChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -71,11 +73,11 @@ func PrepareDiskVolumeLoss(computeService *compute.Service, experimentsDetails * switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(computeService, experimentsDetails, diskNamesList, diskZonesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, computeService, experimentsDetails, diskNamesList, diskZonesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(computeService, experimentsDetails, diskNamesList, diskZonesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, computeService, experimentsDetails, diskNamesList, diskZonesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -93,7 +95,7 @@ func PrepareDiskVolumeLoss(computeService *compute.Service, experimentsDetails * } // injectChaosInSerialMode will inject the disk loss chaos in serial mode which means one after the other -func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, diskZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, diskZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -125,7 +127,7 @@ func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails // run the probes during chaos // the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -164,7 +166,7 @@ func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails } // injectChaosInParallelMode will inject the disk loss chaos in parallel mode that means all at once -func injectChaosInParallelMode(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, diskZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, diskZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -200,7 +202,7 @@ func injectChaosInParallelMode(computeService *compute.Service, experimentsDetai // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go b/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go index b7e8fb149..86d194e74 100644 --- a/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go +++ b/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -19,14 +20,15 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "google.golang.org/api/compute/v1" ) var inject, abort chan os.Signal // PrepareVMStopByLabel executes the experiment steps by injecting chaos into target VM instances -func PrepareVMStopByLabel(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectVMInstanceStopByLabelChaos") +func PrepareVMStopByLabel(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMInstanceStopByLabelChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -53,11 +55,11 @@ func PrepareVMStopByLabel(computeService *compute.Service, experimentsDetails *e switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err := injectChaosInSerialMode(computeService, experimentsDetails, instanceNamesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := injectChaosInSerialMode(ctx, computeService, experimentsDetails, instanceNamesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err := injectChaosInParallelMode(computeService, experimentsDetails, instanceNamesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := injectChaosInParallelMode(ctx, computeService, experimentsDetails, instanceNamesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -74,7 +76,7 @@ func PrepareVMStopByLabel(computeService *compute.Service, experimentsDetails *e } // injectChaosInSerialMode stops VM instances in serial mode i.e. one after the other -func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -115,7 +117,7 @@ func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails // run the probes during chaos // the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -159,7 +161,7 @@ func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails } // injectChaosInParallelMode will inject the VM instance termination in serial mode that is one after other -func injectChaosInParallelMode(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -203,7 +205,7 @@ func injectChaosInParallelMode(computeService *compute.Service, experimentsDetai // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go b/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go index b3569cf71..35eeac647 100644 --- a/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go +++ b/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -19,6 +20,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "google.golang.org/api/compute/v1" ) @@ -28,8 +30,8 @@ var ( ) // PrepareVMStop contains the prepration and injection steps for the experiment -func PrepareVMStop(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectVMInstanceStopChaos") +func PrepareVMStop(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMInstanceStopChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -58,11 +60,11 @@ func PrepareVMStop(computeService *compute.Service, experimentsDetails *experime switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(computeService, experimentsDetails, instanceNamesList, instanceZonesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, computeService, experimentsDetails, instanceNamesList, instanceZonesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(computeService, experimentsDetails, instanceNamesList, instanceZonesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, computeService, experimentsDetails, instanceNamesList, instanceZonesList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -79,7 +81,7 @@ func PrepareVMStop(computeService *compute.Service, experimentsDetails *experime } // injectChaosInSerialMode stops VM instances in serial mode i.e. one after the other -func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, instanceZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, instanceZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -120,7 +122,7 @@ func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails // run the probes during chaos // the OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -164,7 +166,7 @@ func injectChaosInSerialMode(computeService *compute.Service, experimentsDetails } // injectChaosInParallelMode stops VM instances in parallel mode i.e. all at once -func injectChaosInParallelMode(computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, instanceZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, instanceZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -208,7 +210,7 @@ func injectChaosInParallelMode(computeService *compute.Service, experimentsDetai // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/http-chaos/lib/header/header.go b/chaoslib/litmus/http-chaos/lib/header/header.go index 95bef093a..ec38f6c08 100644 --- a/chaoslib/litmus/http-chaos/lib/header/header.go +++ b/chaoslib/litmus/http-chaos/lib/header/header.go @@ -1,6 +1,8 @@ package header import ( + "context" + http_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" @@ -8,11 +10,12 @@ import ( "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel" ) // PodHttpModifyHeaderChaos contains the steps to prepare and inject http modify header chaos -func PodHttpModifyHeaderChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodHTTPModifyHeaderChaos") +func PodHttpModifyHeaderChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPModifyHeaderChaos") defer span.End() log.InfoWithValues("[Info]: The chaos tunables are:", logrus.Fields{ @@ -30,5 +33,5 @@ func PodHttpModifyHeaderChaos(experimentsDetails *experimentTypes.ExperimentDeta stream = "upstream" } args := "-t header --" + stream + " -a headers='" + (experimentsDetails.HeadersMap) + "' -a mode=" + experimentsDetails.HeaderMode - return http_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) + return http_chaos.PrepareAndInjectChaos(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) } diff --git a/chaoslib/litmus/http-chaos/lib/http-chaos.go b/chaoslib/litmus/http-chaos/lib/http-chaos.go index 3c90b0715..185033459 100644 --- a/chaoslib/litmus/http-chaos/lib/http-chaos.go +++ b/chaoslib/litmus/http-chaos/lib/http-chaos.go @@ -10,6 +10,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" @@ -25,7 +26,7 @@ import ( ) // PrepareAndInjectChaos contains the preparation & injection steps -func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, args string) error { +func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, args string) error { var err error // Get the target pod details for the chaos execution @@ -65,11 +66,11 @@ func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetPodList, args, clients, chaosDetails, resultDetails, eventsDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetPodList, args, clients, chaosDetails, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetPodList, args, clients, chaosDetails, resultDetails, eventsDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetPodList, args, clients, chaosDetails, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -80,11 +81,11 @@ func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails } // injectChaosInSerialMode inject the http chaos in all target application serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, args string, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, args string, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -104,7 +105,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai }) runID := stringutils.GetRunID() - if err := createHelperPod(experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer), pod.Spec.NodeName, runID, args); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer), pod.Spec.NodeName, runID, args); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -137,11 +138,11 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode inject the http chaos in all target application in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, args string, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, args string, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -155,7 +156,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet targetsPerNode = append(targetsPerNode, fmt.Sprintf("%s:%s:%s", k.Name, k.Namespace, k.TargetContainer)) } - if err := createHelperPod(experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID, args); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID, args); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } } @@ -188,8 +189,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID, args string) error { - span := telemetry.StartTracing(clients, "InjectHTTPChaosHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID, args string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateHTTPChaosHelperPod") defer span.End() privilegedEnable := true @@ -233,7 +234,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name http-chaos", }, Resources: chaosDetails.Resources, - Env: getPodEnv(clients.Context, experimentsDetails, targets, args), + Env: getPodEnv(ctx, experimentsDetails, targets, args), VolumeMounts: []apiv1.VolumeMount{ { Name: "cri-socket", diff --git a/chaoslib/litmus/http-chaos/lib/latency/latency.go b/chaoslib/litmus/http-chaos/lib/latency/latency.go index 24df1a4f2..a45432e0a 100644 --- a/chaoslib/litmus/http-chaos/lib/latency/latency.go +++ b/chaoslib/litmus/http-chaos/lib/latency/latency.go @@ -1,6 +1,7 @@ package latency import ( + "context" "strconv" http_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib" @@ -10,11 +11,12 @@ import ( "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel" ) // PodHttpLatencyChaos contains the steps to prepare and inject http latency chaos -func PodHttpLatencyChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodHTTPLatencyChaos") +func PodHttpLatencyChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPLatencyChaos") defer span.End() log.InfoWithValues("[Info]: The chaos tunables are:", logrus.Fields{ @@ -27,5 +29,5 @@ func PodHttpLatencyChaos(experimentsDetails *experimentTypes.ExperimentDetails, }) args := "-t latency -a latency=" + strconv.Itoa(experimentsDetails.Latency) - return http_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) + return http_chaos.PrepareAndInjectChaos(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) } diff --git a/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go b/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go index 7a5980c6f..6093036e6 100644 --- a/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go +++ b/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go @@ -1,6 +1,7 @@ package modifybody import ( + "context" "fmt" "math" "strings" @@ -12,11 +13,12 @@ import ( "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel" ) // PodHttpModifyBodyChaos contains the steps to prepare and inject http modify body chaos -func PodHttpModifyBodyChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodHTTPModifyBodyChaos") +func PodHttpModifyBodyChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPModifyBodyChaos") defer span.End() // responseBodyMaxLength defines the max length of response body string to be printed. It is taken as @@ -37,7 +39,7 @@ func PodHttpModifyBodyChaos(experimentsDetails *experimentTypes.ExperimentDetail args := fmt.Sprintf( `-t modify_body -a body="%v" -a content_type=%v -a content_encoding=%v`, EscapeQuotes(experimentsDetails.ResponseBody), experimentsDetails.ContentType, experimentsDetails.ContentEncoding) - return http_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) + return http_chaos.PrepareAndInjectChaos(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) } // EscapeQuotes escapes the quotes in the given string diff --git a/chaoslib/litmus/http-chaos/lib/reset/reset.go b/chaoslib/litmus/http-chaos/lib/reset/reset.go index 3b10245cb..d8df3eb6c 100644 --- a/chaoslib/litmus/http-chaos/lib/reset/reset.go +++ b/chaoslib/litmus/http-chaos/lib/reset/reset.go @@ -1,6 +1,7 @@ package reset import ( + "context" "strconv" http_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib" @@ -10,11 +11,12 @@ import ( "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel" ) // PodHttpResetPeerChaos contains the steps to prepare and inject http reset peer chaos -func PodHttpResetPeerChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodHTTPResetPeerChaos") +func PodHttpResetPeerChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPResetPeerChaos") defer span.End() log.InfoWithValues("[Info]: The chaos tunables are:", logrus.Fields{ @@ -27,5 +29,5 @@ func PodHttpResetPeerChaos(experimentsDetails *experimentTypes.ExperimentDetails }) args := "-t reset_peer -a timeout=" + strconv.Itoa(experimentsDetails.ResetTimeout) - return http_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) + return http_chaos.PrepareAndInjectChaos(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) } diff --git a/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go b/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go index 9c00c0ae9..c2a115a32 100644 --- a/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go +++ b/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go @@ -1,6 +1,7 @@ package statuscode import ( + "context" "fmt" "math" "math/rand" @@ -10,6 +11,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" + "go.opentelemetry.io/otel" http_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib" body "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib/modify-body" @@ -28,8 +30,8 @@ var acceptedStatusCodes = []string{ } // PodHttpStatusCodeChaos contains the steps to prepare and inject http status code chaos -func PodHttpStatusCodeChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodHTTPStatusCodeChaos") +func PodHttpStatusCodeChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPStatusCodeChaos") defer span.End() // responseBodyMaxLength defines the max length of response body string to be printed. It is taken as @@ -53,7 +55,7 @@ func PodHttpStatusCodeChaos(experimentsDetails *experimentTypes.ExperimentDetail `-t status_code -a status_code=%s -a modify_response_body=%d -a response_body="%v" -a content_type=%s -a content_encoding=%s`, experimentsDetails.StatusCode, stringBoolToInt(experimentsDetails.ModifyResponseBody), body.EscapeQuotes(experimentsDetails.ResponseBody), experimentsDetails.ContentType, experimentsDetails.ContentEncoding) - return http_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) + return http_chaos.PrepareAndInjectChaos(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) } // GetStatusCode performs two functions: diff --git a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go index 0ed8420b4..f89afc377 100644 --- a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go +++ b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go @@ -17,11 +17,12 @@ import ( "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/litmuschaos/litmus-go/pkg/utils/stringutils" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func experimentExecution(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { if experimentsDetails.EngineName != "" { msg := "Injecting " + experimentsDetails.ExperimentName + " chaos" types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails) @@ -29,7 +30,7 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, } // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -37,7 +38,7 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, runID := stringutils.GetRunID() // creating the helper pod to perform k6-loadgen chaos - if err := createHelperPod(experimentsDetails, clients, chaosDetails, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -69,8 +70,8 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, } // PrepareChaos contains the preparation steps before chaos injection -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectK6LoadGenChaos") +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectK6LoadGenChaos") defer span.End() // Waiting for the ramp time before chaos injection @@ -80,7 +81,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients } // Starting the k6-loadgen experiment - if err := experimentExecution(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := experimentExecution(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not execute chaos") } @@ -93,8 +94,8 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, runID string) error { - span := telemetry.StartTracing(clients, "CreateK6LoadGenHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, runID string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateK6LoadGenHelperPod") defer span.End() const volumeName = "script-volume" diff --git a/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go b/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go index 98420c431..b5646d041 100644 --- a/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go +++ b/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go @@ -11,6 +11,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/workloads" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -25,8 +26,8 @@ import ( ) // PreparePodDelete contains the prepration steps before chaos injection -func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectKafkaPodDeleteChaos") +func PreparePodDelete(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectKafkaPodDeleteChaos") defer span.End() //Waiting for the ramp time before chaos injection @@ -37,11 +38,11 @@ func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, cli switch strings.ToLower(experimentsDetails.ChaoslibDetail.Sequence) { case "serial": - if err := injectChaosInSerialMode(experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { + if err := injectChaosInSerialMode(ctx, experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err := injectChaosInParallelMode(experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { + if err := injectChaosInParallelMode(ctx, experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -57,11 +58,11 @@ func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, cli } // injectChaosInSerialMode delete the kafka broker pods in serial mode(one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -152,11 +153,11 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode delete the kafka broker pods in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go b/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go index 283d7ac12..3132902b7 100644 --- a/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go +++ b/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go @@ -8,6 +8,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -24,8 +25,8 @@ import ( ) // PrepareKubeletKill contains prepration steps before chaos injection -func PrepareKubeletKill(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectKubeletServiceKillChaos") +func PrepareKubeletKill(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectKubeletServiceKillChaos") defer span.End() var err error @@ -62,7 +63,7 @@ func PrepareKubeletKill(experimentsDetails *experimentTypes.ExperimentDetails, c } // Creating the helper pod to perform node memory hog - if err = createHelperPod(experimentsDetails, clients, chaosDetails, experimentsDetails.TargetNode); err != nil { + if err = createHelperPod(ctx, experimentsDetails, clients, chaosDetails, experimentsDetails.TargetNode); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -79,7 +80,7 @@ func PrepareKubeletKill(experimentsDetails *experimentTypes.ExperimentDetails, c // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { common.DeleteAllHelperPodBasedOnJobCleanupPolicy(appLabel, chaosDetails, clients) return err } @@ -115,8 +116,8 @@ func PrepareKubeletKill(experimentsDetails *experimentTypes.ExperimentDetails, c } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, appNodeName string) error { - span := telemetry.StartTracing(clients, "CreateKubeletServiceKillHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, appNodeName string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateKubeletServiceKillHelperPod") defer span.End() privileged := true diff --git a/chaoslib/litmus/network-chaos/lib/corruption/corruption.go b/chaoslib/litmus/network-chaos/lib/corruption/corruption.go index cd855dac1..18da21d3d 100644 --- a/chaoslib/litmus/network-chaos/lib/corruption/corruption.go +++ b/chaoslib/litmus/network-chaos/lib/corruption/corruption.go @@ -1,18 +1,21 @@ package corruption import ( + "context" + network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" + "go.opentelemetry.io/otel" ) // PodNetworkCorruptionChaos contains the steps to prepare and inject chaos -func PodNetworkCorruptionChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodNetworkCorruptionChaos") +func PodNetworkCorruptionChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkCorruptionChaos") defer span.End() args := "corrupt " + experimentsDetails.NetworkPacketCorruptionPercentage - return network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) + return network_chaos.PrepareAndInjectChaos(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) } diff --git a/chaoslib/litmus/network-chaos/lib/duplication/duplication.go b/chaoslib/litmus/network-chaos/lib/duplication/duplication.go index 0d42d2ab4..e428e3cec 100644 --- a/chaoslib/litmus/network-chaos/lib/duplication/duplication.go +++ b/chaoslib/litmus/network-chaos/lib/duplication/duplication.go @@ -1,18 +1,21 @@ package duplication import ( + "context" + network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" + "go.opentelemetry.io/otel" ) // PodNetworkDuplicationChaos contains the steps to prepare and inject chaos -func PodNetworkDuplicationChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodNetworkDuplicationChaos") +func PodNetworkDuplicationChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkDuplicationChaos") defer span.End() args := "duplicate " + experimentsDetails.NetworkPacketDuplicationPercentage - return network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) + return network_chaos.PrepareAndInjectChaos(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) } diff --git a/chaoslib/litmus/network-chaos/lib/latency/latency.go b/chaoslib/litmus/network-chaos/lib/latency/latency.go index 790f7cffc..817533fde 100644 --- a/chaoslib/litmus/network-chaos/lib/latency/latency.go +++ b/chaoslib/litmus/network-chaos/lib/latency/latency.go @@ -1,6 +1,7 @@ package latency import ( + "context" "strconv" network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib" @@ -8,13 +9,14 @@ import ( experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" + "go.opentelemetry.io/otel" ) // PodNetworkLatencyChaos contains the steps to prepare and inject chaos -func PodNetworkLatencyChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodNetworkLatencyChaos") +func PodNetworkLatencyChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkLatencyChaos") defer span.End() args := "delay " + strconv.Itoa(experimentsDetails.NetworkLatency) + "ms " + strconv.Itoa(experimentsDetails.Jitter) + "ms" - return network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) + return network_chaos.PrepareAndInjectChaos(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) } diff --git a/chaoslib/litmus/network-chaos/lib/loss/loss.go b/chaoslib/litmus/network-chaos/lib/loss/loss.go index 424f1c9a3..a4acdb2b2 100644 --- a/chaoslib/litmus/network-chaos/lib/loss/loss.go +++ b/chaoslib/litmus/network-chaos/lib/loss/loss.go @@ -1,18 +1,21 @@ package loss import ( + "context" + network_chaos "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" + "go.opentelemetry.io/otel" ) // PodNetworkLossChaos contains the steps to prepare and inject chaos -func PodNetworkLossChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodNetworkLossChaos") +func PodNetworkLossChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkLossChaos") defer span.End() args := "loss " + experimentsDetails.NetworkPacketLossPercentage - return network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) + return network_chaos.PrepareAndInjectChaos(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args) } diff --git a/chaoslib/litmus/network-chaos/lib/network-chaos.go b/chaoslib/litmus/network-chaos/lib/network-chaos.go index 31dfffaf0..3ae0b0f17 100644 --- a/chaoslib/litmus/network-chaos/lib/network-chaos.go +++ b/chaoslib/litmus/network-chaos/lib/network-chaos.go @@ -11,6 +11,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" k8serrors "k8s.io/apimachinery/pkg/api/errors" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -31,7 +32,7 @@ var destIpsSvcMesh string var destIps string // PrepareAndInjectChaos contains the preparation & injection steps -func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, args string) error { +func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, args string) error { var err error // Get the target pod details for the chaos execution @@ -71,11 +72,11 @@ func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails experimentsDetails.IsTargetContainerProvided = experimentsDetails.TargetContainer != "" switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetPodList, clients, chaosDetails, args, resultDetails, eventsDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetPodList, clients, chaosDetails, args, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetPodList, clients, chaosDetails, args, resultDetails, eventsDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetPodList, clients, chaosDetails, args, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -86,10 +87,10 @@ func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails } // injectChaosInSerialMode inject the network chaos in all target application serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, args string, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, args string, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -109,7 +110,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai runID := stringutils.GetRunID() - if err := createHelperPod(experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer, serviceMesh), pod.Spec.NodeName, runID, args); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer, serviceMesh), pod.Spec.NodeName, runID, args); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -142,12 +143,12 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode inject the network chaos in all target application in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, args string, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, args string, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { var err error // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -165,7 +166,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet targetsPerNode = append(targetsPerNode, fmt.Sprintf("%s:%s:%s:%s", k.Name, k.Namespace, k.TargetContainer, k.ServiceMesh)) } - if err := createHelperPod(experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID, args); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID, args); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } } @@ -198,8 +199,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets string, nodeName, runID, args string) error { - span := telemetry.StartTracing(clients, "CreateNetworkChaosHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets string, nodeName, runID, args string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNetworkChaosHelperPod") defer span.End() privilegedEnable := true @@ -243,7 +244,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name network-chaos", }, Resources: chaosDetails.Resources, - Env: getPodEnv(clients.Context, experimentsDetails, targets, args), + Env: getPodEnv(ctx, experimentsDetails, targets, args), VolumeMounts: []apiv1.VolumeMount{ { Name: "cri-socket", diff --git a/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go b/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go index cacbbb9b4..aa1685c63 100644 --- a/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go +++ b/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go @@ -9,6 +9,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -25,8 +26,8 @@ import ( ) // PrepareNodeCPUHog contains preparation steps before chaos injection -func PrepareNodeCPUHog(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectNodeCPUHogChaos") +func PrepareNodeCPUHog(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeCPUHogChaos") defer span.End() //set up the tunables if provided in range @@ -65,11 +66,11 @@ func PrepareNodeCPUHog(experimentsDetails *experimentTypes.ExperimentDetails, cl switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -85,13 +86,13 @@ func PrepareNodeCPUHog(experimentsDetails *experimentTypes.ExperimentDetails, cl } // injectChaosInSerialMode stress the cpu of all the target nodes serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { nodeCPUCores := experimentsDetails.NodeCPUcores // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -119,7 +120,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai experimentsDetails.RunID = stringutils.GetRunID() // Creating the helper pod to perform node cpu hog - if err := createHelperPod(experimentsDetails, chaosDetails, appNode, clients); err != nil { + if err := createHelperPod(ctx, experimentsDetails, chaosDetails, appNode, clients); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -152,12 +153,12 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode stress the cpu of all the target nodes in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { nodeCPUCores := experimentsDetails.NodeCPUcores // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -185,7 +186,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet }) // Creating the helper pod to perform node cpu hog - if err := createHelperPod(experimentsDetails, chaosDetails, appNode, clients); err != nil { + if err := createHelperPod(ctx, experimentsDetails, chaosDetails, appNode, clients); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } } @@ -231,8 +232,8 @@ func setCPUCapacity(experimentsDetails *experimentTypes.ExperimentDetails, appNo } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets) error { - span := telemetry.StartTracing(clients, "CreateNodeCPUHogHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeCPUHogHelperPod") defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-drain/lib/node-drain.go b/chaoslib/litmus/node-drain/lib/node-drain.go index dc9a59b34..37fcb5425 100644 --- a/chaoslib/litmus/node-drain/lib/node-drain.go +++ b/chaoslib/litmus/node-drain/lib/node-drain.go @@ -14,6 +14,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -34,8 +35,8 @@ var ( ) // PrepareNodeDrain contains the preparation steps before chaos injection -func PrepareNodeDrain(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectNodeDrainChaos") +func PrepareNodeDrain(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeDrainChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -70,7 +71,7 @@ func PrepareNodeDrain(experimentsDetails *experimentTypes.ExperimentDetails, cli // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/node-io-stress/lib/node-io-stress.go b/chaoslib/litmus/node-io-stress/lib/node-io-stress.go index 1c3b1dbab..995100dba 100644 --- a/chaoslib/litmus/node-io-stress/lib/node-io-stress.go +++ b/chaoslib/litmus/node-io-stress/lib/node-io-stress.go @@ -9,6 +9,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -25,8 +26,8 @@ import ( ) // PrepareNodeIOStress contains preparation steps before chaos injection -func PrepareNodeIOStress(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectNodeIOStressChaos") +func PrepareNodeIOStress(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeIOStressChaos") defer span.End() //set up the tunables if provided in range setChaosTunables(experimentsDetails) @@ -65,11 +66,11 @@ func PrepareNodeIOStress(experimentsDetails *experimentTypes.ExperimentDetails, switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -85,11 +86,11 @@ func PrepareNodeIOStress(experimentsDetails *experimentTypes.ExperimentDetails, } // injectChaosInSerialMode stress the io of all the target nodes serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -111,7 +112,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai experimentsDetails.RunID = stringutils.GetRunID() // Creating the helper pod to perform node io stress - if err := createHelperPod(experimentsDetails, chaosDetails, appNode, clients); err != nil { + if err := createHelperPod(ctx, experimentsDetails, chaosDetails, appNode, clients); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -143,11 +144,11 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode stress the io of all the target nodes in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -169,7 +170,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet }) // Creating the helper pod to perform node io stress - if err := createHelperPod(experimentsDetails, chaosDetails, appNode, clients); err != nil { + if err := createHelperPod(ctx, experimentsDetails, chaosDetails, appNode, clients); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } } @@ -207,8 +208,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets) error { - span := telemetry.StartTracing(clients, "CreateNodeIOStressHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeIOStressHelperPod") defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go b/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go index ebe0a8cd5..1d14d0a41 100644 --- a/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go +++ b/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go @@ -9,6 +9,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -26,8 +27,8 @@ import ( ) // PrepareNodeMemoryHog contains preparation steps before chaos injection -func PrepareNodeMemoryHog(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectNodeMemoryHogChaos") +func PrepareNodeMemoryHog(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeMemoryHogChaos") defer span.End() //set up the tunables if provided in range @@ -67,11 +68,11 @@ func PrepareNodeMemoryHog(experimentsDetails *experimentTypes.ExperimentDetails, switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetNodeList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -87,11 +88,11 @@ func PrepareNodeMemoryHog(experimentsDetails *experimentTypes.ExperimentDetails, } // injectChaosInSerialMode stress the memory of all the target nodes serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -125,7 +126,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // Creating the helper pod to perform node memory hog - if err = createHelperPod(experimentsDetails, chaosDetails, appNode, clients, MemoryConsumption); err != nil { + if err = createHelperPod(ctx, experimentsDetails, chaosDetails, appNode, clients, MemoryConsumption); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -161,11 +162,11 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode stress the memory all the target nodes in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -199,7 +200,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet } // Creating the helper pod to perform node memory hog - if err = createHelperPod(experimentsDetails, chaosDetails, appNode, clients, MemoryConsumption); err != nil { + if err = createHelperPod(ctx, experimentsDetails, chaosDetails, appNode, clients, MemoryConsumption); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } } @@ -315,8 +316,8 @@ func calculateMemoryConsumption(experimentsDetails *experimentTypes.ExperimentDe } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets, MemoryConsumption string) error { - span := telemetry.StartTracing(clients, "CreateNodeMemoryHogHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets, MemoryConsumption string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeMemoryHogHelperPod") defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-restart/lib/node-restart.go b/chaoslib/litmus/node-restart/lib/node-restart.go index 074d502d5..5afa517be 100644 --- a/chaoslib/litmus/node-restart/lib/node-restart.go +++ b/chaoslib/litmus/node-restart/lib/node-restart.go @@ -9,6 +9,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -39,8 +40,8 @@ const ( ) // PrepareNodeRestart contains preparation steps before chaos injection -func PrepareNodeRestart(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectNodeRestartChaos") +func PrepareNodeRestart(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeRestartChaos") defer span.End() //Select the node @@ -84,7 +85,7 @@ func PrepareNodeRestart(experimentsDetails *experimentTypes.ExperimentDetails, c } // Creating the helper pod to perform node restart - if err = createHelperPod(experimentsDetails, chaosDetails, clients); err != nil { + if err = createHelperPod(ctx, experimentsDetails, chaosDetails, clients); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -101,7 +102,7 @@ func PrepareNodeRestart(experimentsDetails *experimentTypes.ExperimentDetails, c // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { common.DeleteAllHelperPodBasedOnJobCleanupPolicy(appLabel, chaosDetails, clients) return err } @@ -130,11 +131,11 @@ func PrepareNodeRestart(experimentsDetails *experimentTypes.ExperimentDetails, c } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, clients clients.ClientSets) error { +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, clients clients.ClientSets) error { // This method is attaching emptyDir along with secret volume, and copy data from secret // to the emptyDir, because secret is mounted as readonly and with 777 perms and it can't be changed // because of: https://github.com/kubernetes/kubernetes/issues/57923 - span := telemetry.StartTracing(clients, "CreateNodeRestartHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeRestartHelperPod") defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-taint/lib/node-taint.go b/chaoslib/litmus/node-taint/lib/node-taint.go index 72453894a..118d6bcec 100644 --- a/chaoslib/litmus/node-taint/lib/node-taint.go +++ b/chaoslib/litmus/node-taint/lib/node-taint.go @@ -12,6 +12,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -31,8 +32,8 @@ var ( ) // PrepareNodeTaint contains the preparation steps before chaos injection -func PrepareNodeTaint(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectNodeTaintChaos") +func PrepareNodeTaint(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeTaintChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -67,7 +68,7 @@ func PrepareNodeTaint(experimentsDetails *experimentTypes.ExperimentDetails, cli // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go b/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go index 2161d75fe..915f9979d 100644 --- a/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go +++ b/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go @@ -12,6 +12,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-autoscaler/types" @@ -34,8 +35,8 @@ var ( ) // PreparePodAutoscaler contains the preparation steps and chaos injection steps -func PreparePodAutoscaler(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodAutoScalerChaos") +func PreparePodAutoscaler(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodAutoScalerChaos") defer span.End() //Waiting for the ramp time before chaos injection @@ -68,7 +69,7 @@ func PreparePodAutoscaler(experimentsDetails *experimentTypes.ExperimentDetails, //calling go routine which will continuously watch for the abort signal go abortPodAutoScalerChaos(appsUnderTest, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails) - if err = podAutoscalerChaosInDeployment(experimentsDetails, clients, appsUnderTest, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = podAutoscalerChaosInDeployment(ctx, experimentsDetails, clients, appsUnderTest, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not scale deployment") } @@ -95,7 +96,7 @@ func PreparePodAutoscaler(experimentsDetails *experimentTypes.ExperimentDetails, //calling go routine which will continuously watch for the abort signal go abortPodAutoScalerChaos(appsUnderTest, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails) - if err = podAutoscalerChaosInStatefulset(experimentsDetails, clients, appsUnderTest, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = podAutoscalerChaosInStatefulset(ctx, experimentsDetails, clients, appsUnderTest, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not scale statefulset") } @@ -159,7 +160,7 @@ func getStatefulsetDetails(experimentsDetails *experimentTypes.ExperimentDetails } // podAutoscalerChaosInDeployment scales up the replicas of deployment and verify the status -func podAutoscalerChaosInDeployment(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, appsUnderTest []experimentTypes.ApplicationUnderTest, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func podAutoscalerChaosInDeployment(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, appsUnderTest []experimentTypes.ApplicationUnderTest, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // Scale Application retryErr := retries.RetryOnConflict(retries.DefaultRetry, func() error { @@ -186,11 +187,11 @@ func podAutoscalerChaosInDeployment(experimentsDetails *experimentTypes.Experime } log.Info("[Info]: The application started scaling") - return deploymentStatusCheck(experimentsDetails, clients, appsUnderTest, resultDetails, eventsDetails, chaosDetails) + return deploymentStatusCheck(ctx, experimentsDetails, clients, appsUnderTest, resultDetails, eventsDetails, chaosDetails) } // podAutoscalerChaosInStatefulset scales up the replicas of statefulset and verify the status -func podAutoscalerChaosInStatefulset(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, appsUnderTest []experimentTypes.ApplicationUnderTest, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func podAutoscalerChaosInStatefulset(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, appsUnderTest []experimentTypes.ApplicationUnderTest, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // Scale Application retryErr := retries.RetryOnConflict(retries.DefaultRetry, func() error { @@ -216,11 +217,11 @@ func podAutoscalerChaosInStatefulset(experimentsDetails *experimentTypes.Experim } log.Info("[Info]: The application started scaling") - return statefulsetStatusCheck(experimentsDetails, clients, appsUnderTest, resultDetails, eventsDetails, chaosDetails) + return statefulsetStatusCheck(ctx, experimentsDetails, clients, appsUnderTest, resultDetails, eventsDetails, chaosDetails) } // deploymentStatusCheck check the status of deployment and verify the available replicas -func deploymentStatusCheck(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, appsUnderTest []experimentTypes.ApplicationUnderTest, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func deploymentStatusCheck(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, appsUnderTest []experimentTypes.ApplicationUnderTest, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -250,7 +251,7 @@ func deploymentStatusCheck(experimentsDetails *experimentTypes.ExperimentDetails // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -265,7 +266,7 @@ func deploymentStatusCheck(experimentsDetails *experimentTypes.ExperimentDetails } // statefulsetStatusCheck check the status of statefulset and verify the available replicas -func statefulsetStatusCheck(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, appsUnderTest []experimentTypes.ApplicationUnderTest, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func statefulsetStatusCheck(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, appsUnderTest []experimentTypes.ApplicationUnderTest, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -295,7 +296,7 @@ func statefulsetStatusCheck(experimentsDetails *experimentTypes.ExperimentDetail // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go b/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go index 8fa4eba6f..22d7234a2 100644 --- a/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go +++ b/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -11,6 +12,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -28,8 +30,8 @@ import ( var inject chan os.Signal // PrepareCPUExecStress contains the chaos preparation and injection steps -func PrepareCPUExecStress(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectCPUExecStressChaos") +func PrepareCPUExecStress(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectCPUExecStressChaos") defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) @@ -42,7 +44,7 @@ func PrepareCPUExecStress(experimentsDetails *experimentTypes.ExperimentDetails, common.WaitForDuration(experimentsDetails.RampTime) } //Starting the CPU stress experiment - if err := experimentCPU(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := experimentCPU(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not stress cpu") } //Waiting for the ramp time after chaos injection @@ -66,7 +68,7 @@ func stressCPU(experimentsDetails *experimentTypes.ExperimentDetails, podName, n } // experimentCPU function orchestrates the experiment by calling the StressCPU function for every core, of every container, of every pod that is targeted -func experimentCPU(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func experimentCPU(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage @@ -88,11 +90,11 @@ func experimentCPU(experimentsDetails *experimentTypes.ExperimentDetails, client experimentsDetails.IsTargetContainerProvided = experimentsDetails.TargetContainer != "" switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -103,11 +105,11 @@ func experimentCPU(experimentsDetails *experimentTypes.ExperimentDetails, client } // injectChaosInSerialMode stressed the cpu of all target application serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -200,13 +202,13 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode stressed the cpu of all target application in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // creating err channel to receive the error from the go routine stressErr := make(chan error) // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/pod-delete/lib/pod-delete.go b/chaoslib/litmus/pod-delete/lib/pod-delete.go index f66981a91..0553c403f 100644 --- a/chaoslib/litmus/pod-delete/lib/pod-delete.go +++ b/chaoslib/litmus/pod-delete/lib/pod-delete.go @@ -20,12 +20,13 @@ import ( "github.com/litmuschaos/litmus-go/pkg/workloads" "github.com/palantir/stacktrace" "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // PreparePodDelete contains the preparation steps before chaos injection -func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodDeleteChaos") +func PreparePodDelete(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodDeleteChaos") defer span.End() //Waiting for the ramp time before chaos injection @@ -44,11 +45,11 @@ func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, cli switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err := injectChaosInSerialMode(experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { + if err := injectChaosInSerialMode(ctx, experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err := injectChaosInParallelMode(experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { + if err := injectChaosInParallelMode(ctx, experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -64,11 +65,11 @@ func PreparePodDelete(experimentsDetails *experimentTypes.ExperimentDetails, cli } // injectChaosInSerialMode delete the target application pods serial mode(one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -161,11 +162,11 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode delete the target application pods in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go b/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go index fe81c0d3c..a0071896c 100644 --- a/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go +++ b/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go @@ -10,6 +10,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-dns-chaos/types" @@ -26,8 +27,8 @@ import ( ) // PrepareAndInjectChaos contains the preparation & injection steps -func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodDNSChaos") +func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodDNSChaos") defer span.End() // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage @@ -68,11 +69,11 @@ func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails experimentsDetails.IsTargetContainerProvided = experimentsDetails.TargetContainer != "" switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -83,11 +84,11 @@ func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails } // injectChaosInSerialMode inject the DNS Chaos in all target application serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -106,7 +107,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai "ContainerName": experimentsDetails.TargetContainer, }) runID := stringutils.GetRunID() - if err := createHelperPod(experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer), pod.Spec.NodeName, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer), pod.Spec.NodeName, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -139,12 +140,12 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode inject the DNS Chaos in all target application in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { var err error // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -158,7 +159,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet targetsPerNode = append(targetsPerNode, fmt.Sprintf("%s:%s:%s", k.Name, k.Namespace, k.TargetContainer)) } - if err := createHelperPod(experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } } @@ -195,8 +196,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { - span := telemetry.StartTracing(clients, "CreatePodDNSChaosHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreatePodDNSChaosHelperPod") defer span.End() privilegedEnable := true terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) @@ -239,7 +240,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name dns-chaos", }, Resources: chaosDetails.Resources, - Env: getPodEnv(clients.Context, experimentsDetails, targets), + Env: getPodEnv(ctx, experimentsDetails, targets), VolumeMounts: []apiv1.VolumeMount{ { Name: "cri-socket", diff --git a/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go b/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go index 5586a6d5d..0b7cc1389 100644 --- a/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go +++ b/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -12,6 +13,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/result" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -26,8 +28,8 @@ import ( ) // PrepareChaos contains the chaos preparation and injection steps -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPidFIOStressChaos") +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPidFIOStressChaos") defer span.End() //Waiting for the ramp time before chaos injection @@ -36,7 +38,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients common.WaitForDuration(experimentsDetails.RampTime) } //Starting the Fio stress experiment - if err := experimentExecution(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := experimentExecution(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not inject chaos") } //Waiting for the ramp time after chaos injection @@ -70,7 +72,7 @@ func stressStorage(experimentDetails *experimentTypes.ExperimentDetails, podName } // experimentExecution function orchestrates the experiment by calling the StressStorage function, of every container, of every pod that is targeted -func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func experimentExecution(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage @@ -92,11 +94,11 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, experimentsDetails.IsTargetContainerProvided = experimentsDetails.TargetContainer != "" switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -107,12 +109,12 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, } // injectChaosInSerialMode stressed the storage of all target application in serial mode (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // creating err channel to receive the error from the go routine stressErr := make(chan error) // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -188,12 +190,12 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode stressed the storage of all target application in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // creating err channel to receive the error from the go routine stressErr := make(chan error) // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go b/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go index ac56694c9..6ae51c8f6 100644 --- a/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go +++ b/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -12,6 +13,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" @@ -29,8 +31,8 @@ import ( var inject chan os.Signal // PrepareMemoryExecStress contains the chaos preparation and injection steps -func PrepareMemoryExecStress(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodMemoryHogChaos") +func PrepareMemoryExecStress(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodMemoryHogChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -44,7 +46,7 @@ func PrepareMemoryExecStress(experimentsDetails *experimentTypes.ExperimentDetai common.WaitForDuration(experimentsDetails.RampTime) } //Starting the Memory stress experiment - if err := experimentMemory(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := experimentMemory(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not stress memory") } //Waiting for the ramp time after chaos injection @@ -75,7 +77,7 @@ func stressMemory(MemoryConsumption, containerName, podName, namespace string, c } // experimentMemory function orchestrates the experiment by calling the StressMemory function, of every container, of every pod that is targeted -func experimentMemory(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func experimentMemory(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage @@ -97,11 +99,11 @@ func experimentMemory(experimentsDetails *experimentTypes.ExperimentDetails, cli experimentsDetails.IsTargetContainerProvided = experimentsDetails.TargetContainer != "" switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -112,11 +114,11 @@ func experimentMemory(experimentsDetails *experimentTypes.ExperimentDetails, cli } // injectChaosInSerialMode stressed the memory of all target application serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -206,12 +208,12 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode stressed the memory of all target application in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // creating err channel to receive the error from the go routine stressErr := make(chan error) // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go b/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go index 7292c33e3..79fffbe69 100644 --- a/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go +++ b/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go @@ -12,6 +12,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-network-partition/types" @@ -33,8 +34,8 @@ var ( ) // PrepareAndInjectChaos contains the prepration & injection steps -func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectPodNetworkPartitionChaos") +func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkPartitionChaos") defer span.End() // inject channel is used to transmit signal notifications. @@ -94,7 +95,7 @@ func PrepareAndInjectChaos(experimentsDetails *experimentTypes.ExperimentDetails // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go b/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go index a010f049a..bd76590ad 100644 --- a/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go +++ b/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "time" @@ -14,6 +15,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) // injectChaos initiates node restart chaos on the target node @@ -23,11 +25,11 @@ func injectChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients } // experimentExecution function orchestrates the experiment by calling the injectChaos function -func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func experimentExecution(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -48,8 +50,8 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, } // PrepareChaos contains the chaos prepration and injection steps -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectRedfishNodeRestartChaos") +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectRedfishNodeRestartChaos") defer span.End() //Waiting for the ramp time before chaos injection @@ -58,7 +60,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients common.WaitForDuration(experimentsDetails.RampTime) } //Starting the Redfish node restart experiment - if err := experimentExecution(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := experimentExecution(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return err } common.SetTargets(experimentsDetails.IPMIIP, "targeted", "node", chaosDetails) diff --git a/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go b/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go index 3e22a58fb..29fe4f7c0 100644 --- a/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go +++ b/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go @@ -2,6 +2,7 @@ package lib import ( "bytes" + "context" "encoding/json" "fmt" "net/http" @@ -14,6 +15,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" corev1 "k8s.io/api/core/v1" "github.com/litmuschaos/litmus-go/pkg/clients" @@ -52,8 +54,8 @@ func SetTargetPodList(experimentsDetails *experimentTypes.ExperimentDetails, cli } // PrepareChaos contains the preparation steps before chaos injection -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectSpringBootChaos") +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectSpringBootChaos") defer span.End() // Waiting for the ramp time before chaos injection @@ -73,11 +75,11 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err := injectChaosInSerialMode(experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { + if err := injectChaosInSerialMode(ctx, experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err := injectChaosInParallelMode(experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { + if err := injectChaosInParallelMode(ctx, experimentsDetails, clients, chaosDetails, eventsDetails, resultDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -191,7 +193,7 @@ func setChaosMonkeyAssault(chaosMonkeyPort string, chaosMonkeyPath string, assau } // disableChaosMonkey disables chaos monkey on selected pods -func disableChaosMonkey(chaosMonkeyPort string, chaosMonkeyPath string, pod corev1.Pod) error { +func disableChaosMonkey(ctx context.Context, chaosMonkeyPort string, chaosMonkeyPath string, pod corev1.Pod) error { log.Infof("[Chaos]: disabling assaults on pod %s", pod.Name) jsonValue, err := json.Marshal(revertAssault) if err != nil { @@ -215,11 +217,11 @@ func disableChaosMonkey(chaosMonkeyPort string, chaosMonkeyPath string, pod core } // injectChaosInSerialMode injects chaos monkey assault on pods in serial mode(one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -273,7 +275,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai select { case <-signChan: log.Info("[Chaos]: Revert Started") - if err := disableChaosMonkey(experimentsDetails.ChaosMonkeyPort, experimentsDetails.ChaosMonkeyPath, pod); err != nil { + if err := disableChaosMonkey(ctx, experimentsDetails.ChaosMonkeyPort, experimentsDetails.ChaosMonkeyPath, pod); err != nil { log.Errorf("Error in disabling chaos monkey, err: %v", err) } else { common.SetTargets(pod.Name, "reverted", "pod", chaosDetails) @@ -291,7 +293,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } } - if err := disableChaosMonkey(experimentsDetails.ChaosMonkeyPort, experimentsDetails.ChaosMonkeyPath, pod); err != nil { + if err := disableChaosMonkey(ctx, experimentsDetails.ChaosMonkeyPort, experimentsDetails.ChaosMonkeyPath, pod); err != nil { return err } @@ -303,11 +305,11 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode injects chaos monkey assault on pods in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -362,7 +364,7 @@ loop: case <-signChan: log.Info("[Chaos]: Revert Started") for _, pod := range experimentsDetails.TargetPodList.Items { - if err := disableChaosMonkey(experimentsDetails.ChaosMonkeyPort, experimentsDetails.ChaosMonkeyPath, pod); err != nil { + if err := disableChaosMonkey(ctx, experimentsDetails.ChaosMonkeyPort, experimentsDetails.ChaosMonkeyPath, pod); err != nil { log.Errorf("Error in disabling chaos monkey, err: %v", err) } else { common.SetTargets(pod.Name, "reverted", "pod", chaosDetails) @@ -383,7 +385,7 @@ loop: var errorList []string for _, pod := range experimentsDetails.TargetPodList.Items { - if err := disableChaosMonkey(experimentsDetails.ChaosMonkeyPort, experimentsDetails.ChaosMonkeyPath, pod); err != nil { + if err := disableChaosMonkey(ctx, experimentsDetails.ChaosMonkeyPort, experimentsDetails.ChaosMonkeyPath, pod); err != nil { errorList = append(errorList, err.Error()) continue } diff --git a/chaoslib/litmus/stress-chaos/lib/stress-chaos.go b/chaoslib/litmus/stress-chaos/lib/stress-chaos.go index 73ef6b458..8aa6a8461 100644 --- a/chaoslib/litmus/stress-chaos/lib/stress-chaos.go +++ b/chaoslib/litmus/stress-chaos/lib/stress-chaos.go @@ -10,6 +10,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "github.com/litmuschaos/litmus-go/pkg/clients" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/stress-chaos/types" @@ -25,8 +26,8 @@ import ( ) // PrepareAndInjectStressChaos contains the prepration & injection steps for the stress experiments. -func PrepareAndInjectStressChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - span := telemetry.StartTracing(clients, "InjectStressChaos") +func PrepareAndInjectStressChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectStressChaos") defer span.End() var err error //Set up the tunables if provided in range @@ -92,11 +93,11 @@ func PrepareAndInjectStressChaos(experimentsDetails *experimentTypes.ExperimentD experimentsDetails.IsTargetContainerProvided = experimentsDetails.TargetContainer != "" switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetPodList, clients, chaosDetails, resultDetails, eventsDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -107,11 +108,11 @@ func PrepareAndInjectStressChaos(experimentsDetails *experimentTypes.ExperimentD } // injectChaosInSerialMode inject the stress chaos in all target application serially (one by one) -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -130,7 +131,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai "ContainerName": experimentsDetails.TargetContainer, }) runID := stringutils.GetRunID() - if err := createHelperPod(experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer), pod.Spec.NodeName, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, fmt.Sprintf("%s:%s:%s", pod.Name, pod.Namespace, experimentsDetails.TargetContainer), pod.Spec.NodeName, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -163,12 +164,12 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode inject the stress chaos in all target application in parallel mode (all at once) -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { var err error // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -182,7 +183,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet targetsPerNode = append(targetsPerNode, fmt.Sprintf("%s:%s:%s", k.Name, k.Namespace, k.TargetContainer)) } - if err := createHelperPod(experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, strings.Join(targetsPerNode, ";"), node, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } } @@ -216,8 +217,8 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { - span := telemetry.StartTracing(clients, "CreateStressHelperPod") +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateStressHelperPod") defer span.End() privilegedEnable := true @@ -270,7 +271,7 @@ func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clie "./helpers -name stress-chaos", }, Resources: chaosDetails.Resources, - Env: getPodEnv(clients.Context, experimentsDetails, targets), + Env: getPodEnv(ctx, experimentsDetails, targets), VolumeMounts: []apiv1.VolumeMount{ { Name: "socket-path", diff --git a/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go b/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go index 97f59a9bb..084ceff6b 100644 --- a/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go +++ b/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "os/signal" @@ -19,13 +20,14 @@ import ( "github.com/litmuschaos/litmus-go/pkg/utils/common" experimentTypes "github.com/litmuschaos/litmus-go/pkg/vmware/vm-poweroff/types" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) var inject, abort chan os.Signal // InjectVMPowerOffChaos injects the chaos in serial or parallel mode -func InjectVMPowerOffChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, cookie string) error { - span := telemetry.StartTracing(clients, "InjectVMPowerOffChaos") +func InjectVMPowerOffChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, cookie string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMPowerOffChaos") defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) @@ -51,11 +53,11 @@ func InjectVMPowerOffChaos(experimentsDetails *experimentTypes.ExperimentDetails switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err := injectChaosInSerialMode(experimentsDetails, vmIdList, cookie, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := injectChaosInSerialMode(ctx, experimentsDetails, vmIdList, cookie, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err := injectChaosInParallelMode(experimentsDetails, vmIdList, cookie, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err := injectChaosInParallelMode(ctx, experimentsDetails, vmIdList, cookie, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -72,7 +74,7 @@ func InjectVMPowerOffChaos(experimentsDetails *experimentTypes.ExperimentDetails } // injectChaosInSerialMode stops VMs in serial mode i.e. one after the other -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, vmIdList []string, cookie string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, vmIdList []string, cookie string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: // stopping the chaos execution, if abort signal received @@ -111,7 +113,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai //Run the probes during the chaos //The OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } @@ -143,7 +145,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode stops VMs in parallel mode i.e. all at once -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, vmIdList []string, cookie string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, vmIdList []string, cookie string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -186,7 +188,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet //Running the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return stacktrace.Propagate(err, "failed to run probes") } } diff --git a/experiments/aws-ssm/aws-ssm-chaos-by-id/experiment/aws-ssm-chaos-by-id.go b/experiments/aws-ssm/aws-ssm-chaos-by-id/experiment/aws-ssm-chaos-by-id.go index cf3445cf2..4edeaf6d3 100644 --- a/experiments/aws-ssm/aws-ssm-chaos-by-id/experiment/aws-ssm-chaos-by-id.go +++ b/experiments/aws-ssm/aws-ssm-chaos-by-id/experiment/aws-ssm-chaos-by-id.go @@ -1,13 +1,14 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/aws-ssm-chaos/lib/ssm" experimentEnv "github.com/litmuschaos/litmus-go/pkg/aws-ssm/aws-ssm-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/aws-ssm/aws-ssm-chaos/types" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" ec2 "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ec2" "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ssm" "github.com/litmuschaos/litmus-go/pkg/events" @@ -20,7 +21,7 @@ import ( ) // AWSSSMChaosByID inject the ssm chaos on ec2 instance -func AWSSSMChaosByID(clients clients.ClientSets) { +func AWSSSMChaosByID(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -80,7 +81,7 @@ func AWSSSMChaosByID(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -118,7 +119,7 @@ func AWSSSMChaosByID(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareAWSSSMChaosByID(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareAWSSSMChaosByID(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) //Delete the ssm document on the given aws service monitoring docs @@ -152,7 +153,7 @@ func AWSSSMChaosByID(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/aws-ssm/aws-ssm-chaos-by-tag/experiment/aws-ssm-chaos-by-tag.go b/experiments/aws-ssm/aws-ssm-chaos-by-tag/experiment/aws-ssm-chaos-by-tag.go index d287e4be6..1799ac322 100644 --- a/experiments/aws-ssm/aws-ssm-chaos-by-tag/experiment/aws-ssm-chaos-by-tag.go +++ b/experiments/aws-ssm/aws-ssm-chaos-by-tag/experiment/aws-ssm-chaos-by-tag.go @@ -1,13 +1,14 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/aws-ssm-chaos/lib/ssm" experimentEnv "github.com/litmuschaos/litmus-go/pkg/aws-ssm/aws-ssm-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/aws-ssm/aws-ssm-chaos/types" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" ec2 "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ec2" "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ssm" "github.com/litmuschaos/litmus-go/pkg/events" @@ -20,7 +21,7 @@ import ( ) // AWSSSMChaosByTag inject the ssm chaos on ec2 instance -func AWSSSMChaosByTag(clients clients.ClientSets) { +func AWSSSMChaosByTag(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -88,7 +89,7 @@ func AWSSSMChaosByTag(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -109,7 +110,7 @@ func AWSSSMChaosByTag(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareAWSSSMChaosByTag(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareAWSSSMChaosByTag(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) //Delete the ssm document on the given aws service monitoring docs @@ -143,7 +144,7 @@ func AWSSSMChaosByTag(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/azure/azure-disk-loss/experiment/azure-disk-loss.go b/experiments/azure/azure-disk-loss/experiment/azure-disk-loss.go index 9887f81bd..85507b7ad 100644 --- a/experiments/azure/azure-disk-loss/experiment/azure-disk-loss.go +++ b/experiments/azure/azure-disk-loss/experiment/azure-disk-loss.go @@ -1,13 +1,14 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/azure-disk-loss/lib" experimentEnv "github.com/litmuschaos/litmus-go/pkg/azure/disk-loss/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/azure/disk-loss/types" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" azureCommon "github.com/litmuschaos/litmus-go/pkg/cloud/azure/common" azureStatus "github.com/litmuschaos/litmus-go/pkg/cloud/azure/disk" "github.com/litmuschaos/litmus-go/pkg/events" @@ -20,7 +21,7 @@ import ( ) // AzureDiskLoss contains steps to inject chaos -func AzureDiskLoss(clients clients.ClientSets) { +func AzureDiskLoss(ctx context.Context, clients clients.ClientSets) { var err error experimentsDetails := experimentTypes.ExperimentDetails{} @@ -99,7 +100,7 @@ func AzureDiskLoss(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -120,7 +121,7 @@ func AzureDiskLoss(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err = litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err = litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) log.Errorf("Chaos injection failed: %v", err) return @@ -147,7 +148,7 @@ func AzureDiskLoss(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/azure/instance-stop/experiment/azure-instance-stop.go b/experiments/azure/instance-stop/experiment/azure-instance-stop.go index a934c5302..74b3424c8 100644 --- a/experiments/azure/instance-stop/experiment/azure-instance-stop.go +++ b/experiments/azure/instance-stop/experiment/azure-instance-stop.go @@ -1,13 +1,14 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/azure-instance-stop/lib" experimentEnv "github.com/litmuschaos/litmus-go/pkg/azure/instance-stop/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/azure/instance-stop/types" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" azureCommon "github.com/litmuschaos/litmus-go/pkg/cloud/azure/common" azureStatus "github.com/litmuschaos/litmus-go/pkg/cloud/azure/instance" @@ -21,7 +22,7 @@ import ( ) // AzureInstanceStop inject the azure instance stop chaos -func AzureInstanceStop(clients clients.ClientSets) { +func AzureInstanceStop(ctx context.Context, clients clients.ClientSets) { var err error experimentsDetails := experimentTypes.ExperimentDetails{} @@ -90,7 +91,7 @@ func AzureInstanceStop(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) if err != nil { log.Errorf("Probe Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" @@ -122,7 +123,7 @@ func AzureInstanceStop(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err = litmusLIB.PrepareAzureStop(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err = litmusLIB.PrepareAzureStop(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -149,7 +150,7 @@ func AzureInstanceStop(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) if err != nil { log.Errorf("Probes Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" diff --git a/experiments/baremetal/redfish-node-restart/experiment/redfish-node-restart.go b/experiments/baremetal/redfish-node-restart/experiment/redfish-node-restart.go index e0d9a1b45..7b9ae654d 100644 --- a/experiments/baremetal/redfish-node-restart/experiment/redfish-node-restart.go +++ b/experiments/baremetal/redfish-node-restart/experiment/redfish-node-restart.go @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -8,7 +9,7 @@ import ( redfishLib "github.com/litmuschaos/litmus-go/pkg/baremetal/redfish" experimentEnv "github.com/litmuschaos/litmus-go/pkg/baremetal/redfish-node-restart/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/baremetal/redfish-node-restart/types" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" @@ -20,7 +21,7 @@ import ( ) // NodeRestart contains steps to inject chaos -func NodeRestart(clients clients.ClientSets) { +func NodeRestart(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -112,7 +113,7 @@ func NodeRestart(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "NUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -129,7 +130,7 @@ func NodeRestart(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) log.Errorf("Chaos injection failed, err: %v", err) return @@ -181,7 +182,7 @@ func NodeRestart(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "NUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/cassandra/pod-delete/experiment/pod-delete.go b/experiments/cassandra/pod-delete/experiment/pod-delete.go index c4af00d31..6e7417d48 100644 --- a/experiments/cassandra/pod-delete/experiment/pod-delete.go +++ b/experiments/cassandra/pod-delete/experiment/pod-delete.go @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -8,7 +9,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/cassandra" experimentEnv "github.com/litmuschaos/litmus-go/pkg/cassandra/pod-delete/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/cassandra/pod-delete/types" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" @@ -20,7 +21,7 @@ import ( ) // CasssandraPodDelete inject the cassandra-pod-delete chaos -func CasssandraPodDelete(clients clients.ClientSets) { +func CasssandraPodDelete(ctx context.Context, clients clients.ClientSets) { var err error var ResourceVersionBefore string @@ -102,7 +103,7 @@ func CasssandraPodDelete(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg = common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -132,7 +133,7 @@ func CasssandraPodDelete(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err = litmusLIB.PreparePodDelete(experimentsDetails.ChaoslibDetail, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err = litmusLIB.PreparePodDelete(ctx, experimentsDetails.ChaoslibDetail, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -169,7 +170,7 @@ func CasssandraPodDelete(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg = common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/gcp/gcp-vm-disk-loss-by-label/experiment/gcp-vm-disk-loss-by-label.go b/experiments/gcp/gcp-vm-disk-loss-by-label/experiment/gcp-vm-disk-loss-by-label.go index 446d6aa3f..644aea20f 100644 --- a/experiments/gcp/gcp-vm-disk-loss-by-label/experiment/gcp-vm-disk-loss-by-label.go +++ b/experiments/gcp/gcp-vm-disk-loss-by-label/experiment/gcp-vm-disk-loss-by-label.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/cloud/gcp" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/gcp/gcp-vm-disk-loss/environment" @@ -20,7 +21,7 @@ import ( ) // GCPVMDiskLossByLabel contains steps to inject chaos -func GCPVMDiskLossByLabel(clients clients.ClientSets) { +func GCPVMDiskLossByLabel(ctx context.Context, clients clients.ClientSets) { var ( computeService *compute.Service @@ -83,7 +84,7 @@ func GCPVMDiskLossByLabel(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -117,7 +118,7 @@ func GCPVMDiskLossByLabel(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareDiskVolumeLossByLabel(computeService, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareDiskVolumeLossByLabel(ctx, computeService, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -146,7 +147,7 @@ func GCPVMDiskLossByLabel(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/gcp/gcp-vm-disk-loss/experiment/gcp-vm-disk-loss.go b/experiments/gcp/gcp-vm-disk-loss/experiment/gcp-vm-disk-loss.go index abb182a9e..be1adbc8a 100644 --- a/experiments/gcp/gcp-vm-disk-loss/experiment/gcp-vm-disk-loss.go +++ b/experiments/gcp/gcp-vm-disk-loss/experiment/gcp-vm-disk-loss.go @@ -1,12 +1,13 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/gcp-vm-disk-loss/lib" "github.com/litmuschaos/litmus-go/pkg/clients" - gcp "github.com/litmuschaos/litmus-go/pkg/cloud/gcp" + "github.com/litmuschaos/litmus-go/pkg/cloud/gcp" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/gcp/gcp-vm-disk-loss/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/gcp/gcp-vm-disk-loss/types" @@ -20,7 +21,7 @@ import ( ) // VMDiskLoss injects the disk volume loss chaos -func VMDiskLoss(clients clients.ClientSets) { +func VMDiskLoss(ctx context.Context, clients clients.ClientSets) { var ( computeService *compute.Service @@ -83,7 +84,7 @@ func VMDiskLoss(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -125,7 +126,7 @@ func VMDiskLoss(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err = litmusLIB.PrepareDiskVolumeLoss(computeService, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err = litmusLIB.PrepareDiskVolumeLoss(ctx, computeService, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -152,7 +153,7 @@ func VMDiskLoss(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/gcp/gcp-vm-instance-stop-by-label/experiment/gcp-vm-instance-stop-by-label.go b/experiments/gcp/gcp-vm-instance-stop-by-label/experiment/gcp-vm-instance-stop-by-label.go index a4075b0ac..30dc7d7c5 100644 --- a/experiments/gcp/gcp-vm-instance-stop-by-label/experiment/gcp-vm-instance-stop-by-label.go +++ b/experiments/gcp/gcp-vm-instance-stop-by-label/experiment/gcp-vm-instance-stop-by-label.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/cloud/gcp" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/gcp/gcp-vm-instance-stop/environment" @@ -20,7 +21,7 @@ import ( ) // GCPVMInstanceStopByLabel contains steps to inject chaos -func GCPVMInstanceStopByLabel(clients clients.ClientSets) { +func GCPVMInstanceStopByLabel(ctx context.Context, clients clients.ClientSets) { var ( computeService *compute.Service @@ -84,7 +85,7 @@ func GCPVMInstanceStopByLabel(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -118,7 +119,7 @@ func GCPVMInstanceStopByLabel(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareVMStopByLabel(computeService, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareVMStopByLabel(ctx, computeService, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -146,7 +147,7 @@ func GCPVMInstanceStopByLabel(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/gcp/gcp-vm-instance-stop/experiment/gcp-vm-instance-stop.go b/experiments/gcp/gcp-vm-instance-stop/experiment/gcp-vm-instance-stop.go index 7f3cbfb1b..8da11f7f7 100644 --- a/experiments/gcp/gcp-vm-instance-stop/experiment/gcp-vm-instance-stop.go +++ b/experiments/gcp/gcp-vm-instance-stop/experiment/gcp-vm-instance-stop.go @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -20,7 +21,7 @@ import ( ) // VMInstanceStop executes the experiment steps by injecting chaos into the specified vm instances -func VMInstanceStop(clients clients.ClientSets) { +func VMInstanceStop(ctx context.Context, clients clients.ClientSets) { var ( computeService *compute.Service @@ -83,7 +84,7 @@ func VMInstanceStop(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -119,7 +120,7 @@ func VMInstanceStop(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareVMStop(computeService, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareVMStop(ctx, computeService, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -147,7 +148,7 @@ func VMInstanceStop(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/container-kill/experiment/container-kill.go b/experiments/generic/container-kill/experiment/container-kill.go index 7c06c37fc..05d3f8f80 100644 --- a/experiments/generic/container-kill/experiment/container-kill.go +++ b/experiments/generic/container-kill/experiment/container-kill.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/container-kill/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/container-kill/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/container-kill/types" @@ -19,7 +20,7 @@ import ( ) // ContainerKill inject the container-kill chaos -func ContainerKill(clients clients.ClientSets) { +func ContainerKill(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func ContainerKill(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg = common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func ContainerKill(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareContainerKill(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareContainerKill(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func ContainerKill(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg = common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/disk-fill/experiment/disk-fill.go b/experiments/generic/disk-fill/experiment/disk-fill.go index 4e8a73741..19546d0e6 100644 --- a/experiments/generic/disk-fill/experiment/disk-fill.go +++ b/experiments/generic/disk-fill/experiment/disk-fill.go @@ -1,9 +1,12 @@ package experiment import ( + "context" + "os" + "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/disk-fill/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/types" @@ -14,11 +17,10 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/sirupsen/logrus" - "os" ) // DiskFill inject the disk-fill chaos -func DiskFill(clients clients.ClientSets) { +func DiskFill(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -88,7 +90,7 @@ func DiskFill(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg = common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -104,7 +106,7 @@ func DiskFill(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareDiskFill(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareDiskFill(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -132,7 +134,7 @@ func DiskFill(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg = common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/docker-service-kill/experiment/docker-service-kill.go b/experiments/generic/docker-service-kill/experiment/docker-service-kill.go index f93156e4f..06ed1d565 100644 --- a/experiments/generic/docker-service-kill/experiment/docker-service-kill.go +++ b/experiments/generic/docker-service-kill/experiment/docker-service-kill.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/docker-service-kill/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/docker-service-kill/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/docker-service-kill/types" @@ -19,7 +20,7 @@ import ( ) // DockerServiceKill inject the docker-service-kill chaos -func DockerServiceKill(clients clients.ClientSets) { +func DockerServiceKill(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -107,7 +108,7 @@ func DockerServiceKill(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -123,7 +124,7 @@ func DockerServiceKill(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareDockerServiceKill(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareDockerServiceKill(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) log.Errorf("Chaos injection failed, err: %v", err) return @@ -167,7 +168,7 @@ func DockerServiceKill(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/kubelet-service-kill/experiment/kubelet-service-kill.go b/experiments/generic/kubelet-service-kill/experiment/kubelet-service-kill.go index 2aaebafd1..c78f065ed 100644 --- a/experiments/generic/kubelet-service-kill/experiment/kubelet-service-kill.go +++ b/experiments/generic/kubelet-service-kill/experiment/kubelet-service-kill.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/kubelet-service-kill/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/kubelet-service-kill/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/kubelet-service-kill/types" @@ -19,7 +20,7 @@ import ( ) // KubeletServiceKill inject the kubelet-service-kill chaos -func KubeletServiceKill(clients clients.ClientSets) { +func KubeletServiceKill(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -107,7 +108,7 @@ func KubeletServiceKill(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -123,7 +124,7 @@ func KubeletServiceKill(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareKubeletKill(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareKubeletKill(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -167,7 +168,7 @@ func KubeletServiceKill(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/node-cpu-hog/experiment/node-cpu-hog.go b/experiments/generic/node-cpu-hog/experiment/node-cpu-hog.go index a035acfdf..5fbd0248a 100644 --- a/experiments/generic/node-cpu-hog/experiment/node-cpu-hog.go +++ b/experiments/generic/node-cpu-hog/experiment/node-cpu-hog.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/node-cpu-hog/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/node-cpu-hog/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-cpu-hog/types" @@ -19,7 +20,7 @@ import ( ) // NodeCPUHog inject the node-cpu-hog chaos -func NodeCPUHog(clients clients.ClientSets) { +func NodeCPUHog(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -108,7 +109,7 @@ func NodeCPUHog(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -124,7 +125,7 @@ func NodeCPUHog(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareNodeCPUHog(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareNodeCPUHog(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("[Error]: CPU hog failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -168,7 +169,7 @@ func NodeCPUHog(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/node-drain/experiment/node-drain.go b/experiments/generic/node-drain/experiment/node-drain.go index 8e709bcd2..9b6533b17 100644 --- a/experiments/generic/node-drain/experiment/node-drain.go +++ b/experiments/generic/node-drain/experiment/node-drain.go @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -19,7 +20,7 @@ import ( ) // NodeDrain inject the node-drain chaos -func NodeDrain(clients clients.ClientSets) { +func NodeDrain(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -107,7 +108,7 @@ func NodeDrain(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -123,7 +124,7 @@ func NodeDrain(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareNodeDrain(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareNodeDrain(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -167,7 +168,7 @@ func NodeDrain(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/node-io-stress/experiment/node-io-stress.go b/experiments/generic/node-io-stress/experiment/node-io-stress.go index 1b76fa841..a58e0f2e5 100644 --- a/experiments/generic/node-io-stress/experiment/node-io-stress.go +++ b/experiments/generic/node-io-stress/experiment/node-io-stress.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/node-io-stress/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/node-io-stress/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-io-stress/types" @@ -19,7 +20,7 @@ import ( ) // NodeIOStress inject the node-io-stress chaos -func NodeIOStress(clients clients.ClientSets) { +func NodeIOStress(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -110,7 +111,7 @@ func NodeIOStress(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -126,7 +127,7 @@ func NodeIOStress(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareNodeIOStress(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareNodeIOStress(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("[Error]: node io stress failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -170,7 +171,7 @@ func NodeIOStress(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/node-memory-hog/experiment/node-memory-hog.go b/experiments/generic/node-memory-hog/experiment/node-memory-hog.go index 3c5dea5b8..cd040c5a0 100644 --- a/experiments/generic/node-memory-hog/experiment/node-memory-hog.go +++ b/experiments/generic/node-memory-hog/experiment/node-memory-hog.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/node-memory-hog/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/node-memory-hog/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-memory-hog/types" @@ -19,7 +20,7 @@ import ( ) // NodeMemoryHog inject the node-memory-hog chaos -func NodeMemoryHog(clients clients.ClientSets) { +func NodeMemoryHog(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -109,7 +110,7 @@ func NodeMemoryHog(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -125,7 +126,7 @@ func NodeMemoryHog(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareNodeMemoryHog(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareNodeMemoryHog(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("[Error]: node memory hog failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -169,7 +170,7 @@ func NodeMemoryHog(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/node-restart/experiment/node-restart.go b/experiments/generic/node-restart/experiment/node-restart.go index cf6084a07..788836f76 100644 --- a/experiments/generic/node-restart/experiment/node-restart.go +++ b/experiments/generic/node-restart/experiment/node-restart.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/node-restart/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/node-restart/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-restart/types" @@ -19,7 +20,7 @@ import ( ) // NodeRestart inject the node-restart chaos -func NodeRestart(clients clients.ClientSets) { +func NodeRestart(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -107,7 +108,7 @@ func NodeRestart(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -123,7 +124,7 @@ func NodeRestart(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareNodeRestart(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareNodeRestart(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("[Error]: Node restart failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -167,7 +168,7 @@ func NodeRestart(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/node-taint/experiment/node-taint.go b/experiments/generic/node-taint/experiment/node-taint.go index 834c36119..9468e1c9d 100644 --- a/experiments/generic/node-taint/experiment/node-taint.go +++ b/experiments/generic/node-taint/experiment/node-taint.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/node-taint/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/node-taint/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-taint/types" @@ -19,7 +20,7 @@ import ( ) // NodeTaint inject the node-taint chaos -func NodeTaint(clients clients.ClientSets) { +func NodeTaint(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -108,7 +109,7 @@ func NodeTaint(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -124,7 +125,7 @@ func NodeTaint(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareNodeTaint(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareNodeTaint(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -168,7 +169,7 @@ func NodeTaint(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "NUT: Ready, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-autoscaler/experiment/pod-autoscaler.go b/experiments/generic/pod-autoscaler/experiment/pod-autoscaler.go index 5930959db..b7b78b8c5 100644 --- a/experiments/generic/pod-autoscaler/experiment/pod-autoscaler.go +++ b/experiments/generic/pod-autoscaler/experiment/pod-autoscaler.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-autoscaler/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/pod-autoscaler/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-autoscaler/types" @@ -19,7 +20,7 @@ import ( ) // PodAutoscaler inject the pod-autoscaler chaos -func PodAutoscaler(clients clients.ClientSets) { +func PodAutoscaler(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -91,7 +92,7 @@ func PodAutoscaler(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -107,7 +108,7 @@ func PodAutoscaler(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PreparePodAutoscaler(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PreparePodAutoscaler(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -136,7 +137,7 @@ func PodAutoscaler(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-cpu-hog-exec/experiment/pod-cpu-hog-exec.go b/experiments/generic/pod-cpu-hog-exec/experiment/pod-cpu-hog-exec.go index 49b7c2b75..396d74c04 100644 --- a/experiments/generic/pod-cpu-hog-exec/experiment/pod-cpu-hog-exec.go +++ b/experiments/generic/pod-cpu-hog-exec/experiment/pod-cpu-hog-exec.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-cpu-hog-exec/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/pod-cpu-hog-exec/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-cpu-hog-exec/types" @@ -19,7 +20,7 @@ import ( ) // PodCPUHogExec inject the pod-cpu-hog-exec chaos -func PodCPUHogExec(clients clients.ClientSets) { +func PodCPUHogExec(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func PodCPUHogExec(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func PodCPUHogExec(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareCPUExecStress(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareCPUExecStress(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("[Error]: CPU hog failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func PodCPUHogExec(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-cpu-hog/experiment/pod-cpu-hog.go b/experiments/generic/pod-cpu-hog/experiment/pod-cpu-hog.go index ded331c6c..6ad9c212a 100644 --- a/experiments/generic/pod-cpu-hog/experiment/pod-cpu-hog.go +++ b/experiments/generic/pod-cpu-hog/experiment/pod-cpu-hog.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/stress-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/stress-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/stress-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodCPUHog inject the pod-cpu-hog chaos -func PodCPUHog(clients clients.ClientSets) { +func PodCPUHog(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func PodCPUHog(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func PodCPUHog(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareAndInjectStressChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareAndInjectStressChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("[Error]: CPU hog failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func PodCPUHog(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-delete/experiment/pod-delete.go b/experiments/generic/pod-delete/experiment/pod-delete.go index 7fcf048f9..0fb445f15 100644 --- a/experiments/generic/pod-delete/experiment/pod-delete.go +++ b/experiments/generic/pod-delete/experiment/pod-delete.go @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -19,7 +20,7 @@ import ( ) // PodDelete inject the pod-delete chaos -func PodDelete(clients clients.ClientSets) { +func PodDelete(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} eventsDetails := types.EventDetails{} @@ -95,7 +96,7 @@ func PodDelete(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg = common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -113,7 +114,7 @@ func PodDelete(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PreparePodDelete(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PreparePodDelete(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -141,7 +142,7 @@ func PodDelete(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg = common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-dns-error/experiment/pod-dns-error.go b/experiments/generic/pod-dns-error/experiment/pod-dns-error.go index 4442365c9..a7c739f65 100644 --- a/experiments/generic/pod-dns-error/experiment/pod-dns-error.go +++ b/experiments/generic/pod-dns-error/experiment/pod-dns-error.go @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -19,7 +20,7 @@ import ( ) // PodDNSError contains steps to inject chaos -func PodDNSError(clients clients.ClientSets) { +func PodDNSError(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -91,7 +92,7 @@ func PodDNSError(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -107,7 +108,7 @@ func PodDNSError(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareAndInjectChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareAndInjectChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -135,7 +136,7 @@ func PodDNSError(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-dns-spoof/experiment/pod-dns-spoof.go b/experiments/generic/pod-dns-spoof/experiment/pod-dns-spoof.go index 277680572..145376a64 100644 --- a/experiments/generic/pod-dns-spoof/experiment/pod-dns-spoof.go +++ b/experiments/generic/pod-dns-spoof/experiment/pod-dns-spoof.go @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -19,7 +20,7 @@ import ( ) // PodDNSSpoof contains steps to inject chaos -func PodDNSSpoof(clients clients.ClientSets) { +func PodDNSSpoof(ctx context.Context, clients clients.ClientSets) { var err error experimentsDetails := experimentTypes.ExperimentDetails{} @@ -92,7 +93,7 @@ func PodDNSSpoof(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) if err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") @@ -109,7 +110,7 @@ func PodDNSSpoof(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err = litmusLIB.PrepareAndInjectChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err = litmusLIB.PrepareAndInjectChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -137,7 +138,7 @@ func PodDNSSpoof(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-fio-stress/experiment/pod-fio-stress.go b/experiments/generic/pod-fio-stress/experiment/pod-fio-stress.go index 2f7348a66..e23a4df08 100644 --- a/experiments/generic/pod-fio-stress/experiment/pod-fio-stress.go +++ b/experiments/generic/pod-fio-stress/experiment/pod-fio-stress.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-fio-stress/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/pod-fio-stress/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-fio-stress/types" @@ -19,7 +20,7 @@ import ( ) // Experiment contains steps to inject chaos -func PodFioStress(clients clients.ClientSets) { +func PodFioStress(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -89,7 +90,7 @@ func PodFioStress(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -105,7 +106,7 @@ func PodFioStress(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) log.Errorf("Chaos injection failed, err: %v", err) return @@ -133,7 +134,7 @@ func PodFioStress(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-http-latency/experiment/pod-http-latency.go b/experiments/generic/pod-http-latency/experiment/pod-http-latency.go index 03bee5023..7f8a9f1cb 100644 --- a/experiments/generic/pod-http-latency/experiment/pod-http-latency.go +++ b/experiments/generic/pod-http-latency/experiment/pod-http-latency.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib/latency" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodHttpLatency inject the pod-http-latency chaos -func PodHttpLatency(clients clients.ClientSets) { +func PodHttpLatency(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func PodHttpLatency(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func PodHttpLatency(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PodHttpLatencyChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PodHttpLatencyChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func PodHttpLatency(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-http-modify-body/experiment/pod-http-modify-body.go b/experiments/generic/pod-http-modify-body/experiment/pod-http-modify-body.go index c68b40595..782d539f4 100644 --- a/experiments/generic/pod-http-modify-body/experiment/pod-http-modify-body.go +++ b/experiments/generic/pod-http-modify-body/experiment/pod-http-modify-body.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib/modify-body" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodHttpModifyBody contains steps to inject chaos -func PodHttpModifyBody(clients clients.ClientSets) { +func PodHttpModifyBody(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func PodHttpModifyBody(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func PodHttpModifyBody(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PodHttpModifyBodyChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PodHttpModifyBodyChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func PodHttpModifyBody(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-http-modify-header/experiment/pod-http-modify-header.go b/experiments/generic/pod-http-modify-header/experiment/pod-http-modify-header.go index cfb634457..f05053481 100644 --- a/experiments/generic/pod-http-modify-header/experiment/pod-http-modify-header.go +++ b/experiments/generic/pod-http-modify-header/experiment/pod-http-modify-header.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib/header" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodHttpModifyHeader inject the pod-http-modify-header chaos -func PodHttpModifyHeader(clients clients.ClientSets) { +func PodHttpModifyHeader(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func PodHttpModifyHeader(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func PodHttpModifyHeader(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PodHttpModifyHeaderChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PodHttpModifyHeaderChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func PodHttpModifyHeader(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-http-reset-peer/experiment/pod-http-reset-peer.go b/experiments/generic/pod-http-reset-peer/experiment/pod-http-reset-peer.go index 76188c3a1..d5df84fd4 100644 --- a/experiments/generic/pod-http-reset-peer/experiment/pod-http-reset-peer.go +++ b/experiments/generic/pod-http-reset-peer/experiment/pod-http-reset-peer.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib/reset" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodHttpResetPeer contains steps to inject chaos -func PodHttpResetPeer(clients clients.ClientSets) { +func PodHttpResetPeer(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func PodHttpResetPeer(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func PodHttpResetPeer(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PodHttpResetPeerChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PodHttpResetPeerChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func PodHttpResetPeer(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-http-status-code/experiment/pod-http-status-code.go b/experiments/generic/pod-http-status-code/experiment/pod-http-status-code.go index b37de87df..447b3ef13 100644 --- a/experiments/generic/pod-http-status-code/experiment/pod-http-status-code.go +++ b/experiments/generic/pod-http-status-code/experiment/pod-http-status-code.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/http-chaos/lib/statuscode" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/http-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodHttpStatusCode contains steps to inject chaos -func PodHttpStatusCode(clients clients.ClientSets) { +func PodHttpStatusCode(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -98,7 +99,7 @@ func PodHttpStatusCode(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -114,7 +115,7 @@ func PodHttpStatusCode(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PodHttpStatusCodeChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PodHttpStatusCodeChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -142,7 +143,7 @@ func PodHttpStatusCode(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-io-stress/experiment/pod-io-stress.go b/experiments/generic/pod-io-stress/experiment/pod-io-stress.go index eb6dcdb3f..95b964754 100644 --- a/experiments/generic/pod-io-stress/experiment/pod-io-stress.go +++ b/experiments/generic/pod-io-stress/experiment/pod-io-stress.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/stress-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/stress-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/stress-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodIOStress inject the pod-io-stress chaos -func PodIOStress(clients clients.ClientSets) { +func PodIOStress(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func PodIOStress(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func PodIOStress(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareAndInjectStressChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareAndInjectStressChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("[Error]: Pod IO Stress failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func PodIOStress(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-memory-hog-exec/experiment/pod-memory-hog-exec.go b/experiments/generic/pod-memory-hog-exec/experiment/pod-memory-hog-exec.go index f3a1d4a4f..7cad3f0e3 100644 --- a/experiments/generic/pod-memory-hog-exec/experiment/pod-memory-hog-exec.go +++ b/experiments/generic/pod-memory-hog-exec/experiment/pod-memory-hog-exec.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-memory-hog-exec/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/pod-memory-hog-exec/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-memory-hog-exec/types" @@ -19,7 +20,7 @@ import ( ) // PodMemoryHogExec inject the pod-memory-hog-exec chaos -func PodMemoryHogExec(clients clients.ClientSets) { +func PodMemoryHogExec(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func PodMemoryHogExec(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func PodMemoryHogExec(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareMemoryExecStress(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareMemoryExecStress(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("[Error]: pod memory hog failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func PodMemoryHogExec(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-memory-hog/experiment/pod-memory-hog.go b/experiments/generic/pod-memory-hog/experiment/pod-memory-hog.go index a4bf3cc57..128e177f4 100644 --- a/experiments/generic/pod-memory-hog/experiment/pod-memory-hog.go +++ b/experiments/generic/pod-memory-hog/experiment/pod-memory-hog.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/stress-chaos/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/stress-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/stress-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodMemoryHog inject the pod-memory-hog chaos -func PodMemoryHog(clients clients.ClientSets) { +func PodMemoryHog(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func PodMemoryHog(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func PodMemoryHog(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareAndInjectStressChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareAndInjectStressChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("[Error]: pod memory hog failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func PodMemoryHog(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-network-corruption/experiment/pod-network-corruption.go b/experiments/generic/pod-network-corruption/experiment/pod-network-corruption.go index d3276dbfd..183b2021b 100644 --- a/experiments/generic/pod-network-corruption/experiment/pod-network-corruption.go +++ b/experiments/generic/pod-network-corruption/experiment/pod-network-corruption.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib/corruption" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodNetworkCorruption inject the pod-network-corruption chaos -func PodNetworkCorruption(clients clients.ClientSets) { +func PodNetworkCorruption(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -91,7 +92,7 @@ func PodNetworkCorruption(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -107,7 +108,7 @@ func PodNetworkCorruption(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PodNetworkCorruptionChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PodNetworkCorruptionChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -135,7 +136,7 @@ func PodNetworkCorruption(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-network-duplication/experiment/pod-network-duplication.go b/experiments/generic/pod-network-duplication/experiment/pod-network-duplication.go index f37c46369..f1e42c839 100644 --- a/experiments/generic/pod-network-duplication/experiment/pod-network-duplication.go +++ b/experiments/generic/pod-network-duplication/experiment/pod-network-duplication.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib/duplication" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodNetworkDuplication inject the pod-network-duplication chaos -func PodNetworkDuplication(clients clients.ClientSets) { +func PodNetworkDuplication(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -91,7 +92,7 @@ func PodNetworkDuplication(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -107,7 +108,7 @@ func PodNetworkDuplication(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PodNetworkDuplicationChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PodNetworkDuplicationChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -135,7 +136,7 @@ func PodNetworkDuplication(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-network-latency/experiment/pod-network-latency.go b/experiments/generic/pod-network-latency/experiment/pod-network-latency.go index a4ca95682..efa7699a0 100644 --- a/experiments/generic/pod-network-latency/experiment/pod-network-latency.go +++ b/experiments/generic/pod-network-latency/experiment/pod-network-latency.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib/latency" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodNetworkLatency inject the pod-network-latency chaos -func PodNetworkLatency(clients clients.ClientSets) { +func PodNetworkLatency(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func PodNetworkLatency(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -107,7 +108,7 @@ func PodNetworkLatency(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PodNetworkLatencyChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PodNetworkLatencyChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -135,7 +136,7 @@ func PodNetworkLatency(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-network-loss/experiment/pod-network-loss.go b/experiments/generic/pod-network-loss/experiment/pod-network-loss.go index 926459318..cfb538156 100644 --- a/experiments/generic/pod-network-loss/experiment/pod-network-loss.go +++ b/experiments/generic/pod-network-loss/experiment/pod-network-loss.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/network-chaos/lib/loss" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" @@ -19,7 +20,7 @@ import ( ) // PodNetworkLoss inject the pod-network-loss chaos -func PodNetworkLoss(clients clients.ClientSets) { +func PodNetworkLoss(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} chaosDetails := types.ChaosDetails{} @@ -90,7 +91,7 @@ func PodNetworkLoss(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -106,7 +107,7 @@ func PodNetworkLoss(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PodNetworkLossChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PodNetworkLossChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -134,7 +135,7 @@ func PodNetworkLoss(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/generic/pod-network-partition/experiment/pod-network-partition.go b/experiments/generic/pod-network-partition/experiment/pod-network-partition.go index c0c300b86..44e73cd67 100644 --- a/experiments/generic/pod-network-partition/experiment/pod-network-partition.go +++ b/experiments/generic/pod-network-partition/experiment/pod-network-partition.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/pod-network-partition/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/pod-network-partition/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-network-partition/types" @@ -19,7 +20,7 @@ import ( ) // PodNetworkPartition inject the pod-network-partition chaos -func PodNetworkPartition(clients clients.ClientSets) { +func PodNetworkPartition(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -89,7 +90,7 @@ func PodNetworkPartition(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -105,7 +106,7 @@ func PodNetworkPartition(clients clients.ClientSets) { } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareAndInjectChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareAndInjectChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) log.Errorf("Chaos injection failed, err: %v", err) return @@ -133,7 +134,7 @@ func PodNetworkPartition(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/kafka/kafka-broker-pod-failure/experiment/kafka-broker-pod-failure.go b/experiments/kafka/kafka-broker-pod-failure/experiment/kafka-broker-pod-failure.go index 7bf9204c2..ef33545cf 100644 --- a/experiments/kafka/kafka-broker-pod-failure/experiment/kafka-broker-pod-failure.go +++ b/experiments/kafka/kafka-broker-pod-failure/experiment/kafka-broker-pod-failure.go @@ -1,12 +1,13 @@ package experiment import ( + "context" "os" "strings" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" kafkaPodDelete "github.com/litmuschaos/litmus-go/chaoslib/litmus/kafka-broker-pod-failure/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" "github.com/litmuschaos/litmus-go/pkg/kafka" experimentEnv "github.com/litmuschaos/litmus-go/pkg/kafka/environment" @@ -21,7 +22,7 @@ import ( ) // KafkaBrokerPodFailure derive and kill the kafka broker leader -func KafkaBrokerPodFailure(clients clients.ClientSets) { +func KafkaBrokerPodFailure(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -89,7 +90,7 @@ func KafkaBrokerPodFailure(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -125,7 +126,7 @@ func KafkaBrokerPodFailure(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err := kafkaPodDelete.PreparePodDelete(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := kafkaPodDelete.PreparePodDelete(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -154,7 +155,7 @@ func KafkaBrokerPodFailure(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := common.GetStatusMessage(chaosDetails.DefaultHealthCheck, "AUT: Running", "Unsuccessful") types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/kube-aws/ebs-loss-by-id/experiment/ebs-loss-by-id.go b/experiments/kube-aws/ebs-loss-by-id/experiment/ebs-loss-by-id.go index 5f64c7e4f..20d3cc248 100644 --- a/experiments/kube-aws/ebs-loss-by-id/experiment/ebs-loss-by-id.go +++ b/experiments/kube-aws/ebs-loss-by-id/experiment/ebs-loss-by-id.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" aws "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ebs" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/kube-aws/ebs-loss/environment" @@ -19,7 +20,7 @@ import ( ) // EBSLossByID inject the ebs volume loss chaos -func EBSLossByID(clients clients.ClientSets) { +func EBSLossByID(ctx context.Context, clients clients.ClientSets) { var err error experimentsDetails := experimentTypes.ExperimentDetails{} @@ -90,7 +91,7 @@ func EBSLossByID(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -111,7 +112,7 @@ func EBSLossByID(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err = litmusLIB.PrepareEBSLossByID(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err = litmusLIB.PrepareEBSLossByID(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -137,7 +138,7 @@ func EBSLossByID(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/kube-aws/ebs-loss-by-tag/experiment/ebs-loss-by-tag.go b/experiments/kube-aws/ebs-loss-by-tag/experiment/ebs-loss-by-tag.go index 96a7323e6..44f201efa 100644 --- a/experiments/kube-aws/ebs-loss-by-tag/experiment/ebs-loss-by-tag.go +++ b/experiments/kube-aws/ebs-loss-by-tag/experiment/ebs-loss-by-tag.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" aws "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ebs" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/kube-aws/ebs-loss/environment" @@ -19,7 +20,7 @@ import ( ) // EBSLossByTag inject the ebs volume loss chaos -func EBSLossByTag(clients clients.ClientSets) { +func EBSLossByTag(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -88,7 +89,7 @@ func EBSLossByTag(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -109,7 +110,7 @@ func EBSLossByTag(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareEBSLossByTag(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareEBSLossByTag(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -135,7 +136,7 @@ func EBSLossByTag(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/kube-aws/ec2-terminate-by-id/experiment/ec2-terminate-by-id.go b/experiments/kube-aws/ec2-terminate-by-id/experiment/ec2-terminate-by-id.go index 5db97c1e4..95010a803 100644 --- a/experiments/kube-aws/ec2-terminate-by-id/experiment/ec2-terminate-by-id.go +++ b/experiments/kube-aws/ec2-terminate-by-id/experiment/ec2-terminate-by-id.go @@ -1,12 +1,13 @@ package experiment import ( + "context" "os" "strings" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/ec2-terminate-by-id/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" aws "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ec2" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/kube-aws/ec2-terminate-by-id/environment" @@ -20,7 +21,7 @@ import ( ) // EC2TerminateByID inject the ebs volume loss chaos -func EC2TerminateByID(clients clients.ClientSets) { +func EC2TerminateByID(ctx context.Context, clients clients.ClientSets) { var ( err error @@ -86,7 +87,7 @@ func EC2TerminateByID(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -129,7 +130,7 @@ func EC2TerminateByID(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err = litmusLIB.PrepareEC2TerminateByID(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err = litmusLIB.PrepareEC2TerminateByID(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -167,7 +168,7 @@ func EC2TerminateByID(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/kube-aws/ec2-terminate-by-tag/experiment/ec2-terminate-tag.go b/experiments/kube-aws/ec2-terminate-by-tag/experiment/ec2-terminate-tag.go index 9fa3b9ff5..5d4a0ee8e 100644 --- a/experiments/kube-aws/ec2-terminate-by-tag/experiment/ec2-terminate-tag.go +++ b/experiments/kube-aws/ec2-terminate-by-tag/experiment/ec2-terminate-tag.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/ec2-terminate-by-tag/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" aws "github.com/litmuschaos/litmus-go/pkg/cloud/aws/ec2" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/kube-aws/ec2-terminate-by-tag/environment" @@ -19,7 +20,7 @@ import ( ) // EC2TerminateByTag inject the ebs volume loss chaos -func EC2TerminateByTag(clients clients.ClientSets) { +func EC2TerminateByTag(ctx context.Context, clients clients.ClientSets) { var ( err error @@ -86,7 +87,7 @@ func EC2TerminateByTag(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -125,7 +126,7 @@ func EC2TerminateByTag(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err = litmusLIB.PrepareEC2TerminateByTag(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err = litmusLIB.PrepareEC2TerminateByTag(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -162,7 +163,7 @@ func EC2TerminateByTag(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/load/k6-loadgen/experiment/k6-loadgen.go b/experiments/load/k6-loadgen/experiment/k6-loadgen.go index 5b8b10db7..0a62d3949 100644 --- a/experiments/load/k6-loadgen/experiment/k6-loadgen.go +++ b/experiments/load/k6-loadgen/experiment/k6-loadgen.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/k6-loadgen/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/events" experimentEnv "github.com/litmuschaos/litmus-go/pkg/load/k6-loadgen/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/load/k6-loadgen/types" @@ -19,7 +20,7 @@ import ( ) // Experiment contains steps to inject chaos -func Experiment(clients clients.ClientSets) { +func Experiment(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -89,7 +90,7 @@ func Experiment(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -104,7 +105,7 @@ func Experiment(clients clients.ClientSets) { events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -131,7 +132,7 @@ func Experiment(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/spring-boot/spring-boot-faults/experiment/spring-boot-faults.go b/experiments/spring-boot/spring-boot-faults/experiment/spring-boot-faults.go index 7e3dc57e2..45d27ef62 100644 --- a/experiments/spring-boot/spring-boot-faults/experiment/spring-boot-faults.go +++ b/experiments/spring-boot/spring-boot-faults/experiment/spring-boot-faults.go @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -19,7 +20,7 @@ import ( ) // Experiment contains steps to inject chaos -func Experiment(clients clients.ClientSets, expName string) { +func Experiment(ctx context.Context, clients clients.ClientSets, expName string) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -113,7 +114,7 @@ func Experiment(clients clients.ClientSets, expName string) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -130,7 +131,7 @@ func Experiment(clients clients.ClientSets, expName string) { chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -159,7 +160,7 @@ func Experiment(clients clients.ClientSets, expName string) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/experiments/vmware/vm-poweroff/experiment/vm-poweroff.go b/experiments/vmware/vm-poweroff/experiment/vm-poweroff.go index bee4d4193..551d717d0 100644 --- a/experiments/vmware/vm-poweroff/experiment/vm-poweroff.go +++ b/experiments/vmware/vm-poweroff/experiment/vm-poweroff.go @@ -1,11 +1,12 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/vm-poweroff/lib" - clients "github.com/litmuschaos/litmus-go/pkg/clients" + "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/cloud/vmware" "github.com/litmuschaos/litmus-go/pkg/events" "github.com/litmuschaos/litmus-go/pkg/log" @@ -22,7 +23,7 @@ import ( var err error // VMPoweroff contains steps to inject vm-power-off chaos -func VMPoweroff(clients clients.ClientSets) { +func VMPoweroff(ctx context.Context, clients clients.ClientSets) { experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -110,7 +111,7 @@ func VMPoweroff(clients clients.ClientSets) { // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil { log.Errorf("Probe Failed: %v", err) msg := "IUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -131,7 +132,7 @@ func VMPoweroff(clients clients.ClientSets) { chaosDetails.Phase = types.ChaosInjectPhase - if err = litmusLIB.InjectVMPowerOffChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails, cookie); err != nil { + if err = litmusLIB.InjectVMPowerOffChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails, cookie); err != nil { log.Errorf("Chaos injection failed: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -159,7 +160,7 @@ func VMPoweroff(clients clients.ClientSets) { // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { + if err = probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails); err != nil { log.Errorf("Probes Failed: %v", err) msg := "IUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/pkg/clients/clientset.go b/pkg/clients/clientset.go index 6d7cfee22..5cc252638 100644 --- a/pkg/clients/clientset.go +++ b/pkg/clients/clientset.go @@ -1,7 +1,6 @@ package clients import ( - "context" "flag" chaosClient "github.com/litmuschaos/chaos-operator/pkg/client/clientset/versioned/typed/litmuschaos/v1alpha1" @@ -21,7 +20,6 @@ type ClientSets struct { LitmusClient *chaosClient.LitmuschaosV1alpha1Client KubeConfig *rest.Config DynamicClient dynamic.Interface - Context context.Context } // GenerateClientSetFromKubeConfig will generation both ClientSets (k8s, and Litmus) as well as the KubeConfig diff --git a/pkg/probe/probe.go b/pkg/probe/probe.go index 4ca818b40..fe6e1a271 100644 --- a/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -17,6 +17,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/types" "github.com/palantir/stacktrace" "github.com/sirupsen/logrus" + "go.opentelemetry.io/otel" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -24,8 +25,8 @@ var err error // RunProbes contains the steps to trigger the probes // It contains steps to trigger all three probes: k8sprobe, httpprobe, cmdprobe -func RunProbes(chaosDetails *types.ChaosDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, phase string, eventsDetails *types.EventDetails) error { - span := telemetry.StartTracing(clients, "RunProbes") +func RunProbes(ctx context.Context, chaosDetails *types.ChaosDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, phase string, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "RunProbes") defer span.End() // get the probes details from the chaosengine diff --git a/pkg/telemetry/tracing.go b/pkg/telemetry/tracing.go index 3787178fc..83c24e852 100644 --- a/pkg/telemetry/tracing.go +++ b/pkg/telemetry/tracing.go @@ -5,11 +5,9 @@ import ( "encoding/json" "os" - "github.com/litmuschaos/litmus-go/pkg/clients" "github.com/litmuschaos/litmus-go/pkg/log" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" - "go.opentelemetry.io/otel/trace" ) const ( @@ -17,12 +15,6 @@ const ( TraceParent = "TRACE_PARENT" ) -func StartTracing(clients clients.ClientSets, spanName string) trace.Span { - ctx, span := otel.Tracer(TracerName).Start(clients.Context, spanName) - clients.Context = ctx - return span -} - func GetTraceParentContext() context.Context { traceParent := os.Getenv(TraceParent) From 86c0bab4c3fa7ad43061a0d1be492cb463be3a21 Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Mon, 16 Sep 2024 19:11:10 +0900 Subject: [PATCH 07/12] update templates Signed-off-by: namkyu1999 --- .../templates/chaoslib_exec.tmpl | 16 +++++++++----- .../templates/chaoslib_helper.tmpl | 22 ++++++++++++------- .../templates/chaoslib_non-k8s.tmpl | 18 +++++++++------ .../templates/experiment_aws.tmpl | 9 ++++---- .../templates/experiment_azure.tmpl | 9 ++++---- .../templates/experiment_gcp.tmpl | 7 +++--- .../templates/experiment_k8s.tmpl | 9 ++++---- .../templates/experiment_vmware.tmpl | 10 +++++---- 8 files changed, 60 insertions(+), 40 deletions(-) diff --git a/contribute/developer-guide/templates/chaoslib_exec.tmpl b/contribute/developer-guide/templates/chaoslib_exec.tmpl index e4e3afcb2..a5a6d5704 100644 --- a/contribute/developer-guide/templates/chaoslib_exec.tmpl +++ b/contribute/developer-guide/templates/chaoslib_exec.tmpl @@ -1,6 +1,7 @@ package lib import ( + "context" "fmt" "os" "github.com/litmuschaos/litmus-go/pkg/cerrors" @@ -32,7 +33,7 @@ func injectChaos(experimentsDetails *experimentTypes.ExperimentDetails, podName return nil } -func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func experimentExecution(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage @@ -53,13 +54,13 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, } log.Infof("Target pods list for chaos, %v", podNames) - return runChaos(experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails) + return runChaos(ctx, experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails) } -func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func runChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -120,7 +121,10 @@ func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodLi } //PrepareChaos contains the preparation steps before chaos injection -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + // @TODO: setup tracing + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectChaos") + // defer span.End() //Waiting for the ramp time before chaos injection if experimentsDetails.RampTime != 0 { @@ -128,7 +132,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients common.WaitForDuration(experimentsDetails.RampTime) } //Starting the CPU stress experiment - if err := experimentExecution(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails);err != nil { + if err := experimentExecution(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails);err != nil { return stacktrace.Propagate(err, "could not execute experiment") } //Waiting for the ramp time after chaos injection diff --git a/contribute/developer-guide/templates/chaoslib_helper.tmpl b/contribute/developer-guide/templates/chaoslib_helper.tmpl index 290e2b557..6e88616b0 100644 --- a/contribute/developer-guide/templates/chaoslib_helper.tmpl +++ b/contribute/developer-guide/templates/chaoslib_helper.tmpl @@ -19,7 +19,7 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func experimentExecution(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage @@ -54,10 +54,10 @@ func experimentExecution(experimentsDetails *experimentTypes.ExperimentDetails, } } - return runChaos(experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails) + return runChaos(ctx, experimentsDetails, targetPodList, clients, resultDetails, eventsDetails, chaosDetails) } -func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func runChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { if experimentsDetails.EngineName != "" { msg := "Injecting " + experimentsDetails.ExperimentName + " chaos on target pod" types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails) @@ -66,7 +66,7 @@ func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodLi // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -89,7 +89,7 @@ func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodLi "Target Container": experimentsDetails.TargetContainer, }) - if err := createHelperPod(experimentsDetails, clients, chaosDetails, pod.Name, pod.Spec.NodeName, runID); err != nil { + if err := createHelperPod(ctx, experimentsDetails, clients, chaosDetails, pod.Name, pod.Spec.NodeName, runID); err != nil { return stacktrace.Propagate(err, "could not create helper pod") } @@ -124,7 +124,10 @@ func runChaos(experimentsDetails *experimentTypes.ExperimentDetails, targetPodLi } //PrepareChaos contains the preparation steps before chaos injection -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + // @TODO: setup tracing + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "name-your-chaos-fault") + // defer span.End() //Waiting for the ramp time before chaos injection if experimentsDetails.RampTime != 0 { @@ -132,7 +135,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients common.WaitForDuration(experimentsDetails.RampTime) } //Starting the CPU stress experiment - if err := experimentExecution(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails);err != nil { + if err := experimentExecution(ctx, experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails);err != nil { return stacktrace.Propagate(err, "could not execute chaos") } //Waiting for the ramp time after chaos injection @@ -144,7 +147,10 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients } // createHelperPod derive the attributes for helper pod and create the helper pod -func createHelperPod(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { +func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { + // @TODO: setup tracing + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateHelperPod") + // defer span.End() helperPod := &corev1.Pod{ ObjectMeta: v1.ObjectMeta{ diff --git a/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl b/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl index 3b2954aaa..7f11d65d5 100644 --- a/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl +++ b/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl @@ -1,6 +1,7 @@ package lib import ( + "context" "os" "os/signal" "strings" @@ -22,7 +23,10 @@ var ( ) //PrepareChaos contains the preparation and injection steps for the experiment -func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + // @TODO: setup tracing + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectChaos") + // defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) @@ -53,11 +57,11 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients switch strings.ToLower(experimentsDetails.Sequence) { case "serial": - if err = injectChaosInSerialMode(experimentsDetails, targetIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInSerialMode(ctx, experimentsDetails, targetIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in serial mode") } case "parallel": - if err = injectChaosInParallelMode(experimentsDetails, targetIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { + if err = injectChaosInParallelMode(ctx, experimentsDetails, targetIDList, clients, resultDetails, eventsDetails, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not run chaos in parallel mode") } default: @@ -73,7 +77,7 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients } //injectChaosInSerialMode will inject the chaos on the target one after other -func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetails, targetIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInSerialMode(ctx context.Contxt, experimentsDetails *experimentTypes.ExperimentDetails, targetIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -111,7 +115,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai // The OnChaos probes execution will start in the first iteration and keep running for the entire chaos duration if len(resultDetails.ProbeDetails) != 0 && i == 0 { - if err = probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err = probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } @@ -136,7 +140,7 @@ func injectChaosInSerialMode(experimentsDetails *experimentTypes.ExperimentDetai } // injectChaosInParallelMode will inject the chaos on the target all at once -func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDetails, targetIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { +func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { select { case <-inject: @@ -177,7 +181,7 @@ func injectChaosInParallelMode(experimentsDetails *experimentTypes.ExperimentDet // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { + if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { return err } } diff --git a/contribute/developer-guide/templates/experiment_aws.tmpl b/contribute/developer-guide/templates/experiment_aws.tmpl index b1920a590..7104ac807 100644 --- a/contribute/developer-guide/templates/experiment_aws.tmpl +++ b/contribute/developer-guide/templates/experiment_aws.tmpl @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/{{ .Name }}/lib" @@ -19,7 +20,7 @@ import ( ) // Experiment contains steps to inject chaos -func Experiment(clients clients.ClientSets){ +func Experiment(ctx context.Context, clients clients.ClientSets){ experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -90,7 +91,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -111,7 +112,7 @@ func Experiment(clients clients.ClientSets){ // @TODO: user INVOKE-CHAOSLIB chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -142,7 +143,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/contribute/developer-guide/templates/experiment_azure.tmpl b/contribute/developer-guide/templates/experiment_azure.tmpl index 7d8a76a18..9cf17e378 100644 --- a/contribute/developer-guide/templates/experiment_azure.tmpl +++ b/contribute/developer-guide/templates/experiment_azure.tmpl @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -20,7 +21,7 @@ import ( ) // Experiment contains steps to inject chaos -func Experiment(clients clients.ClientSets){ +func Experiment(ctx context.Context, clients clients.ClientSets){ experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -99,7 +100,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -120,7 +121,7 @@ func Experiment(clients clients.ClientSets){ // @TODO: user INVOKE-CHAOSLIB chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -148,7 +149,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/contribute/developer-guide/templates/experiment_gcp.tmpl b/contribute/developer-guide/templates/experiment_gcp.tmpl index c22151420..20bbe81b4 100644 --- a/contribute/developer-guide/templates/experiment_gcp.tmpl +++ b/contribute/developer-guide/templates/experiment_gcp.tmpl @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -98,7 +99,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -119,7 +120,7 @@ func Experiment(clients clients.ClientSets){ // @TODO: user INVOKE-CHAOSLIB chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) failStep := "[chaos]: Failed inside the chaoslib, err: " + err.Error() result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) @@ -149,7 +150,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/contribute/developer-guide/templates/experiment_k8s.tmpl b/contribute/developer-guide/templates/experiment_k8s.tmpl index bd33e4a78..85f29a6ef 100644 --- a/contribute/developer-guide/templates/experiment_k8s.tmpl +++ b/contribute/developer-guide/templates/experiment_k8s.tmpl @@ -1,6 +1,7 @@ package experiment import ( + "context" "os" "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" @@ -19,7 +20,7 @@ import ( ) // Experiment contains steps to inject chaos -func Experiment(clients clients.ClientSets){ +func Experiment(ctx context.Context, clients clients.ClientSets){ experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -104,7 +105,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -125,7 +126,7 @@ func Experiment(clients clients.ClientSets){ // @TODO: user INVOKE-CHAOSLIB chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) result.RecordAfterFailure(&chaosDetails, &resultDetails, err, clients, &eventsDetails) return @@ -168,7 +169,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) diff --git a/contribute/developer-guide/templates/experiment_vmware.tmpl b/contribute/developer-guide/templates/experiment_vmware.tmpl index 38f64a162..aad8e769a 100644 --- a/contribute/developer-guide/templates/experiment_vmware.tmpl +++ b/contribute/developer-guide/templates/experiment_vmware.tmpl @@ -1,8 +1,10 @@ package experiment import ( + "context" "os" + "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" litmusLIB "github.com/litmuschaos/litmus-go/chaoslib/litmus/{{ .Name }}/lib" clients "github.com/litmuschaos/litmus-go/pkg/clients" @@ -19,7 +21,7 @@ import ( ) // Experiment contains steps to inject chaos -func Experiment(clients clients.ClientSets){ +func Experiment(ctx context.Context, clients clients.ClientSets){ experimentsDetails := experimentTypes.ExperimentDetails{} resultDetails := types.ResultDetails{} @@ -97,7 +99,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the pre-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil { log.Errorf("Probe Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) @@ -118,7 +120,7 @@ func Experiment(clients clients.ClientSets){ // @TODO: user INVOKE-CHAOSLIB chaosDetails.Phase = types.ChaosInjectPhase - if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { + if err := litmusLIB.PrepareChaos(ctx, &experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil { log.Errorf("Chaos injection failed, err: %v", err) failStep := "[chaos]: Failed inside the chaoslib, err: " + err.Error() result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) @@ -148,7 +150,7 @@ func Experiment(clients clients.ClientSets){ // run the probes in the post-chaos check if len(resultDetails.ProbeDetails) != 0 { - if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { + if err := probe.RunProbes(ctx, &chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil { log.Errorf("Probes Failed, err: %v", err) msg := "AUT: Running, Probes: Unsuccessful" types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) From 7241a9c455b861fc9a456ce930b5cdbf2ce91a8c Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Wed, 9 Oct 2024 20:40:58 +0900 Subject: [PATCH 08/12] feat: rename spans and enhance coverage Signed-off-by: namkyu1999 --- chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go | 6 ++++++ .../aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go | 2 +- .../aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go | 2 +- chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go | 6 +++++- .../azure-instance-stop/lib/azure-instance-stop.go | 8 +++++++- chaoslib/litmus/container-kill/lib/container-kill.go | 8 ++++++-- chaoslib/litmus/disk-fill/lib/disk-fill.go | 10 ++++++---- .../docker-service-kill/lib/docker-service-kill.go | 4 ++-- .../ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go | 2 +- .../lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go | 2 +- chaoslib/litmus/ebs-loss/lib/ebs-loss.go | 6 ++++++ .../ec2-terminate-by-id/lib/ec2-terminate-by-id.go | 6 +++++- .../ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go | 6 +++++- .../lib/gcp-vm-disk-loss-by-label.go | 6 +++++- .../litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go | 7 +++++-- .../lib/gcp-vm-instance-stop-by-label.go | 7 +++++-- .../gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go | 6 +++++- chaoslib/litmus/http-chaos/lib/header/header.go | 2 +- chaoslib/litmus/http-chaos/lib/http-chaos.go | 4 ++++ chaoslib/litmus/http-chaos/lib/latency/latency.go | 2 +- .../litmus/http-chaos/lib/modify-body/modify-body.go | 2 +- chaoslib/litmus/http-chaos/lib/reset/reset.go | 2 +- .../litmus/http-chaos/lib/statuscode/status-code.go | 2 +- chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go | 7 +++++-- .../litmus/kafka-broker-pod-failure/lib/pod-delete.go | 8 +++++--- .../kubelet-service-kill/lib/kubelet-service-kill.go | 4 ++-- .../litmus/network-chaos/lib/corruption/corruption.go | 2 +- .../network-chaos/lib/duplication/duplication.go | 2 +- chaoslib/litmus/network-chaos/lib/latency/latency.go | 2 +- chaoslib/litmus/network-chaos/lib/loss/loss.go | 2 +- chaoslib/litmus/network-chaos/lib/network-chaos.go | 7 ++++++- chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go | 9 +++++++-- chaoslib/litmus/node-drain/lib/node-drain.go | 8 +++++--- chaoslib/litmus/node-io-stress/lib/node-io-stress.go | 8 ++++++-- chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go | 8 ++++++-- chaoslib/litmus/node-restart/lib/node-restart.go | 4 ++-- chaoslib/litmus/node-taint/lib/node-taint.go | 8 +++++--- chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go | 2 +- .../litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go | 10 +++++++--- chaoslib/litmus/pod-delete/lib/pod-delete.go | 6 +++++- chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go | 8 ++++++-- chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go | 8 +++++++- .../pod-memory-hog-exec/lib/pod-memory-hog-exec.go | 7 ++++++- .../pod-network-partition/lib/pod-network-partition.go | 8 +++++--- .../redfish-node-restart/lib/redfish-node-restart.go | 9 ++++++--- .../litmus/spring-boot-chaos/lib/spring-boot-chaos.go | 6 +++++- chaoslib/litmus/stress-chaos/lib/stress-chaos.go | 8 ++++++-- chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go | 7 ++++++- 48 files changed, 194 insertions(+), 72 deletions(-) diff --git a/chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go b/chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go index 6c90e0ae0..0a54489fd 100644 --- a/chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go +++ b/chaoslib/litmus/aws-ssm-chaos/lib/ssm-chaos.go @@ -12,13 +12,17 @@ import ( "github.com/litmuschaos/litmus-go/pkg/events" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) // InjectChaosInSerialMode will inject the aws ssm chaos in serial mode that is one after other func InjectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, inject chan os.Signal) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSSSMFaultInSerialMode") + defer span.End() select { case <-inject: @@ -87,6 +91,8 @@ func InjectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // InjectChaosInParallelMode will inject the aws ssm chaos in parallel mode that is all at once func InjectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, inject chan os.Signal) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSSSMFaultInParallelMode") + defer span.End() select { case <-inject: diff --git a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go index a0b708208..e4bb5a50b 100644 --- a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go +++ b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go @@ -28,7 +28,7 @@ var ( // PrepareAWSSSMChaosByID contains the prepration and injection steps for the experiment func PrepareAWSSSMChaosByID(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSChaosByIDChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareAWSSSMFaultByID") defer span.End() // inject channel is used to transmit signal notifications. diff --git a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go index 7fdade038..c7e872c7b 100644 --- a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go +++ b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-tag.go @@ -23,7 +23,7 @@ import ( // PrepareAWSSSMChaosByTag contains the prepration and injection steps for the experiment func PrepareAWSSSMChaosByTag(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSSSMChaosByTagChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSSSMFaultByTag") defer span.End() // inject channel is used to transmit signal notifications. diff --git a/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go b/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go index 342149990..210377809 100644 --- a/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go +++ b/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go @@ -33,7 +33,7 @@ var ( // PrepareChaos contains the prepration and injection steps for the experiment func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAzureDiskLossChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareAzureDiskLossFault") defer span.End() // inject channel is used to transmit signal notifications. @@ -106,6 +106,8 @@ func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.Exper // injectChaosInParallelMode will inject the Azure disk loss chaos in parallel mode that is all at once func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesWithDiskNames map[string][]string, attachedDisksWithInstance map[string]*[]compute.DataDisk, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAzureDiskLossFaultInParallelMode") + defer span.End() //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -184,6 +186,8 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime // injectChaosInSerialMode will inject the Azure disk loss chaos in serial mode that is one after other func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesWithDiskNames map[string][]string, attachedDisksWithInstance map[string]*[]compute.DataDisk, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAzureDiskLossFaultInSerialMode") + defer span.End() //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() diff --git a/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go b/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go index b9c70bc23..eefd1c54a 100644 --- a/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go +++ b/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go @@ -31,7 +31,7 @@ var ( // PrepareAzureStop will initialize instanceNameList and start chaos injection based on sequence method selected func PrepareAzureStop(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAzureInstanceStopChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareAzureInstanceStopFault") defer span.End() // inject channel is used to transmit signal notifications @@ -81,6 +81,9 @@ func PrepareAzureStop(ctx context.Context, experimentsDetails *experimentTypes.E // injectChaosInSerialMode will inject the Azure instance termination in serial mode that is one after the other func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceNameList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAzureInstanceStopFaultInSerialMode") + defer span.End() + select { case <-inject: // stopping the chaos execution, if abort signal received @@ -159,6 +162,9 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode will inject the Azure instance termination in parallel mode that is all at once func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceNameList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAzureInstanceStopFaultInParallelMode") + defer span.End() + select { case <-inject: // Stopping the chaos execution, if abort signal received diff --git a/chaoslib/litmus/container-kill/lib/container-kill.go b/chaoslib/litmus/container-kill/lib/container-kill.go index 52c3151a6..95d81bf96 100644 --- a/chaoslib/litmus/container-kill/lib/container-kill.go +++ b/chaoslib/litmus/container-kill/lib/container-kill.go @@ -27,7 +27,7 @@ import ( // PrepareContainerKill contains the preparation steps before chaos injection func PrepareContainerKill(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectContainerKillChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareContainerKillFault") defer span.End() var err error @@ -93,6 +93,8 @@ func PrepareContainerKill(ctx context.Context, experimentsDetails *experimentTyp // injectChaosInSerialMode kill the container of all target application serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectContainerKillFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { @@ -143,6 +145,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode kill the container of all target application in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectContainerKillFaultInParallelMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { @@ -193,7 +197,7 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateContainerKillHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateContainerKillFaultHelperPod") defer span.End() privilegedEnable := false diff --git a/chaoslib/litmus/disk-fill/lib/disk-fill.go b/chaoslib/litmus/disk-fill/lib/disk-fill.go index 11c9aff30..0c63f84b2 100644 --- a/chaoslib/litmus/disk-fill/lib/disk-fill.go +++ b/chaoslib/litmus/disk-fill/lib/disk-fill.go @@ -28,7 +28,7 @@ import ( // PrepareDiskFill contains the preparation steps before chaos injection func PrepareDiskFill(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectDiskFillChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareDiskFillFault") defer span.End() var err error @@ -98,7 +98,8 @@ func PrepareDiskFill(ctx context.Context, experimentsDetails *experimentTypes.Ex // injectChaosInSerialMode fill the ephemeral storage of all target application serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, execCommandDetails exec.PodDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { - + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectDiskFillFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { @@ -150,7 +151,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode fill the ephemeral storage of of all target application in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, execCommandDetails exec.PodDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { - + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectDiskFillFaultInParallelMode") + defer span.End() var err error // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -202,7 +204,7 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, appNodeName, runID string) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateDiskFillHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateDiskFillFaultHelperPod") defer span.End() privilegedEnable := true diff --git a/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go b/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go index 74b04c512..f1fef9c9e 100644 --- a/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go +++ b/chaoslib/litmus/docker-service-kill/lib/docker-service-kill.go @@ -26,7 +26,7 @@ import ( // PrepareDockerServiceKill contains prepration steps before chaos injection func PrepareDockerServiceKill(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectDockerServiceKillChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareDockerServiceKillFault") defer span.End() var err error @@ -115,7 +115,7 @@ func PrepareDockerServiceKill(ctx context.Context, experimentsDetails *experimen // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, appNodeName string) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateDockerServiceKillHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateDockerServiceKillFaultHelperPod") defer span.End() privileged := true diff --git a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go index a3b48ca1e..dbc504628 100644 --- a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go +++ b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go @@ -27,7 +27,7 @@ var ( // PrepareEBSLossByID contains the prepration and injection steps for the experiment func PrepareEBSLossByID(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectEBSLossByIDChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareAWSEBSLossFaultByID") defer span.End() // inject channel is used to transmit signal notifications. diff --git a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go index ea8342909..6e8589129 100644 --- a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go +++ b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-tag/lib/ebs-loss-by-tag.go @@ -27,7 +27,7 @@ var ( // PrepareEBSLossByTag contains the prepration and injection steps for the experiment func PrepareEBSLossByTag(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectEBSLossByTagChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareAWSEBSLossFaultByTag") defer span.End() // inject channel is used to transmit signal notifications. diff --git a/chaoslib/litmus/ebs-loss/lib/ebs-loss.go b/chaoslib/litmus/ebs-loss/lib/ebs-loss.go index 3d21a6b72..8fa9bb0e4 100644 --- a/chaoslib/litmus/ebs-loss/lib/ebs-loss.go +++ b/chaoslib/litmus/ebs-loss/lib/ebs-loss.go @@ -13,13 +13,17 @@ import ( experimentTypes "github.com/litmuschaos/litmus-go/pkg/kube-aws/ebs-loss/types" "github.com/litmuschaos/litmus-go/pkg/log" "github.com/litmuschaos/litmus-go/pkg/probe" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/litmuschaos/litmus-go/pkg/types" "github.com/litmuschaos/litmus-go/pkg/utils/common" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" ) // InjectChaosInSerialMode will inject the ebs loss chaos in serial mode which means one after other func InjectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetEBSVolumeIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSEBSLossFaultInSerialMode") + defer span.End() //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -97,6 +101,8 @@ func InjectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // InjectChaosInParallelMode will inject the chaos in parallel mode that means all at once func InjectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetEBSVolumeIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSEBSLossFaultInParallelMode") + defer span.End() var ec2InstanceIDList, deviceList []string diff --git a/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go b/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go index 8f30a7c24..5a844099a 100644 --- a/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go +++ b/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go @@ -30,7 +30,7 @@ var ( // PrepareEC2TerminateByID contains the prepration and injection steps for the experiment func PrepareEC2TerminateByID(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectEC2TerminateByIDChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareAWSEC2TerminateFaultByID") defer span.End() // inject channel is used to transmit signal notifications. @@ -81,6 +81,8 @@ func PrepareEC2TerminateByID(ctx context.Context, experimentsDetails *experiment // injectChaosInSerialMode will inject the ec2 instance termination in serial mode that is one after other func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSEC2TerminateFaultByIDInSerialMode") + defer span.End() select { case <-inject: @@ -153,6 +155,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode will inject the ec2 instance termination in parallel mode that is all at once func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSEC2TerminateFaultByIDInParallelMode") + defer span.End() select { case <-inject: diff --git a/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go b/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go index 06efa86c1..2c34b83b4 100644 --- a/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go +++ b/chaoslib/litmus/ec2-terminate-by-tag/lib/ec2-terminate-by-tag.go @@ -28,7 +28,7 @@ var inject, abort chan os.Signal // PrepareEC2TerminateByTag contains the prepration and injection steps for the experiment func PrepareEC2TerminateByTag(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectEC2TerminateByTagChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareAWSEC2TerminateFaultByTag") defer span.End() // inject channel is used to transmit signal notifications. @@ -76,6 +76,8 @@ func PrepareEC2TerminateByTag(ctx context.Context, experimentsDetails *experimen // injectChaosInSerialMode will inject the ce2 instance termination in serial mode that is one after other func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSEC2TerminateFaultByTagInSerialMode") + defer span.End() select { case <-inject: @@ -148,6 +150,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode will inject the ce2 instance termination in parallel mode that is all at once func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAWSEC2TerminateFaultByTagInParallelMode") + defer span.End() select { case <-inject: diff --git a/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go b/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go index 7b5ec29be..42efdf8bd 100644 --- a/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go +++ b/chaoslib/litmus/gcp-vm-disk-loss-by-label/lib/gcp-vm-disk-loss-by-label.go @@ -31,7 +31,7 @@ var ( // PrepareDiskVolumeLossByLabel contains the prepration and injection steps for the experiment func PrepareDiskVolumeLossByLabel(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectDiskVolumeLossByLabelChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareGCPDiskVolumeLossFaultByLabel") defer span.End() // inject channel is used to transmit signal notifications. @@ -91,6 +91,8 @@ func PrepareDiskVolumeLossByLabel(ctx context.Context, computeService *compute.S // injectChaosInSerialMode will inject the disk loss chaos in serial mode which means one after the other func injectChaosInSerialMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, instanceNamesList []string, zone string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectGCPDiskVolumeLossFaultByLabelInSerialMode") + defer span.End() //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() @@ -166,6 +168,8 @@ func injectChaosInSerialMode(ctx context.Context, computeService *compute.Servic // injectChaosInParallelMode will inject the disk loss chaos in parallel mode that means all at once func injectChaosInParallelMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, instanceNamesList []string, zone string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectGCPDiskVolumeLossFaultByLabelInParallelMode") + defer span.End() //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() diff --git a/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go b/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go index e3bd1f817..6a99010d9 100644 --- a/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go +++ b/chaoslib/litmus/gcp-vm-disk-loss/lib/gcp-vm-disk-loss.go @@ -32,7 +32,7 @@ var ( // PrepareDiskVolumeLoss contains the prepration and injection steps for the experiment func PrepareDiskVolumeLoss(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMDiskLossChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareVMDiskLossFault") defer span.End() // inject channel is used to transmit signal notifications. @@ -96,7 +96,8 @@ func PrepareDiskVolumeLoss(ctx context.Context, computeService *compute.Service, // injectChaosInSerialMode will inject the disk loss chaos in serial mode which means one after the other func injectChaosInSerialMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, diskZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMDiskLossFaultInSerialMode") + defer span.End() //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() duration := int(time.Since(ChaosStartTimeStamp).Seconds()) @@ -167,6 +168,8 @@ func injectChaosInSerialMode(ctx context.Context, computeService *compute.Servic // injectChaosInParallelMode will inject the disk loss chaos in parallel mode that means all at once func injectChaosInParallelMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, targetDiskVolumeNamesList, diskZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMDiskLossFaultInParallelMode") + defer span.End() //ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin ChaosStartTimeStamp := time.Now() diff --git a/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go b/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go index 86d194e74..644a02137 100644 --- a/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go +++ b/chaoslib/litmus/gcp-vm-instance-stop-by-label/lib/gcp-vm-instance-stop-by-label.go @@ -28,7 +28,7 @@ var inject, abort chan os.Signal // PrepareVMStopByLabel executes the experiment steps by injecting chaos into target VM instances func PrepareVMStopByLabel(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMInstanceStopByLabelChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareGCPVMInstanceStopFaultByLabel") defer span.End() // inject channel is used to transmit signal notifications. @@ -77,6 +77,8 @@ func PrepareVMStopByLabel(ctx context.Context, computeService *compute.Service, // injectChaosInSerialMode stops VM instances in serial mode i.e. one after the other func injectChaosInSerialMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectGCPVMInstanceStopFaultByLabelInSerialMode") + defer span.End() select { case <-inject: @@ -162,7 +164,8 @@ func injectChaosInSerialMode(ctx context.Context, computeService *compute.Servic // injectChaosInParallelMode will inject the VM instance termination in serial mode that is one after other func injectChaosInParallelMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectGCPVMInstanceStopFaultByLabelInParallelMode") + defer span.End() select { case <-inject: // stopping the chaos execution, if abort signal received diff --git a/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go b/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go index 35eeac647..281e1c211 100644 --- a/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go +++ b/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go @@ -31,7 +31,7 @@ var ( // PrepareVMStop contains the prepration and injection steps for the experiment func PrepareVMStop(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMInstanceStopChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareVMInstanceStopFault") defer span.End() // inject channel is used to transmit signal notifications. @@ -82,6 +82,8 @@ func PrepareVMStop(ctx context.Context, computeService *compute.Service, experim // injectChaosInSerialMode stops VM instances in serial mode i.e. one after the other func injectChaosInSerialMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, instanceZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMInstanceStopFaultInSerialMode") + defer span.End() select { case <-inject: @@ -167,6 +169,8 @@ func injectChaosInSerialMode(ctx context.Context, computeService *compute.Servic // injectChaosInParallelMode stops VM instances in parallel mode i.e. all at once func injectChaosInParallelMode(ctx context.Context, computeService *compute.Service, experimentsDetails *experimentTypes.ExperimentDetails, instanceNamesList []string, instanceZonesList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMInstanceStopFaultInParallelMode") + defer span.End() select { case <-inject: diff --git a/chaoslib/litmus/http-chaos/lib/header/header.go b/chaoslib/litmus/http-chaos/lib/header/header.go index ec38f6c08..1c822d505 100644 --- a/chaoslib/litmus/http-chaos/lib/header/header.go +++ b/chaoslib/litmus/http-chaos/lib/header/header.go @@ -15,7 +15,7 @@ import ( // PodHttpModifyHeaderChaos contains the steps to prepare and inject http modify header chaos func PodHttpModifyHeaderChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPModifyHeaderChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodHTTPModifyHeaderFault") defer span.End() log.InfoWithValues("[Info]: The chaos tunables are:", logrus.Fields{ diff --git a/chaoslib/litmus/http-chaos/lib/http-chaos.go b/chaoslib/litmus/http-chaos/lib/http-chaos.go index 185033459..59323f0b8 100644 --- a/chaoslib/litmus/http-chaos/lib/http-chaos.go +++ b/chaoslib/litmus/http-chaos/lib/http-chaos.go @@ -82,6 +82,8 @@ func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTy // injectChaosInSerialMode inject the http chaos in all target application serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, args string, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -139,6 +141,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode inject the http chaos in all target application in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, args string, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPFaultInParallelMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { diff --git a/chaoslib/litmus/http-chaos/lib/latency/latency.go b/chaoslib/litmus/http-chaos/lib/latency/latency.go index a45432e0a..7cd7f4816 100644 --- a/chaoslib/litmus/http-chaos/lib/latency/latency.go +++ b/chaoslib/litmus/http-chaos/lib/latency/latency.go @@ -16,7 +16,7 @@ import ( // PodHttpLatencyChaos contains the steps to prepare and inject http latency chaos func PodHttpLatencyChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPLatencyChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodHttpLatencyFault") defer span.End() log.InfoWithValues("[Info]: The chaos tunables are:", logrus.Fields{ diff --git a/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go b/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go index 6093036e6..86c136def 100644 --- a/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go +++ b/chaoslib/litmus/http-chaos/lib/modify-body/modify-body.go @@ -18,7 +18,7 @@ import ( // PodHttpModifyBodyChaos contains the steps to prepare and inject http modify body chaos func PodHttpModifyBodyChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPModifyBodyChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodHTTPModifyBodyFault") defer span.End() // responseBodyMaxLength defines the max length of response body string to be printed. It is taken as diff --git a/chaoslib/litmus/http-chaos/lib/reset/reset.go b/chaoslib/litmus/http-chaos/lib/reset/reset.go index d8df3eb6c..9bff4e09d 100644 --- a/chaoslib/litmus/http-chaos/lib/reset/reset.go +++ b/chaoslib/litmus/http-chaos/lib/reset/reset.go @@ -16,7 +16,7 @@ import ( // PodHttpResetPeerChaos contains the steps to prepare and inject http reset peer chaos func PodHttpResetPeerChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPResetPeerChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodHTTPResetPeerFault") defer span.End() log.InfoWithValues("[Info]: The chaos tunables are:", logrus.Fields{ diff --git a/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go b/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go index c2a115a32..228e1072d 100644 --- a/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go +++ b/chaoslib/litmus/http-chaos/lib/statuscode/status-code.go @@ -31,7 +31,7 @@ var acceptedStatusCodes = []string{ // PodHttpStatusCodeChaos contains the steps to prepare and inject http status code chaos func PodHttpStatusCodeChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodHTTPStatusCodeChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodHttpStatusCodeFault") defer span.End() // responseBodyMaxLength defines the max length of response body string to be printed. It is taken as diff --git a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go index f89afc377..1de1d862b 100644 --- a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go +++ b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go @@ -23,6 +23,9 @@ import ( ) func experimentExecution(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectK6LoadGenFault") + defer span.End() + if experimentsDetails.EngineName != "" { msg := "Injecting " + experimentsDetails.ExperimentName + " chaos" types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails) @@ -71,7 +74,7 @@ func experimentExecution(ctx context.Context, experimentsDetails *experimentType // PrepareChaos contains the preparation steps before chaos injection func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectK6LoadGenChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareK6LoadGenFault") defer span.End() // Waiting for the ramp time before chaos injection @@ -95,7 +98,7 @@ func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.Exper // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, runID string) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateK6LoadGenHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateK6LoadGenFaultHelperPod") defer span.End() const volumeName = "script-volume" diff --git a/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go b/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go index b5646d041..d828f614d 100644 --- a/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go +++ b/chaoslib/litmus/kafka-broker-pod-failure/lib/pod-delete.go @@ -27,7 +27,7 @@ import ( // PreparePodDelete contains the prepration steps before chaos injection func PreparePodDelete(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectKafkaPodDeleteChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareKafkaPodDeleteFault") defer span.End() //Waiting for the ramp time before chaos injection @@ -59,7 +59,8 @@ func PreparePodDelete(ctx context.Context, experimentsDetails *experimentTypes.E // injectChaosInSerialMode delete the kafka broker pods in serial mode(one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { - + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectKafkaPodDeleteFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { @@ -154,7 +155,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode delete the kafka broker pods in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { - + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectKafkaPodDeleteFaultInParallelMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { diff --git a/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go b/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go index 3132902b7..350a8b390 100644 --- a/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go +++ b/chaoslib/litmus/kubelet-service-kill/lib/kubelet-service-kill.go @@ -26,7 +26,7 @@ import ( // PrepareKubeletKill contains prepration steps before chaos injection func PrepareKubeletKill(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectKubeletServiceKillChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareKubeletServiceKillFault") defer span.End() var err error @@ -117,7 +117,7 @@ func PrepareKubeletKill(ctx context.Context, experimentsDetails *experimentTypes // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, appNodeName string) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateKubeletServiceKillHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateKubeletServiceKillFaultHelperPod") defer span.End() privileged := true diff --git a/chaoslib/litmus/network-chaos/lib/corruption/corruption.go b/chaoslib/litmus/network-chaos/lib/corruption/corruption.go index 18da21d3d..4d78450da 100644 --- a/chaoslib/litmus/network-chaos/lib/corruption/corruption.go +++ b/chaoslib/litmus/network-chaos/lib/corruption/corruption.go @@ -13,7 +13,7 @@ import ( // PodNetworkCorruptionChaos contains the steps to prepare and inject chaos func PodNetworkCorruptionChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkCorruptionChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodNetworkCorruptionFault") defer span.End() args := "corrupt " + experimentsDetails.NetworkPacketCorruptionPercentage diff --git a/chaoslib/litmus/network-chaos/lib/duplication/duplication.go b/chaoslib/litmus/network-chaos/lib/duplication/duplication.go index e428e3cec..9ceae9fe6 100644 --- a/chaoslib/litmus/network-chaos/lib/duplication/duplication.go +++ b/chaoslib/litmus/network-chaos/lib/duplication/duplication.go @@ -13,7 +13,7 @@ import ( // PodNetworkDuplicationChaos contains the steps to prepare and inject chaos func PodNetworkDuplicationChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkDuplicationChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodNetworkDuplicationFault") defer span.End() args := "duplicate " + experimentsDetails.NetworkPacketDuplicationPercentage diff --git a/chaoslib/litmus/network-chaos/lib/latency/latency.go b/chaoslib/litmus/network-chaos/lib/latency/latency.go index 817533fde..e3f849fbb 100644 --- a/chaoslib/litmus/network-chaos/lib/latency/latency.go +++ b/chaoslib/litmus/network-chaos/lib/latency/latency.go @@ -14,7 +14,7 @@ import ( // PodNetworkLatencyChaos contains the steps to prepare and inject chaos func PodNetworkLatencyChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkLatencyChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodNetworkLatencyFault") defer span.End() args := "delay " + strconv.Itoa(experimentsDetails.NetworkLatency) + "ms " + strconv.Itoa(experimentsDetails.Jitter) + "ms" diff --git a/chaoslib/litmus/network-chaos/lib/loss/loss.go b/chaoslib/litmus/network-chaos/lib/loss/loss.go index a4acdb2b2..336c57a66 100644 --- a/chaoslib/litmus/network-chaos/lib/loss/loss.go +++ b/chaoslib/litmus/network-chaos/lib/loss/loss.go @@ -13,7 +13,7 @@ import ( // PodNetworkLossChaos contains the steps to prepare and inject chaos func PodNetworkLossChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkLossChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodNetworkLossFault") defer span.End() args := "loss " + experimentsDetails.NetworkPacketLossPercentage diff --git a/chaoslib/litmus/network-chaos/lib/network-chaos.go b/chaoslib/litmus/network-chaos/lib/network-chaos.go index 3ae0b0f17..dc73645f8 100644 --- a/chaoslib/litmus/network-chaos/lib/network-chaos.go +++ b/chaoslib/litmus/network-chaos/lib/network-chaos.go @@ -88,6 +88,9 @@ func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTy // injectChaosInSerialMode inject the network chaos in all target application serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, args string, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkFaultInSerialMode") + defer span.End() + // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { if err := probe.RunProbes(ctx, chaosDetails, clients, resultDetails, "DuringChaos", eventsDetails); err != nil { @@ -144,6 +147,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode inject the network chaos in all target application in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, args string, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkFaultInParallelMode") + defer span.End() var err error // run the probes during chaos @@ -200,7 +205,7 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets string, nodeName, runID, args string) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNetworkChaosHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreatePodNetworkFaultHelperPod") defer span.End() privilegedEnable := true diff --git a/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go b/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go index aa1685c63..57bd9adb0 100644 --- a/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go +++ b/chaoslib/litmus/node-cpu-hog/lib/node-cpu-hog.go @@ -27,7 +27,7 @@ import ( // PrepareNodeCPUHog contains preparation steps before chaos injection func PrepareNodeCPUHog(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeCPUHogChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareNodeCPUHogFault") defer span.End() //set up the tunables if provided in range @@ -87,6 +87,8 @@ func PrepareNodeCPUHog(ctx context.Context, experimentsDetails *experimentTypes. // injectChaosInSerialMode stress the cpu of all the target nodes serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeCPUHogFaultInSerialMode") + defer span.End() nodeCPUCores := experimentsDetails.NodeCPUcores @@ -154,6 +156,9 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode stress the cpu of all the target nodes in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeCPUHogFaultInParallelMode") + defer span.End() + nodeCPUCores := experimentsDetails.NodeCPUcores // run the probes during chaos @@ -233,7 +238,7 @@ func setCPUCapacity(experimentsDetails *experimentTypes.ExperimentDetails, appNo // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeCPUHogHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeCPUHogFaultHelperPod") defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-drain/lib/node-drain.go b/chaoslib/litmus/node-drain/lib/node-drain.go index 37fcb5425..b46dd34bf 100644 --- a/chaoslib/litmus/node-drain/lib/node-drain.go +++ b/chaoslib/litmus/node-drain/lib/node-drain.go @@ -36,7 +36,7 @@ var ( // PrepareNodeDrain contains the preparation steps before chaos injection func PrepareNodeDrain(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeDrainChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareNodeDrainFault") defer span.End() // inject channel is used to transmit signal notifications. @@ -80,7 +80,7 @@ func PrepareNodeDrain(ctx context.Context, experimentsDetails *experimentTypes.E go abortWatcher(experimentsDetails, clients, resultDetails, chaosDetails, eventsDetails) // Drain the application node - if err := drainNode(experimentsDetails, clients, chaosDetails); err != nil { + if err := drainNode(ctx, experimentsDetails, clients, chaosDetails); err != nil { log.Info("[Revert]: Reverting chaos because error during draining of node") if uncordonErr := uncordonNode(experimentsDetails, clients, chaosDetails); uncordonErr != nil { return cerrors.PreserveError{ErrString: fmt.Sprintf("[%s,%s]", stacktrace.RootCause(err).Error(), stacktrace.RootCause(uncordonErr).Error())} @@ -130,7 +130,9 @@ func PrepareNodeDrain(ctx context.Context, experimentsDetails *experimentTypes.E } // drainNode drain the target node -func drainNode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails) error { +func drainNode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeDrainFault") + defer span.End() select { case <-inject: diff --git a/chaoslib/litmus/node-io-stress/lib/node-io-stress.go b/chaoslib/litmus/node-io-stress/lib/node-io-stress.go index 995100dba..94b269a81 100644 --- a/chaoslib/litmus/node-io-stress/lib/node-io-stress.go +++ b/chaoslib/litmus/node-io-stress/lib/node-io-stress.go @@ -27,7 +27,7 @@ import ( // PrepareNodeIOStress contains preparation steps before chaos injection func PrepareNodeIOStress(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeIOStressChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareNodeIOStressFault") defer span.End() //set up the tunables if provided in range setChaosTunables(experimentsDetails) @@ -87,6 +87,8 @@ func PrepareNodeIOStress(ctx context.Context, experimentsDetails *experimentType // injectChaosInSerialMode stress the io of all the target nodes serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeIOStressFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -145,6 +147,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode stress the io of all the target nodes in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeIOStressFaultInParallelMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -209,7 +213,7 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeIOStressHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeIOStressFaultHelperPod") defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go b/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go index 1d14d0a41..6562d817f 100644 --- a/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go +++ b/chaoslib/litmus/node-memory-hog/lib/node-memory-hog.go @@ -28,7 +28,7 @@ import ( // PrepareNodeMemoryHog contains preparation steps before chaos injection func PrepareNodeMemoryHog(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeMemoryHogChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareNodeMemoryHogFault") defer span.End() //set up the tunables if provided in range @@ -89,6 +89,8 @@ func PrepareNodeMemoryHog(ctx context.Context, experimentsDetails *experimentTyp // injectChaosInSerialMode stress the memory of all the target nodes serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeMemoryHogFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -163,6 +165,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode stress the memory all the target nodes in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetNodeList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeMemoryHogFaultInParallelMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -317,7 +321,7 @@ func calculateMemoryConsumption(experimentsDetails *experimentTypes.ExperimentDe // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, chaosDetails *types.ChaosDetails, appNode string, clients clients.ClientSets, MemoryConsumption string) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeMemoryHogHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeMemoryHogFaultHelperPod") defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-restart/lib/node-restart.go b/chaoslib/litmus/node-restart/lib/node-restart.go index 5afa517be..d4750912e 100644 --- a/chaoslib/litmus/node-restart/lib/node-restart.go +++ b/chaoslib/litmus/node-restart/lib/node-restart.go @@ -41,7 +41,7 @@ const ( // PrepareNodeRestart contains preparation steps before chaos injection func PrepareNodeRestart(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeRestartChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareNodeRestartFault") defer span.End() //Select the node @@ -135,7 +135,7 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex // This method is attaching emptyDir along with secret volume, and copy data from secret // to the emptyDir, because secret is mounted as readonly and with 777 perms and it can't be changed // because of: https://github.com/kubernetes/kubernetes/issues/57923 - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeRestartHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateNodeRestartFaultHelperPod") defer span.End() terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/node-taint/lib/node-taint.go b/chaoslib/litmus/node-taint/lib/node-taint.go index 118d6bcec..8efd0a289 100644 --- a/chaoslib/litmus/node-taint/lib/node-taint.go +++ b/chaoslib/litmus/node-taint/lib/node-taint.go @@ -33,7 +33,7 @@ var ( // PrepareNodeTaint contains the preparation steps before chaos injection func PrepareNodeTaint(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeTaintChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareNodeTaintFault") defer span.End() // inject channel is used to transmit signal notifications. @@ -77,7 +77,7 @@ func PrepareNodeTaint(ctx context.Context, experimentsDetails *experimentTypes.E go abortWatcher(experimentsDetails, clients, resultDetails, chaosDetails, eventsDetails) // taint the application node - if err := taintNode(experimentsDetails, clients, chaosDetails); err != nil { + if err := taintNode(ctx, experimentsDetails, clients, chaosDetails); err != nil { return stacktrace.Propagate(err, "could not taint node") } @@ -122,7 +122,9 @@ func PrepareNodeTaint(ctx context.Context, experimentsDetails *experimentTypes.E } // taintNode taint the application node -func taintNode(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails) error { +func taintNode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectNodeTaintFault") + defer span.End() // get the taint labels & effect taintKey, taintValue, taintEffect := getTaintDetails(experimentsDetails) diff --git a/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go b/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go index 915f9979d..feefad7f6 100644 --- a/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go +++ b/chaoslib/litmus/pod-autoscaler/lib/pod-autoscaler.go @@ -36,7 +36,7 @@ var ( // PreparePodAutoscaler contains the preparation steps and chaos injection steps func PreparePodAutoscaler(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodAutoScalerChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodAutoscalerFault") defer span.End() //Waiting for the ramp time before chaos injection diff --git a/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go b/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go index 22d7234a2..f28be58f7 100644 --- a/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go +++ b/chaoslib/litmus/pod-cpu-hog-exec/lib/pod-cpu-hog-exec.go @@ -31,7 +31,7 @@ var inject chan os.Signal // PrepareCPUExecStress contains the chaos preparation and injection steps func PrepareCPUExecStress(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectCPUExecStressChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodCPUHogExecFault") defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) @@ -59,7 +59,7 @@ func PrepareCPUExecStress(ctx context.Context, experimentsDetails *experimentTyp // The function will be constantly increasing the CPU utilisation until it reaches the maximum available or allowed number. // Using the TOTAL_CHAOS_DURATION we will need to specify for how long this experiment will last func stressCPU(experimentsDetails *experimentTypes.ExperimentDetails, podName, ns string, clients clients.ClientSets, stressErr chan error) { - // It will contains all the pod & container details required for exec command + // It will contain all the pod & container details required for exec command execCommandDetails := litmusexec.PodDetails{} command := []string{"/bin/sh", "-c", experimentsDetails.ChaosInjectCmd} litmusexec.SetExecCommandAttributes(&execCommandDetails, podName, experimentsDetails.TargetContainer, ns) @@ -69,7 +69,6 @@ func stressCPU(experimentsDetails *experimentTypes.ExperimentDetails, podName, n // experimentCPU function orchestrates the experiment by calling the StressCPU function for every core, of every container, of every pod that is targeted func experimentCPU(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage if experimentsDetails.TargetPods == "" && chaosDetails.AppDetail == nil { @@ -106,6 +105,8 @@ func experimentCPU(ctx context.Context, experimentsDetails *experimentTypes.Expe // injectChaosInSerialMode stressed the cpu of all target application serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodCPUHogExecFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -203,6 +204,9 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode stressed the cpu of all target application in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodCPUHogExecFaultInParallelMode") + defer span.End() + // creating err channel to receive the error from the go routine stressErr := make(chan error) diff --git a/chaoslib/litmus/pod-delete/lib/pod-delete.go b/chaoslib/litmus/pod-delete/lib/pod-delete.go index 0553c403f..aa4fec6e8 100644 --- a/chaoslib/litmus/pod-delete/lib/pod-delete.go +++ b/chaoslib/litmus/pod-delete/lib/pod-delete.go @@ -26,7 +26,7 @@ import ( // PreparePodDelete contains the preparation steps before chaos injection func PreparePodDelete(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodDeleteChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodDeleteFault") defer span.End() //Waiting for the ramp time before chaos injection @@ -66,6 +66,8 @@ func PreparePodDelete(ctx context.Context, experimentsDetails *experimentTypes.E // injectChaosInSerialMode delete the target application pods serial mode(one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodDeleteFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -163,6 +165,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode delete the target application pods in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodDeleteFaultInParallelMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { diff --git a/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go b/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go index a0071896c..ce608e564 100644 --- a/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go +++ b/chaoslib/litmus/pod-dns-chaos/lib/pod-dns-chaos.go @@ -28,7 +28,7 @@ import ( // PrepareAndInjectChaos contains the preparation & injection steps func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodDNSChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodDNSFault") defer span.End() // Get the target pod details for the chaos execution // if the target pod is not defined it will derive the random target pod list using pod affected percentage @@ -85,6 +85,8 @@ func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTy // injectChaosInSerialMode inject the DNS Chaos in all target application serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodDNSFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -141,6 +143,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode inject the DNS Chaos in all target application in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodDNSFaultInParallelMode") + defer span.End() var err error // run the probes during chaos @@ -197,7 +201,7 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreatePodDNSChaosHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreatePodDNSFaultHelperPod") defer span.End() privilegedEnable := true terminationGracePeriodSeconds := int64(experimentsDetails.TerminationGracePeriodSeconds) diff --git a/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go b/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go index 0b7cc1389..56cecf6e1 100644 --- a/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go +++ b/chaoslib/litmus/pod-fio-stress/lib/pod-fio-stress.go @@ -29,7 +29,7 @@ import ( // PrepareChaos contains the chaos preparation and injection steps func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPidFIOStressChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodFIOStressFault") defer span.End() //Waiting for the ramp time before chaos injection @@ -110,6 +110,9 @@ func experimentExecution(ctx context.Context, experimentsDetails *experimentType // injectChaosInSerialMode stressed the storage of all target application in serial mode (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodFIOStressFaultInSerialMode") + defer span.End() + // creating err channel to receive the error from the go routine stressErr := make(chan error) // run the probes during chaos @@ -191,6 +194,9 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode stressed the storage of all target application in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodFIOStressFaultInParallelMode") + defer span.End() + // creating err channel to receive the error from the go routine stressErr := make(chan error) // run the probes during chaos diff --git a/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go b/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go index 6ae51c8f6..cbd9c0f4f 100644 --- a/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go +++ b/chaoslib/litmus/pod-memory-hog-exec/lib/pod-memory-hog-exec.go @@ -32,7 +32,7 @@ var inject chan os.Signal // PrepareMemoryExecStress contains the chaos preparation and injection steps func PrepareMemoryExecStress(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodMemoryHogChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodMemoryHogExecFault") defer span.End() // inject channel is used to transmit signal notifications. @@ -115,6 +115,8 @@ func experimentMemory(ctx context.Context, experimentsDetails *experimentTypes.E // injectChaosInSerialMode stressed the memory of all target application serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodMemoryHogExecFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -209,6 +211,9 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode stressed the memory of all target application in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList corev1.PodList, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodMemoryHogExecFaultInParallelMode") + defer span.End() + // creating err channel to receive the error from the go routine stressErr := make(chan error) // run the probes during chaos diff --git a/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go b/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go index 79fffbe69..ac1b37717 100644 --- a/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go +++ b/chaoslib/litmus/pod-network-partition/lib/pod-network-partition.go @@ -35,7 +35,7 @@ var ( // PrepareAndInjectChaos contains the prepration & injection steps func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkPartitionChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodNetworkPartitionFault") defer span.End() // inject channel is used to transmit signal notifications. @@ -106,7 +106,7 @@ func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTy os.Exit(0) default: // creating the network policy to block the traffic - if err := createNetworkPolicy(experimentsDetails, clients, np, runID); err != nil { + if err := createNetworkPolicy(ctx, experimentsDetails, clients, np, runID); err != nil { return stacktrace.Propagate(err, "could not create network policy") } // updating chaos status to injected for the target pods @@ -144,7 +144,9 @@ func PrepareAndInjectChaos(ctx context.Context, experimentsDetails *experimentTy // createNetworkPolicy creates the network policy in the application namespace // it blocks ingress/egress traffic for the targeted application for specific/all IPs -func createNetworkPolicy(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, networkPolicy *NetworkPolicy, runID string) error { +func createNetworkPolicy(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, networkPolicy *NetworkPolicy, runID string) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodNetworkPartitionFault") + defer span.End() np := &networkv1.NetworkPolicy{ ObjectMeta: v1.ObjectMeta{ diff --git a/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go b/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go index bd76590ad..61fa9c44d 100644 --- a/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go +++ b/chaoslib/litmus/redfish-node-restart/lib/redfish-node-restart.go @@ -19,7 +19,10 @@ import ( ) // injectChaos initiates node restart chaos on the target node -func injectChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets) error { +func injectChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectRedfishNodeRestartFault") + defer span.End() + URL := fmt.Sprintf("https://%v/redfish/v1/Systems/System.Embedded.1/Actions/ComputerSystem.Reset", experimentsDetails.IPMIIP) return redfishLib.RebootNode(URL, experimentsDetails.User, experimentsDetails.Password) } @@ -40,7 +43,7 @@ func experimentExecution(ctx context.Context, experimentsDetails *experimentType events.GenerateEvents(eventsDetails, clients, chaosDetails, "ChaosEngine") } - if err := injectChaos(experimentsDetails, clients); err != nil { + if err := injectChaos(ctx, experimentsDetails, clients); err != nil { return stacktrace.Propagate(err, "chaos injection failed") } @@ -51,7 +54,7 @@ func experimentExecution(ctx context.Context, experimentsDetails *experimentType // PrepareChaos contains the chaos prepration and injection steps func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectRedfishNodeRestartChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareRedfishNodeRestartFault") defer span.End() //Waiting for the ramp time before chaos injection diff --git a/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go b/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go index 29fe4f7c0..6980608a6 100644 --- a/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go +++ b/chaoslib/litmus/spring-boot-chaos/lib/spring-boot-chaos.go @@ -55,7 +55,7 @@ func SetTargetPodList(experimentsDetails *experimentTypes.ExperimentDetails, cli // PrepareChaos contains the preparation steps before chaos injection func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectSpringBootChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareSpringBootFault") defer span.End() // Waiting for the ramp time before chaos injection @@ -218,6 +218,8 @@ func disableChaosMonkey(ctx context.Context, chaosMonkeyPort string, chaosMonkey // injectChaosInSerialMode injects chaos monkey assault on pods in serial mode(one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectSpringBootFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -306,6 +308,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode injects chaos monkey assault on pods in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, eventsDetails *types.EventDetails, resultDetails *types.ResultDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectSpringBootFaultInParallelMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { diff --git a/chaoslib/litmus/stress-chaos/lib/stress-chaos.go b/chaoslib/litmus/stress-chaos/lib/stress-chaos.go index 8aa6a8461..bfa6c878c 100644 --- a/chaoslib/litmus/stress-chaos/lib/stress-chaos.go +++ b/chaoslib/litmus/stress-chaos/lib/stress-chaos.go @@ -27,7 +27,7 @@ import ( // PrepareAndInjectStressChaos contains the prepration & injection steps for the stress experiments. func PrepareAndInjectStressChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectStressChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PreparePodStressFault") defer span.End() var err error //Set up the tunables if provided in range @@ -109,6 +109,8 @@ func PrepareAndInjectStressChaos(ctx context.Context, experimentsDetails *experi // injectChaosInSerialMode inject the stress chaos in all target application serially (one by one) func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodStressFaultInSerialMode") + defer span.End() // run the probes during chaos if len(resultDetails.ProbeDetails) != 0 { @@ -165,6 +167,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode inject the stress chaos in all target application in parallel mode (all at once) func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetPodList apiv1.PodList, clients clients.ClientSets, chaosDetails *types.ChaosDetails, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectPodStressFaultInParallelMode") + defer span.End() var err error // run the probes during chaos @@ -218,7 +222,7 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateStressHelperPod") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreatePodStressFaultHelperPod") defer span.End() privilegedEnable := true diff --git a/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go b/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go index 084ceff6b..e828be326 100644 --- a/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go +++ b/chaoslib/litmus/vm-poweroff/lib/vm-poweroff.go @@ -27,7 +27,7 @@ var inject, abort chan os.Signal // InjectVMPowerOffChaos injects the chaos in serial or parallel mode func InjectVMPowerOffChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails, cookie string) error { - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectVMPowerOffChaos") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "PrepareVMPowerOffFault") defer span.End() // inject channel is used to transmit signal notifications. inject = make(chan os.Signal, 1) @@ -75,6 +75,9 @@ func InjectVMPowerOffChaos(ctx context.Context, experimentsDetails *experimentTy // injectChaosInSerialMode stops VMs in serial mode i.e. one after the other func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, vmIdList []string, cookie string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "injectVMPowerOffFaultInSerialMode") + defer span.End() + select { case <-inject: // stopping the chaos execution, if abort signal received @@ -146,6 +149,8 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment // injectChaosInParallelMode stops VMs in parallel mode i.e. all at once func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, vmIdList []string, cookie string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "injectVMPowerOffFaultInParallelMode") + defer span.End() select { case <-inject: From 2d476f8837b8bd1cfb88dee9694a5fd27692cede Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Wed, 9 Oct 2024 20:54:28 +0900 Subject: [PATCH 09/12] fix: avoid shadowing Signed-off-by: namkyu1999 --- bin/experiment/experiment.go | 10 +++++----- bin/helper/helper.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/experiment/experiment.go b/bin/experiment/experiment.go index 64b351671..a3125d0ec 100755 --- a/bin/experiment/experiment.go +++ b/bin/experiment/experiment.go @@ -80,23 +80,23 @@ func init() { } func main() { - ctx := context.Background() + initCtx := context.Background() // Set up Observability. if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" { - shutdown, err := telemetry.InitOTelSDK(ctx, true, otelExporterEndpoint) + shutdown, err := telemetry.InitOTelSDK(initCtx, true, otelExporterEndpoint) if err != nil { return } defer func() { - err = errors.Join(err, shutdown(ctx)) + err = errors.Join(err, shutdown(initCtx)) }() - ctx = telemetry.GetTraceParentContext() + initCtx = telemetry.GetTraceParentContext() } clients := cli.ClientSets{} - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "ExecuteExperiment") + ctx, span := otel.Tracer(telemetry.TracerName).Start(initCtx, "ExecuteExperiment") defer span.End() // parse the experiment name diff --git a/bin/helper/helper.go b/bin/helper/helper.go index eac6971f0..b753b7426 100644 --- a/bin/helper/helper.go +++ b/bin/helper/helper.go @@ -53,7 +53,7 @@ func main() { clients := cli.ClientSets{} - ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "ExecuteExperimentHelper") + _, span := otel.Tracer(telemetry.TracerName).Start(ctx, "ExecuteExperimentHelper") defer span.End() // parse the helper name From 087a199a55478d7d68b55dcd5fef6345acaf337a Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Wed, 9 Oct 2024 21:16:17 +0900 Subject: [PATCH 10/12] fix: add logs Signed-off-by: namkyu1999 --- bin/experiment/experiment.go | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/experiment/experiment.go b/bin/experiment/experiment.go index a3125d0ec..ef01e1f2f 100755 --- a/bin/experiment/experiment.go +++ b/bin/experiment/experiment.go @@ -86,6 +86,7 @@ func main() { if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" { shutdown, err := telemetry.InitOTelSDK(initCtx, true, otelExporterEndpoint) if err != nil { + log.Errorf("Failed to initialize OTel SDK: %v", err) return } defer func() { From f55bfb773458ff6b36f64bf04d521f3abbd8eeee Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Wed, 9 Oct 2024 21:17:27 +0900 Subject: [PATCH 11/12] fix: add logs Signed-off-by: namkyu1999 --- bin/helper/helper.go | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/helper/helper.go b/bin/helper/helper.go index b753b7426..667c79293 100644 --- a/bin/helper/helper.go +++ b/bin/helper/helper.go @@ -43,6 +43,7 @@ func main() { if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" { shutdown, err := telemetry.InitOTelSDK(ctx, true, otelExporterEndpoint) if err != nil { + log.Errorf("Failed to initialize OTel SDK: %v", err) return } defer func() { From c27b4501af48f868e3ab197949e674923e2e286b Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Thu, 10 Oct 2024 22:20:44 +0900 Subject: [PATCH 12/12] fix: fix templates Signed-off-by: namkyu1999 --- contribute/developer-guide/templates/chaoslib_helper.tmpl | 4 ++-- .../developer-guide/templates/chaoslib_non-k8s.tmpl | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/contribute/developer-guide/templates/chaoslib_helper.tmpl b/contribute/developer-guide/templates/chaoslib_helper.tmpl index 6e88616b0..92b091f07 100644 --- a/contribute/developer-guide/templates/chaoslib_helper.tmpl +++ b/contribute/developer-guide/templates/chaoslib_helper.tmpl @@ -126,7 +126,7 @@ func runChaos(ctx context.Context, experimentsDetails *experimentTypes.Experimen //PrepareChaos contains the preparation steps before chaos injection func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // @TODO: setup tracing - // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "name-your-chaos-fault") + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "Prepare[name-your-chaos]Fault") // defer span.End() //Waiting for the ramp time before chaos injection @@ -149,7 +149,7 @@ func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.Exper // createHelperPod derive the attributes for helper pod and create the helper pod func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, chaosDetails *types.ChaosDetails, targets, nodeName, runID string) error { // @TODO: setup tracing - // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "CreateHelperPod") + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "Create[name-your-chaos]FaultHelperPod") // defer span.End() helperPod := &corev1.Pod{ diff --git a/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl b/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl index 7f11d65d5..717d39438 100644 --- a/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl +++ b/contribute/developer-guide/templates/chaoslib_non-k8s.tmpl @@ -25,7 +25,7 @@ var ( //PrepareChaos contains the preparation and injection steps for the experiment func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { // @TODO: setup tracing - // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectChaos") + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "Prepare[name-your-chaos]Fault") // defer span.End() // inject channel is used to transmit signal notifications. @@ -78,6 +78,9 @@ func PrepareChaos(ctx context.Context, experimentsDetails *experimentTypes.Exper //injectChaosInSerialMode will inject the chaos on the target one after other func injectChaosInSerialMode(ctx context.Contxt, experimentsDetails *experimentTypes.ExperimentDetails, targetIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + // @TODO: setup tracing + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "Inject[name-your-chaos]FaultInSerialMode") + // defer span.End() select { case <-inject: @@ -141,6 +144,9 @@ func injectChaosInSerialMode(ctx context.Contxt, experimentsDetails *experimentT // injectChaosInParallelMode will inject the chaos on the target all at once func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, targetIDList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error { + // @TODO: setup tracing + // ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "Inject[name-your-chaos]FaultInParallelMode") + // defer span.End() select { case <-inject: