-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlocustfile.py
46 lines (38 loc) · 1.55 KB
/
locustfile.py
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
import base64
import random
import time
import json
from locust import FastHttpUser, task
# Convert current time to epoch microseconds
current_time_microseconds = int(time.time() * 1e6)
# Subtract 1 week in microseconds
one_week_microseconds = 7 * 24 * 60 * 60 * 1_000_000
start_time = current_time_microseconds - one_week_microseconds
end_time = current_time_microseconds
# Load queries from JSON file
with open('data/queries.json', 'r') as f:
queries = json.load(f)["queries"]
class ZincUser(FastHttpUser):
connection_timeout = 600.0
network_timeout = 600.0
host = "http://zo1-openobserve-router.perfb.svc.cluster.local:5080/api/default"
user = "[email protected]"
password = "Complexpass@800"
bas64encoded_creds = base64.b64encode(bytes(f"{user}:{password}", "utf-8")).decode("utf-8")
headers = {
'Authorization': 'Basic ' + bas64encoded_creds,
'Content-Type': 'application/json'
}
@task
def run_queries(self):
for index, query in enumerate(queries):
if index == 2:
break
# Replace placeholders with actual times
# query['start_time'] = start_time
# query['end_time'] = end_time
# user fixed start and end time
# 2024-09-26T00:00:00Z - 2024-09-26T00:05:00Z
query['start_time'] = 1727308800000000
query['end_time'] = 1727309100000000
self.client.post("/_search?type=logs&use_cache=true", name=f"/query/{query['name']}", json={"query": query}, headers=self.headers)