From a5d3425a373d7d8678684a5c0b8a6b6f1c49b43a Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Fri, 22 Nov 2024 17:25:40 +0900 Subject: [PATCH 1/2] Export k6 results to the otel collector Signed-off-by: namkyu1999 --- chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go | 38 ++++++++++++++++---- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go index 1de1d862b..64ecfdbb9 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: "k6_", + }, + { + 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{ { From f436f217d13082b9ba930146b43e80a0e8620049 Mon Sep 17 00:00:00 2001 From: namkyu1999 Date: Fri, 22 Nov 2024 18:04:30 +0900 Subject: [PATCH 2/2] add envs for multiple projects Signed-off-by: namkyu1999 --- chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go | 2 +- pkg/load/k6-loadgen/environment/environment.go | 2 +- pkg/load/k6-loadgen/types/types.go | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go index 64ecfdbb9..79ce56b30 100644 --- a/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go +++ b/chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go @@ -119,7 +119,7 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex envs = []corev1.EnvVar{ { Name: "K6_OTEL_METRIC_PREFIX", - Value: "k6_", + Value: experimentsDetails.OTELMetricPrefix, }, { Name: "K6_OTEL_GRPC_EXPORTER_INSECURE", 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 }