Skip to content

Commit

Permalink
Export k6 results to the otel collector
Browse files Browse the repository at this point in the history
Signed-off-by: namkyu1999 <[email protected]>
  • Loading branch information
namkyu1999 committed Nov 22, 2024
1 parent 7e08c69 commit a5d3425
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lib
import (
"context"
"fmt"
"os"
"strconv"

"github.com/litmuschaos/litmus-go/pkg/cerrors"
Expand Down Expand Up @@ -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-",
Expand All @@ -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{
{
Expand Down

0 comments on commit a5d3425

Please sign in to comment.