Quantcast
Channel: Grafana k6 - Grafana Labs Community Forums
Viewing all articles
Browse latest Browse all 350

How to configure extension xk6-Prometheus for distributed testing

$
0
0

We would like to use the xk6-Prometheus extension to make test metrics available for Prometheus.

k6 is being used for distributed testing with TestRun CRD. So far, it hasn’t been possible to provide the generated metrics through TestRun CRD via the extension (pls find config below).

Environment
Extension xk6-prometheus: GitHub - szkiba/xk6-prometheus: Prometheus HTTP exporter for k6
kube-prometheus-stack: Version 61.1.0

Question
Is there a guide on how to use or configure the extension in conjunction with TestRun CRD?

Configurations
Here, I’d like to share my configurations:

Dockerfile - Image creation with the xk6-Prometheus extension

FROM grafana/xk6:0.11.0 as builder

# Build k6 with extensions
RUN xk6 build \
    --with github.com/szkiba/xk6-prometheus@latest \
    && cp k6 $GOPATH/bin/k6

# Use Alpine as the final image
FROM alpine:3.13

# Install CA certificates and create a non-root user
RUN apk add --no-cache ca-certificates && \
    adduser -D -u 12345 -g 12345 k6

# Copy the k6 binary from the builder stage
COPY --from=builder /go/bin/k6 /usr/bin/k6

# Set the user to run the container
USER 12345

# Set the entrypoint to k6
ENTRYPOINT ["k6"]

TestRund CRD - Prometheus HTTP exporter will accessible on port 5656 (default)

apiVersion: k6.io/v1alpha1
kind: TestRun
metadata:
  name: k6-test-run
  namespace: testing
  labels:
    app: k6-test-run
    release: kube-prometheus-stack
spec:
  parallelism: 1
  script:
    configMap:
      name: k6-config-map
      file: script.js
  arguments: -o prometheus
  ports:
    - name: prometheus
      containerPort: 5656
  runner:
    image: k6-extensions:1.0.1
    env:
      - name: K6_OUT
        value: prometheus

ServiceMonitor CRD (Prometheus)

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: k6-prometheus-monitor
  namespace: monitoring
  labels:
    app: kube-prometheus-stack
    release: kube-prometheus-stack
spec:
  endpoints:
    - port: prometheus
      path: /metrics
      interval: 15s
  namespaceSelector:
    any: true  # or specify the namespace if needed
  selector:
    matchLabels:
      app: k6-test-run
      release: kube-prometheus-stack

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 350

Trending Articles