Skip to content

Commit de6d535

Browse files
[fix] Fixed #78: exported redis-benchmark csv that contains commas is not being properly parsed (#80)
1 parent cca1232 commit de6d535

File tree

5 files changed

+44
-14
lines changed

5 files changed

+44
-14
lines changed

redisbench_admin/run/common.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ def prepare_benchmark_parameters(
112112
entry,
113113
current_workdir,
114114
)
115+
printed_command_str = command_str
116+
printed_command_arr = command_arr
117+
if len(command_str) > 200:
118+
printed_command_str = command_str[:200] + "... (trimmed output) ..."
119+
printed_command_arr = printed_command_arr[:1] + ["(...) trimmed output...."]
115120
logging.info(
116121
"Running the benchmark with the following parameters:\n\tArgs array: {}\n\tArgs str: {}".format(
117-
command_arr, command_str
122+
printed_command_arr, printed_command_str
118123
)
119124
)
120125
return command_arr, command_str

redisbench_admin/run/redis_benchmark/redis_benchmark.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ def redis_benchmark_from_stdout_csv_to_json(
1515
"StartTime": start_time_ms,
1616
"StartTimeHuman": start_time_str,
1717
}
18-
csv_data = list(csv.reader(csv_data.splitlines(), delimiter=","))
19-
header = csv_data[0]
20-
for row in csv_data[1:]:
21-
test_name = row[0]
22-
if overload_test_name is not None:
23-
test_name = overload_test_name
24-
results_dict["Tests"][test_name] = {}
25-
for pos, value in enumerate(row[1:]):
26-
results_dict["Tests"][test_name][header[pos + 1]] = value
18+
csv_data = csv_data.splitlines()
19+
full_csv = list(csv.reader(csv_data, delimiter=",", quoting=csv.QUOTE_ALL))
20+
if len(full_csv) >= 2:
21+
header = full_csv[0]
22+
for raw_row in csv_data[1:]:
23+
row = raw_row.rsplit(",", len(header) - 1)
24+
assert len(row) == len(header)
25+
test_name = row[0][1:-1].split(" ")[0]
26+
if overload_test_name is not None:
27+
test_name = overload_test_name
28+
results_dict["Tests"][test_name] = {}
29+
for pos, value in enumerate(row[1:]):
30+
results_dict["Tests"][test_name][header[pos + 1]] = value
2731
return results_dict
2832

2933

@@ -67,10 +71,6 @@ def prepare_redis_benchmark_command(
6771
if last_append is not None:
6872
command_arr.extend(last_append)
6973
command_str = command_str + " " + last_str
70-
logging.info(
71-
"Running the benchmark with the following parameters:"
72-
"\n\tArgs array: {}\n\tArgs str: {}".format(command_arr, command_str)
73-
)
7474
return command_arr, command_str
7575

7676

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"test","rps","avg_latency_ms","min_latency_ms","p50_latency_ms","p95_latency_ms","p99_latency_ms","max_latency_ms"
2+
"JSON.SET pass-100 . {"sclr":0,"str":"b","sub_doc":{"sclr":10,"str":"c","arr":[1,2,3,{"sclr":20,"str":"d"}]},"array_of_docs":[-1,{"sclr":11,"str":"e","arr":[4,5,6,{"sclr":21,"str":"f"}]},{"sclr":12,"str":"g","arr":[7,8,9,{"sclr":22,"str":"h"}]},-2]}","73391.80","0.206","0.024","0.199","0.327","0.423","16.463"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"test","rps","avg_latency_ms","min_latency_ms","p50_latency_ms","p95_latency_ms","p99_latency_ms","max_latency_ms"

tests/test_redis_benchmark_csv_format.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,25 @@ def test_redis_benchmark_export_logic():
3030
csv_data = csv_file.read()
3131
results_dict = redis_benchmark_from_stdout_csv_to_json(csv_data, 1, "1")
3232
redis_benchmark_export_logic(results_dict, [], None, {})
33+
assert "SET" in results_dict["Tests"]
34+
assert "GET" in results_dict["Tests"]
35+
36+
with open("./tests/test_data/redis-benchmark-6.2.0-csv.out.2", "r") as csv_file:
37+
csv_data = csv_file.read()
38+
results_dict = redis_benchmark_from_stdout_csv_to_json(csv_data, 1, "1")
39+
redis_benchmark_export_logic(results_dict, [], None, {})
40+
assert "JSON.SET" in results_dict["Tests"]
41+
42+
with open("./tests/test_data/redis-benchmark-6.2.0-csv.out.2", "r") as csv_file:
43+
csv_data = csv_file.read()
44+
results_dict = redis_benchmark_from_stdout_csv_to_json(
45+
csv_data, 1, "1", "Overall"
46+
)
47+
redis_benchmark_export_logic(results_dict, [], None, {})
48+
assert "Overall" in results_dict["Tests"]
49+
50+
with open("./tests/test_data/redis-benchmark-6.2.0-csv.out.3", "r") as csv_file:
51+
csv_data = csv_file.read()
52+
results_dict = redis_benchmark_from_stdout_csv_to_json(csv_data, 1, "1")
53+
redis_benchmark_export_logic(results_dict, [], None, {})
54+
assert len(results_dict["Tests"].keys()) == 0

0 commit comments

Comments
 (0)