Skip to content

Commit 9b29558

Browse files
namkyu1999ispeakc0deSaranya-jena
authored
feat: export k6 results output to the OTEL collector (#726)
* Export k6 results to the otel collector Signed-off-by: namkyu1999 <[email protected]> * add envs for multiple projects Signed-off-by: namkyu1999 <[email protected]> --------- Signed-off-by: namkyu1999 <[email protected]> Co-authored-by: Shubham Chaudhary <[email protected]> Co-authored-by: Saranya Jena <[email protected]>
1 parent c7ab5a3 commit 9b29558

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

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

Lines changed: 32 additions & 6 deletions
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: experimentsDetails.OTELMetricPrefix,
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
{

pkg/load/k6-loadgen/environment/environment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
2525
experimentDetails.LIBImage = types.Getenv("LIB_IMAGE", "ghcr.io/grafana/k6-operator:latest-runner")
2626
experimentDetails.ScriptSecretName = types.Getenv("SCRIPT_SECRET_NAME", "k6-script")
2727
experimentDetails.ScriptSecretKey = types.Getenv("SCRIPT_SECRET_KEY", "script.js")
28-
28+
experimentDetails.OTELMetricPrefix = types.Getenv("OTEL_METRIC_PREFIX", "k6_")
2929
}

pkg/load/k6-loadgen/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ type ExperimentDetails struct {
1818
LIBImage string
1919
ScriptSecretName string
2020
ScriptSecretKey string
21+
OTELMetricPrefix string
2122
}

0 commit comments

Comments
 (0)