diff --git a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go index 1de1d862b..79ce56b30 100644 --- a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go +++ b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go @@ -3,6 +3,7 @@ package lib import ( "context" "fmt" + "os" "strconv" "github.com/litmuschaos/litmus-go/pkg/cerrors" @@ -103,6 +104,35 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex const volumeName = "script-volume" const mountPath = "/mnt" + + var envs []corev1.EnvVar + args := []string{ + mountPath + "/" + experimentsDetails.ScriptSecretKey, + "-q", + "--duration", + strconv.Itoa(experimentsDetails.ChaosDuration) + "s", + "--tag", + "trace_id=" + span.SpanContext().TraceID().String(), + } + + if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" { + envs = []corev1.EnvVar{ + { + Name: "K6_OTEL_METRIC_PREFIX", + Value: experimentsDetails.OTELMetricPrefix, + }, + { + Name: "K6_OTEL_GRPC_EXPORTER_INSECURE", + Value: "true", + }, + { + Name: "K6_OTEL_GRPC_EXPORTER_ENDPOINT", + Value: otelExporterEndpoint, + }, + } + args = append(args, "--out", "experimental-opentelemetry") + } + helperPod := &corev1.Pod{ ObjectMeta: v1.ObjectMeta{ GenerateName: experimentsDetails.ExperimentName + "-helper-", @@ -122,12 +152,8 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex "k6", "run", }, - Args: []string{ - mountPath + "/" + experimentsDetails.ScriptSecretKey, - "-q", - "--duration", - strconv.Itoa(experimentsDetails.ChaosDuration) + "s", - }, + Args: args, + Env: envs, Resources: chaosDetails.Resources, VolumeMounts: []corev1.VolumeMount{ { diff --git a/pkg/load/k6-loadgen/environment/environment.go b/pkg/load/k6-loadgen/environment/environment.go index 48ac8df28..aa7507f16 100644 --- a/pkg/load/k6-loadgen/environment/environment.go +++ b/pkg/load/k6-loadgen/environment/environment.go @@ -25,5 +25,5 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) { experimentDetails.LIBImage = types.Getenv("LIB_IMAGE", "ghcr.io/grafana/k6-operator:latest-runner") experimentDetails.ScriptSecretName = types.Getenv("SCRIPT_SECRET_NAME", "k6-script") experimentDetails.ScriptSecretKey = types.Getenv("SCRIPT_SECRET_KEY", "script.js") - + experimentDetails.OTELMetricPrefix = types.Getenv("OTEL_METRIC_PREFIX", "k6_") } diff --git a/pkg/load/k6-loadgen/types/types.go b/pkg/load/k6-loadgen/types/types.go index 915f8a8d5..9b6d6877f 100644 --- a/pkg/load/k6-loadgen/types/types.go +++ b/pkg/load/k6-loadgen/types/types.go @@ -18,4 +18,5 @@ type ExperimentDetails struct { LIBImage string ScriptSecretName string ScriptSecretKey string + OTELMetricPrefix string }