Skip to content

Commit af84d3f

Browse files
authored
Publish docker image to be used in tempo examples (#7)
Publish a xk6-client-tracing docker image that runs k6 to generate traces and send them to a OTLP or Jaeger endpoints * Make endpoints in examples configurable * Add example script to docker image * GitHub action to build and publish the image when a new release is created
1 parent fd8ecd7 commit af84d3f

File tree

9 files changed

+80
-17
lines changed

9 files changed

+80
-17
lines changed

.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
/examples
1+
/examples/**/*.yml
2+
/examples/**/*.yaml
23
*.md
34
Dockerfile

.github/workflows/lint-test.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Lint and Test
22

3-
on: [push]
3+
on: pull_request
44

55
jobs:
66
lint-and-test:
@@ -12,7 +12,7 @@ jobs:
1212
- name: Set-up Go
1313
uses: actions/setup-go@v3
1414
with:
15-
go-version: ^1.18
15+
go-version: ^1.19
1616
cache: true
1717

1818
- name: Lint
@@ -22,4 +22,4 @@ jobs:
2222
args: --config ./golangci.yml
2323

2424
- name: Test
25-
run: make test
25+
run: make test

.github/workflows/release.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- name: Set-up Go
15+
uses: actions/setup-go@v3
16+
with:
17+
go-version: ^1.19
18+
cache: true
19+
20+
- name: Test
21+
run: make test
22+
23+
- name: Docker set up buildx
24+
uses: docker/setup-buildx-action@v2
25+
26+
- name: Docker login
27+
uses: docker/login-action@v2
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Docker build and push
34+
uses: docker/build-push-action@v3
35+
with:
36+
context: .
37+
file: Dockerfile
38+
push: true
39+
tags: ghcr.io/grafana/xk6-client-tracing:latest,ghcr.io/grafana/xk6-client-tracing:${{ github.event.release.tag_name }}

Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:alpine AS xk6-client-tracing-build
1+
FROM golang:1.19-alpine AS xk6-client-tracing-build
22

33
RUN apk add --no-cache \
44
build-base \
@@ -20,4 +20,7 @@ RUN make build
2020
FROM alpine:latest
2121

2222
COPY --from=xk6-client-tracing-build /opt/xk6-client-tracing/k6-tracing /k6-tracing
23+
COPY ./examples/template/template.js /example-script.js
24+
2325
ENTRYPOINT [ "/k6-tracing" ]
26+
CMD ["run", "/example-script.js"]

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
BINARY ?= k6-tracing
2-
IMAGE ?= grafana/xk6-client-tracing
2+
IMAGE ?= ghcr.io/grafana/xk6-client-tracing
33
IMAGE_TAG ?= latest
44

55
GO_MODULE := $(shell head -n1 go.mod | cut -d' ' -f2)

examples/param/docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
- ./param.js:/param.js:ro
1111
depends_on:
1212
- otel-collector
13+
restart: always
1314

1415
otel-collector:
1516
image: otel/opentelemetry-collector:latest

examples/param/param.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
44

55
export let options = {
66
vus: 1,
7-
duration: "5m",
7+
duration: "20m",
88
};
99

10+
const endpoint = __ENV.ENDPOINT || "otel-collector:4317"
1011
const client = new tracing.Client({
11-
endpoint: "otel-collector:4317",
12+
endpoint,
1213
exporter: tracing.EXPORTER_OTLP,
1314
insecure: true,
1415
});

examples/template/docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ services:
1010
- ./template.js:/template.js:ro
1111
depends_on:
1212
- otel-collector
13+
restart: always
1314

1415
otel-collector:
1516
image: otel/opentelemetry-collector:latest

examples/template/template.js

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import {sleep} from 'k6';
22
import tracing from 'k6/x/tracing';
3+
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
34

45
export const options = {
56
vus: 1,
6-
duration: "5m",
7+
duration: "20m",
78
};
89

10+
const endpoint = __ENV.ENDPOINT || "otel-collector:4317"
911
const client = new tracing.Client({
10-
endpoint: "otel-collector:4317",
12+
endpoint,
1113
exporter: tracing.EXPORTER_OTLP,
1214
insecure: true,
1315
});
@@ -26,11 +28,28 @@ const traceTemplates = [
2628
{service: "shop-backend", name: "authenticate", duration: {min: 50, max: 100}},
2729
{service: "auth-service", name: "authenticate"},
2830
{service: "shop-backend", name: "fetch-articles", parentIdx: 0},
29-
{service: "article-service", name: "get-articles"},
31+
{service: "article-service", name: "list-articles"},
3032
{service: "article-service", name: "select-articles", attributeSemantics: tracing.SEMANTICS_DB},
3133
{service: "postgres", name: "query-articles", attributeSemantics: tracing.SEMANTICS_DB, randomAttributes: {count: 5}},
3234
]
3335
},
36+
{
37+
defaults: {
38+
attributeSemantics: tracing.SEMANTICS_HTTP,
39+
},
40+
spans: [
41+
{service: "shop-backend", name: "article-to-cart", duration: {min: 400, max: 1200}},
42+
{service: "shop-backend", name: "authenticate", duration: {min: 70, max: 200}},
43+
{service: "auth-service", name: "authenticate"},
44+
{service: "shop-backend", name: "get-article", parentIdx: 0},
45+
{service: "article-service", name: "get-article"},
46+
{service: "article-service", name: "select-articles", attributeSemantics: tracing.SEMANTICS_DB},
47+
{service: "postgres", name: "query-articles", attributeSemantics: tracing.SEMANTICS_DB, randomAttributes: {count: 2}},
48+
{service: "shop-backend", name: "place-articles", parentIdx: 0},
49+
{service: "cart-service", name: "place-articles", attributes: {"article.count": 1, "http.status_code": 201}},
50+
{service: "cart-service", name: "persist-cart"}
51+
]
52+
},
3453
{
3554
defaults: traceDefaults,
3655
spans: [
@@ -42,13 +61,11 @@ const traceTemplates = [
4261
]
4362

4463
export default function () {
45-
traceTemplates.forEach(function (tmpl) {
46-
let gen = new tracing.TemplatedGenerator(tmpl)
47-
let traces = gen.traces()
48-
client.push(traces)
49-
});
64+
const templateIndex = randomIntBetween(0, traceTemplates.length-1)
65+
const gen = new tracing.TemplatedGenerator(traceTemplates[templateIndex])
66+
client.push(gen.traces())
5067

51-
sleep(5);
68+
sleep(randomIntBetween(1, 5));
5269
}
5370

5471
export function teardown() {

0 commit comments

Comments
 (0)