Skip to content

Commit

Permalink
feat: add span attributes for pod-delete
Browse files Browse the repository at this point in the history
Signed-off-by: Suhyen Im <[email protected]>
  • Loading branch information
suhyenim committed Dec 20, 2024
1 parent 7e08c69 commit 86ab69f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions bin/experiment/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"flag"
"go.opentelemetry.io/otel/attribute"
"os"

// Uncomment to load all auth plugins
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions chaoslib/litmus/pod-delete/lib/pod-delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lib
import (
"context"
"fmt"
"go.opentelemetry.io/otel/attribute"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Expand Down
21 changes: 16 additions & 5 deletions pkg/probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"context"
"fmt"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
"html/template"
"strings"
"time"
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
}
Expand All @@ -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())
}
}
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 86ab69f

Please sign in to comment.