-
Notifications
You must be signed in to change notification settings - Fork 2
/
test-metrics.js
72 lines (63 loc) · 2.05 KB
/
test-metrics.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
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_metrics"
const schemaRegistry = new SchemaRegistry();
const producer = new Writer({
brokers: brokers,
topic: topic,
});
const metricNames = [
"metric1",
"metric2"
]
const metricAttributes = new Map()
metricAttributes.set("operation", "create")
export default function () {
var messages = []
const resourceAttributes = new Map()
resourceAttributes.set("pod", "test-abc")
// optionally set static attributes for the resource
generator.setStaticResourceAttributes(resourceAttributes)
for (let idx = 0; idx < 5; idx++) {
messages[idx] = {
value: schemaRegistry.serialize({
data: Array.from(generator.exportMetricsServiceRequest({
"type": "gauge",
"name": "gauge_" + randomItem(metricNames),
"attributes": metricAttributes,
"data": {
"value": randomIntBetween(10, 100)
},
})),
schemaType: SCHEMA_TYPE_BYTES,
})
}
}
for (let idx = 0; idx < 5; idx++) {
messages[idx] = {
value: schemaRegistry.serialize({
data: Array.from(generator.exportMetricsServiceRequest({
"type": "sum",
"name": "sum_" + randomItem(metricNames),
"attributes": metricAttributes,
"data": {
"value": randomIntBetween(10, 100),
"isMonotonic": false, // true or false
"aggregationTemporality": "delta" // delta or cumulative
},
})),
schemaType: SCHEMA_TYPE_BYTES,
})
}
}
producer.produce({ messages: messages })
}