Skip to content

Commit

Permalink
Refactor templated event and link generation (#28)
Browse files Browse the repository at this point in the history
* Consistent naming for internal event and link templates

* Initialize link attribute values during initialization

* Rename EventParam.Rate and remove unused generateExceptionOnError:

* Initialize event attribute values during initialization

* Update example template.js

* Upgrade Go and golangci-lint versions

* Change package name to clienttracing
  • Loading branch information
stoewer authored May 29, 2024
1 parent 1f223eb commit c088e8e
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 237 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
- name: Set-up Go
uses: actions/setup-go@v3
with:
go-version: ^1.21
go-version: ^1.22
cache: true

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
version: v1.59.0
args: --config ./golangci.yml

- name: Test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set-up Go
uses: actions/setup-go@v3
with:
go-version: ^1.19
go-version: ^1.22
cache: true

- name: Test
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21-alpine AS xk6-client-tracing-build
FROM golang:1.22-alpine AS xk6-client-tracing-build

RUN apk add --no-cache \
build-base \
Expand All @@ -7,7 +7,7 @@ RUN apk add --no-cache \
make

RUN go install go.k6.io/xk6/cmd/xk6@latest \
&& wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.50.0 \
&& wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.59.0 \
&& golangci-lint --version

WORKDIR /opt/xk6-client-tracing
Expand Down
37 changes: 27 additions & 10 deletions examples/template/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const client = new tracing.Client({
endpoint,
exporter: tracing.EXPORTER_OTLP,
tls: {
insecure: true,
insecure: true,
},
headers: {
"X-Scope-Orgid": orgid
Expand All @@ -24,8 +24,7 @@ const traceDefaults = {
attributeSemantics: tracing.SEMANTICS_HTTP,
attributes: {"one": "three"},
randomAttributes: {count: 2, cardinality: 5},
randomEvents: {generateExceptionOnError: true, rate: 1.0, randomAttributes: {count: 2, cardinality: 3}},
randomLinks: {rate: 1.0, randomAttributes: {count: 2, cardinality: 3}},
randomEvents: {count: 0.1, exceptionCount: 0.2, randomAttributes: {count: 6, cardinality: 20}},
}

const traceTemplates = [
Expand All @@ -36,7 +35,11 @@ const traceTemplates = [
{service: "shop-backend", name: "authenticate", duration: {min: 50, max: 100}},
{service: "auth-service", name: "authenticate"},
{service: "shop-backend", name: "fetch-articles", parentIdx: 0},
{service: "article-service", name: "list-articles"},
{
service: "article-service",
name: "list-articles",
links: [{attributes: {"link-type": "parent-child"}, randomAttributes: {count: 2, cardinality: 5}}]
},
{service: "article-service", name: "select-articles", attributeSemantics: tracing.SEMANTICS_DB},
{service: "postgres", name: "query-articles", attributeSemantics: tracing.SEMANTICS_DB, randomAttributes: {count: 5}},
]
Expand All @@ -45,6 +48,7 @@ const traceTemplates = [
defaults: {
attributes: {"numbers": ["one", "two", "three"]},
attributeSemantics: tracing.SEMANTICS_HTTP,
randomEvents: {count: 2, randomAttributes: {count: 3, cardinality: 10}},
},
spans: [
{service: "shop-backend", name: "article-to-cart", duration: {min: 400, max: 1200}},
Expand All @@ -64,17 +68,30 @@ const traceTemplates = [
spans: [
{service: "shop-backend", attributes: {"http.status_code": 403}},
{service: "shop-backend", name: "authenticate", attributes: {"http.request.header.accept": ["application/json"]}},
{service: "auth-service", name: "authenticate", attributes: {"http.status_code": 403}},
{
service: "auth-service",
name: "authenticate",
attributes: {"http.status_code": 403},
randomEvents: {count: 0.5, exceptionCount: 2, randomAttributes: {count: 5, cardinality: 5}}
},
]
},
{
defaults: traceDefaults,
spans: [
{service: "shop-backend", attributes: {"http.status_code": 403}},
{service: "shop-backend"},
{service: "shop-backend", name: "authenticate", attributes: {"http.request.header.accept": ["application/json"]}},
{service: "auth-service", name: "authenticate", attributes: {"http.status_code": 403}},
{service: "cart-service", name: "checkout", randomEvents: {exceptionRate: 1, rate: 2, randomAttributes: {count: 5, cardinality: 2}}},
{service: "billing-service", name: "payment", randomLinks: {rate: 2, randomAttributes: {count: 3, cardinality: 2}}}
{service: "auth-service", name: "authenticate"},
{
service: "cart-service",
name: "checkout",
randomEvents: {count: 0.5, exceptionCount: 2, exceptionOnError: true, randomAttributes: {count: 5, cardinality: 5}}
},
{
service: "billing-service",
name: "payment",
randomLinks: {count: 0.5, randomAttributes: {count: 3, cardinality: 10}},
randomEvents: {exceptionOnError: true, randomAttributes: {count: 4}}}
]
},
]
Expand All @@ -89,4 +106,4 @@ export default function () {

export function teardown() {
client.shutdown();
}
}
8 changes: 8 additions & 0 deletions pkg/random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func init() {
rnd = rand.New(rand.NewSource(seed.Int64()))
}

func Rand() *rand.Rand {
return rnd
}

func SelectElement[T any](elements []T) T {
return elements[rnd.Intn(len(elements))]
}
Expand Down Expand Up @@ -121,3 +125,7 @@ func SpanID() pcommon.SpanID {
_, _ = rnd.Read(b[:]) // always returns nil error
return b
}

func EventName() string {
return "event_k6." + String(10)
}
Loading

0 comments on commit c088e8e

Please sign in to comment.