Skip to content

Commit b7dc63b

Browse files
authored
Add two load scripts (#28)
Batched events per HTTP call and single event per call.
1 parent 08b1cb3 commit b7dc63b

File tree

3 files changed

+177
-3
lines changed

3 files changed

+177
-3
lines changed

testcases/load.js renamed to testcases/load_batch_events.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ export default function () {
168168
}
169169
}
170170

171-
let batch_requests = JSON.stringify(generateEvents(30));
172-
171+
let batch_requests = JSON.stringify(generateEvents(10));
173172
let response = http.post(url, batch_requests, params);
174173

175174
if (

testcases/load_single_event.js

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
import http from 'k6/http';
2+
import { check, sleep } from 'k6';
3+
import encoding from 'k6/encoding';
4+
import { randomString, randomItem, randomIntBetween, uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js'
5+
6+
export const options = {
7+
discardResponseBodies: true,
8+
scenarios: {
9+
contacts: {
10+
executor: 'constant-vus',
11+
vus: 10,
12+
},
13+
},
14+
};
15+
16+
function current_time() {
17+
let event = new Date();
18+
return event.toISOString();
19+
}
20+
21+
function schemas() {
22+
return Number(__ENV.P_SCHEMA_COUNT)
23+
}
24+
25+
const common_schema = [
26+
{ "name": "source_time", "gen": current_time, "arg": null },
27+
{ "name": "level", "gen": randomItem, "arg": ["info", "warn", "error"] },
28+
{ "name": "message", "gen": randomItem, "arg": ["Application started", "Application is failing", "Logging a request"] },
29+
{ "name": "version", "gen": randomItem, "arg": ["1.0.0", "1.1.0", "1.2.0"] },
30+
{ "name": "user_id", "gen": randomIntBetween, "arg": [10000, 100000] },
31+
{ "name": "device_id", "gen": randomIntBetween, "arg": [0, 5000] },
32+
{ "name": "session_id", "gen": randomItem, "arg": ["abc", "pqr", "xyz"] },
33+
{ "name": "os", "gen": randomItem, "arg": ["macOS", "Linux", "Windows"] },
34+
{ "name": "host", "gen": randomItem, "arg": ["192.168.1.100", "112.168.1.110", "172.162.1.120"] },
35+
{ "name": "uuid", "gen": uuidv4, "arg": null },
36+
]
37+
38+
const add_fields = {
39+
"location": { "gen": randomString, "arg": 16 },
40+
"timezone": { "gen": randomString, "arg": 3 },
41+
"user_agent": { "gen": randomItem, "arg": ["Banana", "PineApple", "PearOS", "OrangeOS", "Kiwi"] },
42+
"runtime": { "gen": randomString, "arg": 3 },
43+
"request_body": { "gen": randomString, "arg": 100 },
44+
"status_code": { "gen": randomItem, "arg": [200, 300, 400, 500] },
45+
"response_time": { "gen": randomItem, "arg": [12, 22, 34, 56, 70, 112] },
46+
"process_id": { "gen": randomIntBetween, "arg": [100, 1000] },
47+
"app_meta": { "gen": randomString, "arg": 24 }
48+
}
49+
50+
const addFields_permutation = [
51+
['location', 'request_body', 'status_code', 'app_meta'],
52+
['timezone', 'user_agent', 'runtime', 'app_meta'],
53+
['timezone', 'request_body', 'response_time', 'process_id'],
54+
['timezone', 'user_agent', 'request_body', 'process_id'],
55+
['runtime', 'status_code', 'response_time', 'process_id'],
56+
['location', 'user_agent', 'runtime', 'process_id'],
57+
['location', 'timezone', 'request_body', 'response_time'],
58+
['timezone', 'user_agent', 'status_code', 'process_id'],
59+
['timezone', 'runtime', 'request_body', 'response_time'],
60+
['timezone', 'status_code', 'response_time', 'process_id'],
61+
['timezone', 'runtime', 'status_code', 'response_time'],
62+
['location', 'timezone', 'response_time', 'process_id'],
63+
['location', 'timezone', 'runtime', 'process_id'],
64+
['user_agent', 'runtime', 'status_code', 'process_id'],
65+
['timezone', 'response_time', 'process_id', 'app_meta'],
66+
['location', 'user_agent', 'status_code', 'response_time'],
67+
['timezone', 'user_agent', 'runtime', 'status_code'],
68+
['request_body', 'status_code', 'process_id', 'app_meta'],
69+
['location', 'user_agent', 'runtime', 'request_body'],
70+
['location', 'timezone', 'status_code', 'response_time'],
71+
['location', 'user_agent', 'response_time', 'process_id'],
72+
['timezone', 'runtime', 'response_time', 'process_id'],
73+
['location', 'timezone', 'user_agent', 'runtime'],
74+
['user_agent', 'request_body', 'status_code', 'process_id'],
75+
['runtime', 'request_body', 'response_time', 'process_id'],
76+
['location', 'runtime', 'request_body', 'app_meta'],
77+
['runtime', 'response_time', 'process_id', 'app_meta'],
78+
['location', 'runtime', 'status_code', 'app_meta'],
79+
['location', 'runtime', 'process_id', 'app_meta'],
80+
['location', 'request_body', 'process_id', 'app_meta'],
81+
['location', 'timezone', 'runtime', 'request_body'],
82+
['timezone', 'user_agent', 'response_time', 'app_meta'],
83+
['runtime', 'request_body', 'status_code', 'response_time'],
84+
['location', 'timezone', 'user_agent', 'response_time'],
85+
['location', 'runtime', 'request_body', 'status_code'],
86+
['location', 'user_agent', 'request_body', 'response_time'],
87+
['location', 'status_code', 'process_id', 'app_meta'],
88+
['user_agent', 'status_code', 'response_time', 'app_meta'],
89+
['timezone', 'request_body', 'status_code', 'response_time'],
90+
['user_agent', 'runtime', 'request_body', 'process_id'],
91+
['user_agent', 'runtime', 'response_time', 'app_meta'],
92+
['user_agent', 'request_body', 'response_time', 'app_meta']
93+
];
94+
95+
function generateOverlappingSchemas(number = 5) {
96+
const schemas = [];
97+
addFields_permutation.slice(0, number).forEach((listOfFields) => {
98+
const new_schema = [...common_schema];
99+
listOfFields.forEach((field) => {
100+
let gen_value = add_fields[field];
101+
let obj = { "name": field };
102+
Object.assign(obj, gen_value);
103+
new_schema.push(obj)
104+
})
105+
schemas.push(new_schema)
106+
})
107+
108+
return schemas;
109+
}
110+
111+
function generateJSON(schema) {
112+
let json = {};
113+
schema.forEach(item => {
114+
let { name, gen, arg } = item;
115+
var value;
116+
if ((gen === current_time) || (gen === uuidv4)) {
117+
value = gen();
118+
}
119+
else if (gen === randomIntBetween) {
120+
value = gen(...arg);
121+
}
122+
else {
123+
value = gen(arg)
124+
}
125+
json[name] = value;
126+
});
127+
return JSON.stringify(json);
128+
}
129+
130+
function generateEvents(numberOfEvents = 3) {
131+
const events = [];
132+
let numberOfSchemas = schemas();
133+
134+
if (!numberOfSchemas) {
135+
numberOfSchemas = 5
136+
}
137+
138+
let listOfSchema = generateOverlappingSchemas(numberOfSchemas);
139+
140+
for (let i = 0; i < numberOfEvents; i++) {
141+
for (let j = 0; j < listOfSchema.length; j++) {
142+
events.push(generateJSON(listOfSchema[j]))
143+
}
144+
}
145+
146+
return events
147+
}
148+
149+
export default function () {
150+
sleep(0.1);
151+
const url = `${__ENV.P_URL}/api/v1/ingest`;
152+
const credentials = `${__ENV.P_USERNAME}:${__ENV.P_PASSWORD}`;
153+
const encodedCredentials = encoding.b64encode(credentials);
154+
155+
const params = {
156+
headers: {
157+
'Content-Type': 'application/json',
158+
'Authorization': 'Basic '+`${encodedCredentials}`,
159+
'X-P-STREAM': `${__ENV.P_STREAM}`,
160+
'X-P-META-Host': '10.116.0.3',
161+
'X-P-META-Source': 'quest-test',
162+
'X-P-META-ContainerName': 'log-generator',
163+
'X-P-META-ContainerImage': 'ghcr.io/parseablehq/quest',
164+
'X-P-META-Namespace': 'go-apasdp',
165+
'X-P-META-PodLabels': 'app=go-app,pod-template-hash=6c87bc9cc9',
166+
}
167+
}
168+
169+
let batch_requests = generateEvents(1).map(event => ['POST', url, event, params]);
170+
http.batch(batch_requests);
171+
}

testcases/load_test.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ delete_stream () {
8383
}
8484

8585
run_k6() {
86-
k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/testcases/load.js" --vus="$vus" --duration="$duration"
86+
printf "K6 script with 100 batched log events per HTTP Call"
87+
k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/testcases/load_batch_events.js" --vus="$vus" --duration="$duration"
88+
89+
printf "K6 script with 1 event per HTTP Call"
90+
k6 run -e P_URL="$parseable_url" -e P_STREAM="$stream_name" -e P_USERNAME="$username" -e P_PASSWORD="$password" -e P_SCHEMA_COUNT="$count" "/tests/testcases/load_single_event.js" --vus="$vus" --duration="$duration"
8791
}
8892

8993
printf "======= Starting load tests with k6 =======\n"

0 commit comments

Comments
 (0)