-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-logs.js
53 lines (46 loc) · 1.48 KB
/
test-logs.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
import generator from 'k6/x/opentelemetry';
import {
Writer,
SchemaRegistry,
SCHEMA_TYPE_BYTES,
} from 'k6/x/kafka';
import {
randomItem,
randomIntBetween,
} from 'https://jslib.k6.io/k6-utils/1.4.0/index.js';
const brokers = ["localhost:9092"]
const topic = "otel_logs"
const schemaRegistry = new SchemaRegistry();
const producer = new Writer({
brokers: brokers,
topic: topic,
});
const logBodies = [
"this is a log msg",
"this is another log msg"
]
export default function () {
var messages = []
const resourceAttributes = new Map()
resourceAttributes.set("pod", "test-abc")
resourceAttributes.set("instance", 1)
resourceAttributes.set("something", 1.23)
resourceAttributes.set("isProd", true)
// optionally set static attributes for the resource
generator.setStaticResourceAttributes(resourceAttributes)
for (let idx = 0; idx < 10; idx++) {
messages[idx] = {
value: schemaRegistry.serialize({
data: Array.from(generator.exportLogsServiceRequest({
// "attributes": logAttributes, // optionally create log specific attribute map
"data": {
"body": randomItem(logBodies),
"severity": randomIntBetween(0, 24) // severity numbers from 0 to 24
},
})),
schemaType: SCHEMA_TYPE_BYTES,
})
}
}
producer.produce({ messages: messages })
}