From 86ab69f36c78849a2707c7b1ea8f58f211358fb3 Mon Sep 17 00:00:00 2001 From: Suhyen Im Date: Fri, 20 Dec 2024 17:46:24 +0900 Subject: [PATCH] feat: add span attributes for pod-delete Signed-off-by: Suhyen Im --- bin/experiment/experiment.go | 3 +++ chaoslib/litmus/pod-delete/lib/pod-delete.go | 9 +++++++++ pkg/probe/probe.go | 21 +++++++++++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/bin/experiment/experiment.go b/bin/experiment/experiment.go index ef01e1f2f..ca09cc370 100755 --- a/bin/experiment/experiment.go +++ b/bin/experiment/experiment.go @@ -4,6 +4,7 @@ import ( "context" "errors" "flag" + "go.opentelemetry.io/otel/attribute" "os" // Uncomment to load all auth plugins @@ -109,6 +110,8 @@ func main() { return } + span.SetAttributes(attribute.String("experiment.name", *experimentName)) + log.Infof("Experiment Name: %v", *experimentName) // invoke the corresponding experiment based on the (-name) flag diff --git a/chaoslib/litmus/pod-delete/lib/pod-delete.go b/chaoslib/litmus/pod-delete/lib/pod-delete.go index aa4fec6e8..127e53b1f 100644 --- a/chaoslib/litmus/pod-delete/lib/pod-delete.go +++ b/chaoslib/litmus/pod-delete/lib/pod-delete.go @@ -3,6 +3,7 @@ package lib import ( "context" "fmt" + "go.opentelemetry.io/otel/attribute" "strconv" "strings" "time" @@ -113,6 +114,10 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment //Deleting the application pod for _, pod := range targetPodList.Items { + span.SetAttributes( + attribute.String("pod.name", pod.Name), + attribute.String("pod.namespace", pod.Namespace), + ) log.InfoWithValues("[Info]: Killing the following pods", logrus.Fields{ "PodName": pod.Name}) @@ -211,6 +216,10 @@ func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experime //Deleting the application pod for _, pod := range targetPodList.Items { + span.SetAttributes( + attribute.String("pod.name", pod.Name), + attribute.String("pod.namespace", pod.Namespace), + ) log.InfoWithValues("[Info]: Killing the following pods", logrus.Fields{ "PodName": pod.Name}) diff --git a/pkg/probe/probe.go b/pkg/probe/probe.go index fe6e1a271..3800b6c6e 100644 --- a/pkg/probe/probe.go +++ b/pkg/probe/probe.go @@ -4,6 +4,8 @@ import ( "bytes" "context" "fmt" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "html/template" "strings" "time" @@ -35,13 +37,15 @@ func RunProbes(ctx context.Context, chaosDetails *types.ChaosDetails, clients cl return err } + span.SetAttributes(attribute.String("probe.phase", phase)) + switch strings.ToLower(phase) { //execute probes for the prechaos phase case "prechaos": for _, probe := range probes { switch strings.ToLower(probe.Mode) { case "sot", "edge", "continuous": - if err := execute(probe, chaosDetails, clients, resultDetails, phase); err != nil { + if err := execute(ctx, probe, chaosDetails, clients, resultDetails, phase); err != nil { return err } } @@ -50,7 +54,7 @@ func RunProbes(ctx context.Context, chaosDetails *types.ChaosDetails, clients cl case "duringchaos": for _, probe := range probes { if strings.ToLower(probe.Mode) == "onchaos" { - if err := execute(probe, chaosDetails, clients, resultDetails, phase); err != nil { + if err := execute(ctx, probe, chaosDetails, clients, resultDetails, phase); err != nil { return err } } @@ -66,7 +70,7 @@ func RunProbes(ctx context.Context, chaosDetails *types.ChaosDetails, clients cl // evaluate continuous and onchaos probes switch strings.ToLower(probe.Mode) { case "onchaos", "continuous": - if err := execute(probe, chaosDetails, clients, resultDetails, phase); err != nil { + if err := execute(ctx, probe, chaosDetails, clients, resultDetails, phase); err != nil { probeError = append(probeError, stacktrace.RootCause(err).Error()) } } @@ -78,7 +82,7 @@ func RunProbes(ctx context.Context, chaosDetails *types.ChaosDetails, clients cl for _, probe := range probes { switch strings.ToLower(probe.Mode) { case "eot", "edge": - if err := execute(probe, chaosDetails, clients, resultDetails, phase); err != nil { + if err := execute(ctx, probe, chaosDetails, clients, resultDetails, phase); err != nil { return err } } @@ -330,7 +334,14 @@ func stopChaosEngine(probe v1alpha1.ProbeAttributes, clients clients.ClientSets, } // execute contains steps to execute & evaluate probes in different modes at different phases -func execute(probe v1alpha1.ProbeAttributes, chaosDetails *types.ChaosDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, phase string) error { +func execute(ctx context.Context, probe v1alpha1.ProbeAttributes, chaosDetails *types.ChaosDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, phase string) error { + span := trace.SpanFromContext(ctx) + span.SetAttributes( + attribute.String("probe.name", probe.Name), + attribute.String("probe.mode", probe.Mode), + attribute.String("probe.type", probe.Type), + ) + switch strings.ToLower(probe.Type) { case "k8sprobe": // it contains steps to prepare the k8s probe