Skip to content

Commit

Permalink
feat: export k6 results output to the OTEL collector (#726)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent c7ab5a3 commit 9b29558
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 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: 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-",
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
2 changes: 1 addition & 1 deletion pkg/load/k6-loadgen/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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_")
}
1 change: 1 addition & 0 deletions pkg/load/k6-loadgen/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ type ExperimentDetails struct {
LIBImage string
ScriptSecretName string
ScriptSecretKey string
OTELMetricPrefix string
}

0 comments on commit 9b29558

Please sign in to comment.