-
Notifications
You must be signed in to change notification settings - Fork 0
/
qryn-tempo-template.js
108 lines (94 loc) · 4.25 KB
/
qryn-tempo-template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import {sleep, check} from 'k6';
import tracing from 'k6/x/tracing';
import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js';
import { htmlReport, markdownReport } from "https://raw.githubusercontent.com/metrico/k6-reporter/main/dist/bundle.js";
import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js";
import { describe, expect } from 'https://jslib.k6.io/k6chaijs/4.3.4.1/index.js';
import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js';
import http from 'k6/http';
export let options = {
vus: __ENV.K6_VUS || 1,
duration: __ENV.K6_DURATION_MINUTES ? __ENV.K6_DURATION_MINUTES + "m" : "1m",
iterations: __ENV.K6_ITERATIONS || 10,
};
const endpoint = __ENV.K6_TEMPO_ENDPOINT || "http://localhost:3100"
const client = new tracing.Client({
endpoint,
exporter: tracing.EXPORTER_OTLP_HTTP,
insecure: true,
});
const traceDefaults = {
attributeSemantics: tracing.SEMANTICS_HTTP,
attributes: {"one": "three"},
randomAttributes: {count: 2, cardinality: 5}
}
const traceTemplates = [
{
defaults: traceDefaults,
spans: [
{service: "shop-backend", name: "list-articles", duration: {min: 200, max: 900}},
{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: "select-articles", attributeSemantics: tracing.SEMANTICS_DB},
{service: "postgres", name: "query-articles", attributeSemantics: tracing.SEMANTICS_DB, randomAttributes: {count: 5}},
]
},
{
defaults: {
attributeSemantics: tracing.SEMANTICS_HTTP,
},
spans: [
{service: "shop-backend", name: "article-to-cart", duration: {min: 400, max: 1200}},
{service: "shop-backend", name: "authenticate", duration: {min: 70, max: 200}},
{service: "auth-service", name: "authenticate"},
{service: "shop-backend", name: "get-article", parentIdx: 0},
{service: "article-service", name: "get-article"},
{service: "article-service", name: "select-articles", attributeSemantics: tracing.SEMANTICS_DB},
{service: "postgres", name: "query-articles", attributeSemantics: tracing.SEMANTICS_DB, randomAttributes: {count: 2}},
{service: "shop-backend", name: "place-articles", parentIdx: 0},
{service: "cart-service", name: "place-articles", attributes: {"article.count": 1, "http.status_code": 201}},
{service: "cart-service", name: "persist-cart"}
]
},
{
defaults: traceDefaults,
spans: [
{service: "shop-backend", attributes: {"http.status_code": 403}},
{service: "shop-backend", name: "authenticate"},
{service: "auth-service", name: "authenticate", attributes: {"http.status_code": 403}},
]
},
]
export default function () {
const templateIndex = randomIntBetween(0, traceTemplates.length-1)
const gen = new tracing.TemplatedGenerator(traceTemplates[templateIndex])
let t = gen.traces()
let res = client.push(t)
sleep(randomIntBetween(1, 5));
const end = parseInt(Date.now() / 1000);
const start = end - 300;
describe('tempo_query', () => {
const url = new URL(endpoint+"/api/search");
url.searchParams.append('limit', 10);
url.searchParams.append('start', start);
url.searchParams.append('end', end);
url.searchParams.append('tags', 'service.name="shop-backend"');
const res = http.get(url.toString());
expect(res.status, "request status").to.equal(200);
expect(res).to.have.validJsonBody();
expect(res.json().traces.length, "count results "+res.json().traces.length).to.be.greaterThan(0);
});
}
export function teardown() {
client.shutdown();
}
export function handleSummary(data) {
return {
"summary.html": htmlReport(data),
"summary.md": markdownReport(data),
"summary.txt": textSummary(data, { indent: ' ', enableColors: false }),
"stdout": textSummary(data, { indent: ' ', enableColors: true }),
};
}