Skip to content

Commit dafd7f8

Browse files
committed
docker-compose: add the opentelemetry output example
1 parent 48f44d1 commit dafd7f8

File tree

7 files changed

+2217
-0
lines changed

7 files changed

+2217
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# OpenTelemetry Output
2+
3+
This example demonstrates how to integrate k6 performance testing with OpenTelemetry. The test metrics are sent to an OpenTelemetry collector (OTEL Collector), which forwards them to Prometheus for storage. These metrics can then be visualized using Grafana dashboards.
4+
5+
## Prerequisites
6+
7+
- Docker
8+
- Docker Compose
9+
10+
## Run the example
11+
12+
```bash
13+
docker-compose up -d
14+
```
15+
16+
## Access the k6 performance test dashboard
17+
18+
Open the k6 performance test dashboard in your browser http://localhost:3000/d/demo-uid/k6-opentelemetry-prometheus
19+
20+
## Run the k6 test
21+
22+
This will run the test for 3 minutes with 10 virtual users and send the metrics to the OTEL Collector.
23+
24+
```bash
25+
K6_OTEL_GRPC_EXPORTER_ENDPOINT=localhost:4317 \
26+
K6_OTEL_GRPC_EXPORTER_INSECURE=true \
27+
K6_OTEL_METRIC_PREFIX=k6_ \
28+
k6 run --tag testid=1 -o experimental-opentelemetry script.js
29+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
version: '3.8'
2+
3+
networks:
4+
k6:
5+
6+
services:
7+
prometheus:
8+
image: prom/prometheus:v3.2.0
9+
command:
10+
- --web.enable-remote-write-receiver
11+
- --enable-feature=native-histograms
12+
- --config.file=/etc/prometheus/prometheus.yml
13+
networks:
14+
- k6
15+
ports:
16+
- "9090:9090"
17+
18+
alloy:
19+
image: grafana/alloy:v1.6.1
20+
networks:
21+
- k6
22+
volumes:
23+
- ./grafana/alloy:/etc/alloy
24+
environment:
25+
REMOTE_WRITE_HOST: prometheus:9090
26+
depends_on:
27+
- prometheus
28+
command:
29+
- run
30+
- /etc/alloy/config.alloy
31+
- --storage.path=/var/lib/alloy/data
32+
- --server.http.listen-addr=0.0.0.0:12345
33+
- --stability.level=experimental # Enable all functionality
34+
ports:
35+
- "12345:12345" # Alloy UI
36+
- "4317:4317" # gRPC receiver
37+
- "4318:4318" # HTTP receiver
38+
39+
grafana:
40+
image: grafana/grafana:11.5.2
41+
networks:
42+
- k6
43+
ports:
44+
- "3000:3000"
45+
environment:
46+
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
47+
- GF_AUTH_ANONYMOUS_ENABLED=true
48+
- GF_AUTH_BASIC_ENABLED=false
49+
volumes:
50+
- ./grafana:/etc/grafana/provisioning/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// expose OTEL receivers
2+
// https://grafana.com/docs/alloy/latest/reference/components/otelcol.receiver.otlp/
3+
otelcol.receiver.otlp "default" {
4+
// configures the default gRPC receiver endpoint "0.0.0.0:4317"
5+
// https://grafana.com/docs/alloy/latest/reference/components/otelcol.receiver.otlp/#grpc-block
6+
grpc {}
7+
8+
// configures the default HTTP receiver endpoint "0.0.0.0:4318"
9+
// https://grafana.com/docs/alloy/latest/reference/components/otelcol.receiver.otlp/#http-block
10+
http {}
11+
12+
output {
13+
metrics = [otelcol.processor.batch.default.input]
14+
}
15+
}
16+
17+
otelcol.processor.batch "default" {
18+
// https://grafana.com/docs/alloy/latest/reference/components/otelcol.processor.batch/
19+
output {
20+
metrics = [otelcol.exporter.prometheus.default.input]
21+
}
22+
}
23+
24+
otelcol.exporter.prometheus "default" {
25+
add_metric_suffixes = false
26+
forward_to = [prometheus.remote_write.default.receiver]
27+
}
28+
29+
// Collect metrics from the local running Alloy instance and forward to
30+
// Prometheus.
31+
prometheus.exporter.self "alloy" {}
32+
prometheus.scrape "alloy" {
33+
targets = prometheus.exporter.self.alloy.targets
34+
forward_to = [prometheus.remote_write.default.receiver]
35+
}
36+
37+
prometheus.remote_write "default" {
38+
endpoint {
39+
url = format(
40+
"http://%s/api/v1/write",
41+
coalesce(env("REMOTE_WRITE_HOST"), "localhost:9090"),
42+
)
43+
}
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# For configuration options, see
2+
# https://grafana.com/docs/grafana/latest/administration/provisioning/#dashboards
3+
4+
apiVersion: 1
5+
6+
providers:
7+
# We're defining a directory from which to load file-based dashboards
8+
- name: 'prometheus'
9+
type: file
10+
disableDeletion: false
11+
updateIntervalSeconds: 10
12+
editable: true
13+
options:
14+
path: /etc/grafana/provisioning/dashboards

0 commit comments

Comments
 (0)