Skip to content

Commit a5d3425

Browse files
committed
Export k6 results to the otel collector
Signed-off-by: namkyu1999 <[email protected]>
1 parent 7e08c69 commit a5d3425

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

chaoslib/litmus/k6-loadgen/lib/k6-loadgen.go

+32-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package lib
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"strconv"
78

89
"github.com/litmuschaos/litmus-go/pkg/cerrors"
@@ -103,6 +104,35 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex
103104

104105
const volumeName = "script-volume"
105106
const mountPath = "/mnt"
107+
108+
var envs []corev1.EnvVar
109+
args := []string{
110+
mountPath + "/" + experimentsDetails.ScriptSecretKey,
111+
"-q",
112+
"--duration",
113+
strconv.Itoa(experimentsDetails.ChaosDuration) + "s",
114+
"--tag",
115+
"trace_id=" + span.SpanContext().TraceID().String(),
116+
}
117+
118+
if otelExporterEndpoint := os.Getenv(telemetry.OTELExporterOTLPEndpoint); otelExporterEndpoint != "" {
119+
envs = []corev1.EnvVar{
120+
{
121+
Name: "K6_OTEL_METRIC_PREFIX",
122+
Value: "k6_",
123+
},
124+
{
125+
Name: "K6_OTEL_GRPC_EXPORTER_INSECURE",
126+
Value: "true",
127+
},
128+
{
129+
Name: "K6_OTEL_GRPC_EXPORTER_ENDPOINT",
130+
Value: otelExporterEndpoint,
131+
},
132+
}
133+
args = append(args, "--out", "experimental-opentelemetry")
134+
}
135+
106136
helperPod := &corev1.Pod{
107137
ObjectMeta: v1.ObjectMeta{
108138
GenerateName: experimentsDetails.ExperimentName + "-helper-",
@@ -122,12 +152,8 @@ func createHelperPod(ctx context.Context, experimentsDetails *experimentTypes.Ex
122152
"k6",
123153
"run",
124154
},
125-
Args: []string{
126-
mountPath + "/" + experimentsDetails.ScriptSecretKey,
127-
"-q",
128-
"--duration",
129-
strconv.Itoa(experimentsDetails.ChaosDuration) + "s",
130-
},
155+
Args: args,
156+
Env: envs,
131157
Resources: chaosDetails.Resources,
132158
VolumeMounts: []corev1.VolumeMount{
133159
{

0 commit comments

Comments
 (0)