Skip to content

Commit acf09c9

Browse files
fix script to generate desired load (#115)
1 parent cf0ff41 commit acf09c9

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

scripts/load_batch_events_otel_traces.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ import encoding from 'k6/encoding';
33
import { check } from 'k6';
44

55
// config for load test, uncomment to perform load test for an hour
6-
// export const options = {
7-
// discardResponseBodies: true,
8-
// // Key configurations for avg load test in this section
9-
// stages: [
10-
// { duration: '5m', target: 10 },
11-
// { duration: '60m', target: 8 },
12-
// { duration: '5m', target: 0 },
13-
// ],
14-
// };
15-
16-
// default options for all tests
176
export const options = {
187
discardResponseBodies: true,
19-
scenarios: {
20-
contacts: {
21-
executor: 'constant-vus',
22-
vus: 10,
23-
duration: "5m",
24-
},
25-
},
8+
// Key configurations for avg load test in this section
9+
stages: [
10+
{ duration: '5m', target: 10 },
11+
{ duration: '60m', target: 8 },
12+
{ duration: '5m', target: 0 },
13+
],
2614
};
2715

16+
// default options for all tests
17+
// export const options = {
18+
// discardResponseBodies: true,
19+
// scenarios: {
20+
// contacts: {
21+
// executor: 'constant-vus',
22+
// vus: 10,
23+
// duration: "5m",
24+
// },
25+
// },
26+
// };
27+
2828
function randomIntBetween(min, max) {
2929
return Math.floor(Math.random() * (max - min + 1)) + min;
3030
}
@@ -102,7 +102,7 @@ function random_availability_zone() {
102102
}
103103

104104

105-
function generateTraceRecord(overrides = {}) {
105+
function generateTraceRecord() {
106106
const method = randomHttpMethod();
107107
const endpoint = randomApiEndpoint();
108108
const statusCode = randomStatusCode();
@@ -115,7 +115,7 @@ function generateTraceRecord(overrides = {}) {
115115
const eventTime = now.toISOString(); // now
116116
const eventName = randomEventName();
117117
const availability_zone = random_availability_zone();
118-
return Object.assign({
118+
return {
119119
"cloud.account.id": "724973952305",
120120
"cloud.availability_zone": availability_zone,
121121
"cloud.platform": "aws_ec2",
@@ -148,9 +148,17 @@ function generateTraceRecord(overrides = {}) {
148148
"telemetry.sdk.version": "2.0.1",
149149
"event_time_unix_nano": eventTime,
150150
"event_name": eventName
151-
}, overrides);
151+
};
152152
}
153153

154+
// Generate a batch of OTEL traces
155+
function generateOtelTraces(count) {
156+
const traces = [];
157+
for (let i = 0; i < count; i++) {
158+
traces.push(generateTraceRecord());
159+
}
160+
return traces;
161+
}
154162

155163
function eventsPerCall() {
156164
return Number(__ENV.P_EVENTS_COUNT) || 100;
@@ -173,7 +181,7 @@ export default function () {
173181
};
174182

175183
let events = eventsPerCall();
176-
let batchRequests = JSON.stringify(generateTraceRecord(events));
184+
let batchRequests = JSON.stringify(generateOtelTraces(events));
177185
let response = http.post(url, batchRequests, params);
178186
let date = new Date();
179187

0 commit comments

Comments
 (0)