Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add span attributes #729

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading