From 48cac2327749efd6350f1590ec14f5bacfc44fc0 Mon Sep 17 00:00:00 2001 From: Suhyen Im Date: Wed, 13 Nov 2024 17:14:29 +0900 Subject: [PATCH] feat: propagate trace context to helper pods Signed-off-by: Suhyen Im --- bin/helper/helper.go | 14 +++++++------- .../litmus/container-kill/helper/container-kill.go | 6 +++++- chaoslib/litmus/disk-fill/helper/disk-fill.go | 6 +++++- chaoslib/litmus/http-chaos/helper/http-helper.go | 7 ++++++- chaoslib/litmus/network-chaos/helper/netem.go | 7 ++++++- chaoslib/litmus/pod-dns-chaos/helper/dnschaos.go | 7 ++++++- .../litmus/stress-chaos/helper/stress-helper.go | 7 ++++++- 7 files changed, 41 insertions(+), 13 deletions(-) diff --git a/bin/helper/helper.go b/bin/helper/helper.go index 667c79293..c2774a131 100644 --- a/bin/helper/helper.go +++ b/bin/helper/helper.go @@ -54,7 +54,7 @@ func main() { clients := cli.ClientSets{} - _, span := otel.Tracer(telemetry.TracerName).Start(ctx, "ExecuteExperimentHelper") + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "ExecuteExperimentHelper") defer span.End() // parse the helper name @@ -71,17 +71,17 @@ func main() { // invoke the corresponding helper based on the the (-name) flag switch *helperName { case "container-kill": - containerKill.Helper(clients) + containerKill.Helper(ctx, clients) case "disk-fill": - diskFill.Helper(clients) + diskFill.Helper(ctx, clients) case "dns-chaos": - dnsChaos.Helper(clients) + dnsChaos.Helper(ctx, clients) case "stress-chaos": - stressChaos.Helper(clients) + stressChaos.Helper(ctx, clients) case "network-chaos": - networkChaos.Helper(clients) + networkChaos.Helper(ctx, clients) case "http-chaos": - httpChaos.Helper(clients) + httpChaos.Helper(ctx, clients) default: log.Errorf("Unsupported -name %v, please provide the correct value of -name args", *helperName) diff --git a/chaoslib/litmus/container-kill/helper/container-kill.go b/chaoslib/litmus/container-kill/helper/container-kill.go index 6ea335467..81e6b1a67 100644 --- a/chaoslib/litmus/container-kill/helper/container-kill.go +++ b/chaoslib/litmus/container-kill/helper/container-kill.go @@ -4,6 +4,8 @@ import ( "bytes" "context" "fmt" + "github.com/litmuschaos/litmus-go/pkg/telemetry" + "go.opentelemetry.io/otel" "os/exec" "strconv" "time" @@ -27,7 +29,9 @@ import ( var err error // Helper injects the container-kill chaos -func Helper(clients clients.ClientSets) { +func Helper(ctx context.Context, clients clients.ClientSets) { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "SimulateContainerKillFault") + defer span.End() experimentsDetails := experimentTypes.ExperimentDetails{} eventsDetails := types.EventDetails{} diff --git a/chaoslib/litmus/disk-fill/helper/disk-fill.go b/chaoslib/litmus/disk-fill/helper/disk-fill.go index 0ebaf03be..c851ba26f 100644 --- a/chaoslib/litmus/disk-fill/helper/disk-fill.go +++ b/chaoslib/litmus/disk-fill/helper/disk-fill.go @@ -4,7 +4,9 @@ import ( "context" "fmt" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "os" "os/exec" "os/signal" @@ -29,7 +31,9 @@ import ( var inject, abort chan os.Signal // Helper injects the disk-fill chaos -func Helper(clients clients.ClientSets) { +func Helper(ctx context.Context, clients clients.ClientSets) { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "SimulateDiskFillFault") + defer span.End() experimentsDetails := experimentTypes.ExperimentDetails{} eventsDetails := types.EventDetails{} diff --git a/chaoslib/litmus/http-chaos/helper/http-helper.go b/chaoslib/litmus/http-chaos/helper/http-helper.go index e5a0bd29c..b544df448 100644 --- a/chaoslib/litmus/http-chaos/helper/http-helper.go +++ b/chaoslib/litmus/http-chaos/helper/http-helper.go @@ -1,9 +1,12 @@ package helper import ( + "context" "fmt" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "os" "os/signal" "strconv" @@ -27,7 +30,9 @@ var ( ) // Helper injects the http chaos -func Helper(clients clients.ClientSets) { +func Helper(ctx context.Context, clients clients.ClientSets) { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "SimulatePodHTTPFault") + defer span.End() experimentsDetails := experimentTypes.ExperimentDetails{} eventsDetails := types.EventDetails{} diff --git a/chaoslib/litmus/network-chaos/helper/netem.go b/chaoslib/litmus/network-chaos/helper/netem.go index 88b02ec6f..8868cb181 100644 --- a/chaoslib/litmus/network-chaos/helper/netem.go +++ b/chaoslib/litmus/network-chaos/helper/netem.go @@ -1,10 +1,13 @@ package helper import ( + "context" "fmt" "github.com/litmuschaos/litmus-go/pkg/cerrors" "github.com/litmuschaos/litmus-go/pkg/events" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "os" "os/exec" "os/signal" @@ -34,7 +37,9 @@ var ( ) // Helper injects the network chaos -func Helper(clients clients.ClientSets) { +func Helper(ctx context.Context, clients clients.ClientSets) { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "SimulatePodNetworkFault") + defer span.End() experimentsDetails := experimentTypes.ExperimentDetails{} eventsDetails := types.EventDetails{} diff --git a/chaoslib/litmus/pod-dns-chaos/helper/dnschaos.go b/chaoslib/litmus/pod-dns-chaos/helper/dnschaos.go index 794da032e..04b895f9b 100644 --- a/chaoslib/litmus/pod-dns-chaos/helper/dnschaos.go +++ b/chaoslib/litmus/pod-dns-chaos/helper/dnschaos.go @@ -2,9 +2,12 @@ package helper import ( "bytes" + "context" "fmt" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "os" "os/exec" "os/signal" @@ -34,7 +37,9 @@ const ( ) // Helper injects the dns chaos -func Helper(clients clients.ClientSets) { +func Helper(ctx context.Context, clients clients.ClientSets) { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "SimulatePodDNSFault") + defer span.End() experimentsDetails := experimentTypes.ExperimentDetails{} eventsDetails := types.EventDetails{} diff --git a/chaoslib/litmus/stress-chaos/helper/stress-helper.go b/chaoslib/litmus/stress-chaos/helper/stress-helper.go index 13f85418c..88a68fb25 100644 --- a/chaoslib/litmus/stress-chaos/helper/stress-helper.go +++ b/chaoslib/litmus/stress-chaos/helper/stress-helper.go @@ -3,9 +3,12 @@ package helper import ( "bufio" "bytes" + "context" "fmt" "github.com/litmuschaos/litmus-go/pkg/cerrors" + "github.com/litmuschaos/litmus-go/pkg/telemetry" "github.com/palantir/stacktrace" + "go.opentelemetry.io/otel" "io" "os" "os/exec" @@ -51,7 +54,9 @@ const ( ) // Helper injects the stress chaos -func Helper(clients clients.ClientSets) { +func Helper(ctx context.Context, clients clients.ClientSets) { + ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "SimulatePodStressFault") + defer span.End() experimentsDetails := experimentTypes.ExperimentDetails{} eventsDetails := types.EventDetails{}