From a6a77d1466f20edfcca23a153bec2a4c1528178c Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Mon, 16 Sep 2024 13:13:32 +0900 Subject: [PATCH] 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 {