1
1
import csv
2
2
import logging
3
+ import re
3
4
import shlex
5
+ import subprocess
4
6
7
+ from redisbench_admin .utils .remote import executeRemoteCommands
5
8
6
- def redis_benchmark_from_stdout_csv_to_json (stdout , start_time , start_time_str ):
9
+
10
+ def redis_benchmark_from_stdout_csv_to_json (csv_data , start_time , start_time_str , overloadTestName = None ):
7
11
results_dict = {"Tests" : {}, "StartTime" : int (start_time .strftime ("%s" )),
8
12
"StartTimeHuman" : start_time_str }
9
- csv_data = list (csv .reader (stdout . decode ( 'ascii' ) .splitlines (), delimiter = "," ))
13
+ csv_data = list (csv .reader (csv_data .splitlines (), delimiter = "," ))
10
14
header = csv_data [0 ]
11
15
for row in csv_data [1 :]:
12
16
test_name = row [0 ]
17
+ if overloadTestName is not None :
18
+ test_name = overloadTestName
13
19
results_dict ["Tests" ][test_name ] = {}
14
20
for pos , value in enumerate (row [1 :]):
15
21
results_dict ["Tests" ][test_name ][header [pos + 1 ]] = value
@@ -21,38 +27,89 @@ def prepareRedisBenchmarkCommand(
21
27
server_private_ip : object ,
22
28
server_plaintext_port : object ,
23
29
benchmark_config : object ,
24
- ) -> str :
30
+ ):
25
31
"""
26
32
Prepares redis-benchmark command parameters
27
33
:param server_private_ip:
28
34
:param server_plaintext_port:
29
35
:param benchmark_config:
30
- :return: string containing the required command to run the benchmark given the configurations
36
+ :return: [ string] containing the required command to run the benchmark given the configurations
31
37
"""
32
- queries_str = [executable_path ]
33
- queries_str .extend (["-h" , "{}" .format (server_private_ip )])
34
- queries_str .extend (["-p" , "{}" .format (server_plaintext_port )])
38
+ command_str = ""
39
+ command_arr = [executable_path ]
40
+ command_arr .extend (["-h" , "{}" .format (server_private_ip )])
41
+ command_arr .extend (["-p" , "{}" .format (server_plaintext_port )])
35
42
36
43
# we need the csv output
37
- queries_str .extend (["--csv" , "-e" ])
44
+ command_arr .extend (["--csv" , "-e" ])
38
45
last_append = None
39
46
for k in benchmark_config ["parameters" ]:
40
47
if "clients" in k :
41
- queries_str .extend (["-c" , "{}" .format (k ["clients" ])])
48
+ command_arr .extend (["-c" , "{}" .format (k ["clients" ])])
42
49
if "requests" in k :
43
- queries_str .extend (["-n" , "{}" .format (k ["requests" ])])
50
+ command_arr .extend (["-n" , "{}" .format (k ["requests" ])])
44
51
if "threads" in k :
45
- queries_str .extend (["--threads" , "{}" .format (k ["threads" ])])
52
+ command_arr .extend (["--threads" , "{}" .format (k ["threads" ])])
46
53
if "pipeline" in k :
47
- queries_str .extend (["-P" , "{}" .format (k ["pipeline" ])])
54
+ command_arr .extend (["-P" , "{}" .format (k ["pipeline" ])])
48
55
# if we have the command keywork then it needs to be at the end of args
49
56
if "command" in k :
57
+ last_str = k ["command" ]
50
58
last_append = shlex .split (k ["command" ])
59
+ command_str = " " .join (command_arr )
51
60
if last_append is not None :
52
- queries_str .extend (last_append )
61
+ command_arr .extend (last_append )
62
+ command_str = command_str + " " + last_str
53
63
logging .info (
54
- "Running the benchmark with the following parameters: {}" .format (
55
- " " . join ( queries_str )
64
+ "Running the benchmark with the following parameters:\n \t Args array: {} \n \t Args str: {}" .format (
65
+ command_arr , command_str
56
66
)
57
67
)
58
- return queries_str
68
+ return command_arr , command_str
69
+
70
+
71
+ def ensure_redis_benchmark_version_from_input (benchmark_min_tool_version , benchmark_min_tool_version_major ,
72
+ benchmark_min_tool_version_minor , benchmark_min_tool_version_patch ,
73
+ benchmark_tool , stdout ):
74
+ version_output = stdout .decode ('ascii' ).split ("\n " )[0 ]
75
+ logging .info (
76
+ "Detected benchmark config tool {} with version {}" .format (benchmark_tool , version_output ))
77
+ p = re .compile ("redis-benchmark (\d+)\.(\d+)\.(\d+) " )
78
+ m = p .match (version_output )
79
+ if m is None :
80
+ raise Exception (
81
+ "Unable to detect benchmark tool version, and the benchmark requires a min version: {}" .format (
82
+ benchmark_min_tool_version ))
83
+ major = m .group (1 )
84
+ minor = m .group (2 )
85
+ patch = m .group (3 )
86
+ if major < benchmark_min_tool_version_major or (
87
+ major == benchmark_min_tool_version_major and minor < benchmark_min_tool_version_minor ) or (
88
+ major == benchmark_min_tool_version_major and minor == benchmark_min_tool_version_minor and patch < benchmark_min_tool_version_patch ):
89
+ raise Exception (
90
+ "Detected benchmark version that is inferior than the minimum required. {} < {}" .format (
91
+ version_output , benchmark_min_tool_version ))
92
+
93
+
94
+ def redis_benchmark_ensure_min_version_local (benchmark_tool , benchmark_min_tool_version ,
95
+ benchmark_min_tool_version_major ,
96
+ benchmark_min_tool_version_minor , benchmark_min_tool_version_patch ):
97
+ benchmark_client_process = subprocess .Popen (args = [benchmark_tool , "--version" ],
98
+ stdout = subprocess .PIPE ,
99
+ stderr = subprocess .STDOUT )
100
+ (stdout , sterr ) = benchmark_client_process .communicate ()
101
+ ensure_redis_benchmark_version_from_input (benchmark_min_tool_version , benchmark_min_tool_version_major ,
102
+ benchmark_min_tool_version_minor , benchmark_min_tool_version_patch ,
103
+ benchmark_tool , stdout )
104
+
105
+
106
+ def redis_benchmark_ensure_min_version_remote (benchmark_tool , benchmark_min_tool_version ,
107
+ benchmark_min_tool_version_major ,
108
+ benchmark_min_tool_version_minor , benchmark_min_tool_version_patch ):
109
+ benchmark_client_process = subprocess .Popen (args = [benchmark_tool , "--version" ],
110
+ stdout = subprocess .PIPE ,
111
+ stderr = subprocess .STDOUT )
112
+ (stdout , sterr ) = benchmark_client_process .communicate ()
113
+ ensure_redis_benchmark_version_from_input (benchmark_min_tool_version , benchmark_min_tool_version_major ,
114
+ benchmark_min_tool_version_minor , benchmark_min_tool_version_patch ,
115
+ benchmark_tool , stdout )
0 commit comments