1
1
import { sleep } from 'k6' ;
2
2
import tracing from 'k6/x/tracing' ;
3
+ import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js' ;
3
4
4
5
export const options = {
5
6
vus : 1 ,
6
- duration : "5m " ,
7
+ duration : "20m " ,
7
8
} ;
8
9
10
+ const endpoint = __ENV . ENDPOINT || "otel-collector:4317"
9
11
const client = new tracing . Client ( {
10
- endpoint : "otel-collector:4317" ,
12
+ endpoint,
11
13
exporter : tracing . EXPORTER_OTLP ,
12
14
insecure : true ,
13
15
} ) ;
@@ -26,11 +28,28 @@ const traceTemplates = [
26
28
{ service : "shop-backend" , name : "authenticate" , duration : { min : 50 , max : 100 } } ,
27
29
{ service : "auth-service" , name : "authenticate" } ,
28
30
{ service : "shop-backend" , name : "fetch-articles" , parentIdx : 0 } ,
29
- { service : "article-service" , name : "get -articles" } ,
31
+ { service : "article-service" , name : "list -articles" } ,
30
32
{ service : "article-service" , name : "select-articles" , attributeSemantics : tracing . SEMANTICS_DB } ,
31
33
{ service : "postgres" , name : "query-articles" , attributeSemantics : tracing . SEMANTICS_DB , randomAttributes : { count : 5 } } ,
32
34
]
33
35
} ,
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
+ } ,
34
53
{
35
54
defaults : traceDefaults ,
36
55
spans : [
@@ -42,13 +61,11 @@ const traceTemplates = [
42
61
]
43
62
44
63
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 ( ) )
50
67
51
- sleep ( 5 ) ;
68
+ sleep ( randomIntBetween ( 1 , 5 ) ) ;
52
69
}
53
70
54
71
export function teardown ( ) {
0 commit comments