Skip to content

Commit 414cf8e

Browse files
Enable TLS benchmarks on client-runner and memtier_benchmark (#77)
* Enable TLS benchmarks on client-runner and memtier_benchmark * Fixed flake8 error
1 parent d8e79ce commit 414cf8e

File tree

4 files changed

+272
-5
lines changed

4 files changed

+272
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "redis-benchmarks-specification"
3-
version = "0.1.19"
3+
version = "0.1.20"
44
description = "The Redis benchmarks specification describes the cross-language/tools requirements and expectations to foster performance and observability standards around redis related technologies. Members from both industry and academia, including organizations and individuals are encouraged to contribute."
55
authors = ["filipecosta90 <[email protected]>","Redis Performance Group <[email protected]>"]
66
readme = "Readme.md"

redis_benchmarks_specification/__runner__/args.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,31 @@ def create_client_runner_args(project_name):
7676
action="store_true",
7777
help="At the end of every test send a FLUSHALL",
7878
)
79+
parser.add_argument(
80+
"--tls",
81+
default=False,
82+
action="store_true",
83+
help="Enable SSL/TLS transport security",
84+
)
85+
parser.add_argument(
86+
"--tls-skip-verify",
87+
default=False,
88+
action="store_true",
89+
help="Skip verification of server certificate",
90+
)
91+
parser.add_argument(
92+
"--cert",
93+
default="",
94+
help="Use specified client certificate for TLS",
95+
)
96+
parser.add_argument(
97+
"--key",
98+
default="",
99+
help="Use specified private key for TLS",
100+
)
101+
parser.add_argument(
102+
"--cacert",
103+
default="",
104+
help="Use specified CA certs bundle for TLS",
105+
)
79106
return parser

redis_benchmarks_specification/__runner__/runner.py

Lines changed: 102 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import logging
44
import os
55
import pathlib
6-
import shutil
76
import sys
87
import tempfile
98
import traceback
109
from pathlib import Path
10+
import shutil
1111

1212
import docker
1313
import redis
@@ -110,6 +110,11 @@ def main():
110110
exit(1)
111111

112112
running_platform = args.platform_name
113+
tls_enabled = args.tls
114+
tls_skip_verify = args.tls_skip_verify
115+
tls_cert = args.cert
116+
tls_key = args.key
117+
tls_cacert = args.cacert
113118
docker_client = docker.from_env()
114119
home = str(Path.home())
115120
logging.info("Running the benchmark specs.")
@@ -124,6 +129,11 @@ def main():
124129
testsuite_spec_files,
125130
{},
126131
running_platform,
132+
tls_enabled,
133+
tls_skip_verify,
134+
tls_cert,
135+
tls_key,
136+
tls_cacert,
127137
)
128138

129139

@@ -134,6 +144,11 @@ def prepare_memtier_benchmark_parameters(
134144
server,
135145
local_benchmark_output_filename,
136146
oss_cluster_api_enabled,
147+
tls_enabled=False,
148+
tls_skip_verify=False,
149+
tls_cert=None,
150+
tls_key=None,
151+
tls_cacert=None,
137152
):
138153
benchmark_command = [
139154
full_benchmark_path,
@@ -144,6 +159,17 @@ def prepare_memtier_benchmark_parameters(
144159
"--json-out-file",
145160
local_benchmark_output_filename,
146161
]
162+
if tls_enabled:
163+
benchmark_command.append("--tls")
164+
if tls_cert is not None and tls_cert != "":
165+
benchmark_command.extend(["--cert", tls_cert])
166+
if tls_key is not None and tls_key != "":
167+
benchmark_command.extend(["--key", tls_key])
168+
if tls_cacert is not None and tls_cacert != "":
169+
benchmark_command.extend(["--cacert", tls_cacert])
170+
if tls_skip_verify:
171+
benchmark_command.append("--tls-skip-verify")
172+
147173
if oss_cluster_api_enabled is True:
148174
benchmark_command.append("--cluster-mode")
149175
benchmark_command_str = " ".join(benchmark_command)
@@ -163,14 +189,29 @@ def process_self_contained_coordinator_stream(
163189
testsuite_spec_files,
164190
topologies_map,
165191
running_platform,
192+
tls_enabled=False,
193+
tls_skip_verify=False,
194+
tls_cert=None,
195+
tls_key=None,
196+
tls_cacert=None,
166197
):
167198
overall_result = True
168199
total_test_suite_runs = 0
169200
for test_file in testsuite_spec_files:
170201
client_containers = []
171202

172203
with open(test_file, "r") as stream:
173-
benchmark_config, test_name = get_final_benchmark_config(None, stream, "")
204+
_, benchmark_config, test_name = get_final_benchmark_config(
205+
None, stream, ""
206+
)
207+
208+
if tls_enabled:
209+
test_name = test_name + "-tls"
210+
logging.info(
211+
"Given that TLS is enabled, appending -tls to the testname: {}.".format(
212+
test_name
213+
)
214+
)
174215

175216
for topology_spec_name in benchmark_config["redis-topologies"]:
176217
test_result = False
@@ -189,8 +230,22 @@ def process_self_contained_coordinator_stream(
189230

190231
port = args.db_server_port
191232
host = args.db_server_host
192-
r = redis.StrictRedis(host=host, port=port)
233+
234+
ssl_cert_reqs = "required"
235+
if tls_skip_verify:
236+
ssl_cert_reqs = None
237+
r = redis.StrictRedis(
238+
host=host,
239+
port=port,
240+
ssl=tls_enabled,
241+
ssl_cert_reqs=ssl_cert_reqs,
242+
ssl_keyfile=tls_key,
243+
ssl_certfile=tls_cert,
244+
ssl_ca_certs=tls_cacert,
245+
ssl_check_hostname=False,
246+
)
193247
r.ping()
248+
194249
ceil_client_cpu_limit = extract_client_cpu_limit(benchmark_config)
195250
client_cpuset_cpus, current_cpu_pos = generate_cpuset_cpus(
196251
ceil_client_cpu_limit, current_cpu_pos
@@ -202,6 +257,17 @@ def process_self_contained_coordinator_stream(
202257
benchmark_tool_workdir = client_mnt_point
203258

204259
metadata = {}
260+
if tls_enabled:
261+
metadata["tls"] = "true"
262+
if tls_cert is not None and tls_cert != "":
263+
_, tls_cert = cp_to_workdir(temporary_dir_client, tls_cert)
264+
if tls_cacert is not None and tls_cacert != "":
265+
_, tls_cacert = cp_to_workdir(
266+
temporary_dir_client, tls_cacert
267+
)
268+
if tls_key is not None and tls_key != "":
269+
_, tls_key = cp_to_workdir(temporary_dir_client, tls_key)
270+
205271
if "preload_tool" in benchmark_config["dbconfig"]:
206272
data_prepopulation_step(
207273
benchmark_config,
@@ -213,6 +279,11 @@ def process_self_contained_coordinator_stream(
213279
temporary_dir_client,
214280
test_name,
215281
host,
282+
tls_enabled,
283+
tls_skip_verify,
284+
tls_cert,
285+
tls_key,
286+
tls_cacert,
216287
)
217288

218289
benchmark_tool = extract_client_tool(benchmark_config)
@@ -263,7 +334,12 @@ def process_self_contained_coordinator_stream(
263334
port,
264335
host,
265336
local_benchmark_output_filename,
266-
benchmark_tool_workdir,
337+
False,
338+
tls_enabled,
339+
tls_skip_verify,
340+
tls_cert,
341+
tls_key,
342+
tls_cacert,
267343
)
268344

269345
client_container_image = extract_client_container_image(
@@ -389,6 +465,18 @@ def process_self_contained_coordinator_stream(
389465
overall_result &= test_result
390466

391467

468+
def cp_to_workdir(benchmark_tool_workdir, srcfile):
469+
head, filename = os.path.split(srcfile)
470+
dstfile = "{}/{}".format(benchmark_tool_workdir, filename)
471+
shutil.copyfile(srcfile, dstfile)
472+
logging.info(
473+
"Copying to workdir the following file {}. Final workdir file {}".format(
474+
srcfile, dstfile
475+
)
476+
)
477+
return dstfile, filename
478+
479+
392480
def data_prepopulation_step(
393481
benchmark_config,
394482
benchmark_tool_workdir,
@@ -399,6 +487,11 @@ def data_prepopulation_step(
399487
temporary_dir,
400488
test_name,
401489
host,
490+
tls_enabled=False,
491+
tls_skip_verify=False,
492+
tls_cert=None,
493+
tls_key=None,
494+
tls_cacert=None,
402495
):
403496
# setup the benchmark
404497
(
@@ -426,6 +519,11 @@ def data_prepopulation_step(
426519
host,
427520
local_benchmark_output_filename,
428521
False,
522+
tls_enabled,
523+
tls_skip_verify,
524+
tls_cert,
525+
tls_key,
526+
tls_cacert,
429527
)
430528

431529
logging.info(

utils/tests/test_runner.py

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import yaml
2+
3+
from redis_benchmarks_specification.__common__.spec import extract_client_tool
4+
from redis_benchmarks_specification.__runner__.runner import (
5+
prepare_memtier_benchmark_parameters,
6+
)
7+
8+
9+
def test_prepare_memtier_benchmark_parameters():
10+
with open(
11+
"./redis_benchmarks_specification/test-suites/memtier_benchmark-1Mkeys-100B-expire-use-case.yml",
12+
"r",
13+
) as yml_file:
14+
benchmark_config = yaml.safe_load(yml_file)
15+
client_tool = extract_client_tool(benchmark_config)
16+
assert client_tool == "memtier_benchmark"
17+
local_benchmark_output_filename = "1.json"
18+
oss_api_enabled = False
19+
(_, benchmark_command_str,) = prepare_memtier_benchmark_parameters(
20+
benchmark_config["clientconfig"],
21+
client_tool,
22+
12000,
23+
"localhost",
24+
local_benchmark_output_filename,
25+
oss_api_enabled,
26+
)
27+
assert (
28+
benchmark_command_str
29+
== 'memtier_benchmark --port 12000 --server localhost --json-out-file 1.json "--data-size" "100" --command "SETEX __key__ 10 __value__" --command-key-pattern="R" --command "SET __key__ __value__" --command-key-pattern="R" --command "GET __key__" --command-key-pattern="R" --command "DEL __key__" --command-key-pattern="R" -c 50 -t 2 --hide-histogram --test-time 300'
30+
)
31+
oss_api_enabled = True
32+
(_, benchmark_command_str,) = prepare_memtier_benchmark_parameters(
33+
benchmark_config["clientconfig"],
34+
client_tool,
35+
12000,
36+
"localhost",
37+
local_benchmark_output_filename,
38+
oss_api_enabled,
39+
)
40+
assert (
41+
benchmark_command_str
42+
== 'memtier_benchmark --port 12000 --server localhost --json-out-file 1.json --cluster-mode "--data-size" "100" --command "SETEX __key__ 10 __value__" --command-key-pattern="R" --command "SET __key__ __value__" --command-key-pattern="R" --command "GET __key__" --command-key-pattern="R" --command "DEL __key__" --command-key-pattern="R" -c 50 -t 2 --hide-histogram --test-time 300'
43+
)
44+
45+
oss_api_enabled = False
46+
tls_enabled = False
47+
tls_skip_verify = True
48+
tls_cert = None
49+
tls_key = None
50+
51+
# ensure that when tls is disabled we dont change the args
52+
(_, benchmark_command_str,) = prepare_memtier_benchmark_parameters(
53+
benchmark_config["clientconfig"],
54+
client_tool,
55+
12000,
56+
"localhost",
57+
local_benchmark_output_filename,
58+
oss_api_enabled,
59+
tls_enabled,
60+
tls_skip_verify,
61+
tls_cert,
62+
tls_key,
63+
)
64+
assert (
65+
benchmark_command_str
66+
== 'memtier_benchmark --port 12000 --server localhost --json-out-file 1.json "--data-size" "100" --command "SETEX __key__ 10 __value__" --command-key-pattern="R" --command "SET __key__ __value__" --command-key-pattern="R" --command "GET __key__" --command-key-pattern="R" --command "DEL __key__" --command-key-pattern="R" -c 50 -t 2 --hide-histogram --test-time 300'
67+
)
68+
69+
tls_enabled = True
70+
(_, benchmark_command_str,) = prepare_memtier_benchmark_parameters(
71+
benchmark_config["clientconfig"],
72+
client_tool,
73+
12000,
74+
"localhost",
75+
local_benchmark_output_filename,
76+
oss_api_enabled,
77+
tls_enabled,
78+
tls_skip_verify,
79+
tls_cert,
80+
tls_key,
81+
)
82+
assert (
83+
benchmark_command_str
84+
== 'memtier_benchmark --port 12000 --server localhost --json-out-file 1.json --tls --tls-skip-verify "--data-size" "100" --command "SETEX __key__ 10 __value__" --command-key-pattern="R" --command "SET __key__ __value__" --command-key-pattern="R" --command "GET __key__" --command-key-pattern="R" --command "DEL __key__" --command-key-pattern="R" -c 50 -t 2 --hide-histogram --test-time 300'
85+
)
86+
87+
tls_skip_verify = False
88+
(_, benchmark_command_str,) = prepare_memtier_benchmark_parameters(
89+
benchmark_config["clientconfig"],
90+
client_tool,
91+
12000,
92+
"localhost",
93+
local_benchmark_output_filename,
94+
oss_api_enabled,
95+
tls_enabled,
96+
tls_skip_verify,
97+
tls_cert,
98+
tls_key,
99+
)
100+
assert (
101+
benchmark_command_str
102+
== 'memtier_benchmark --port 12000 --server localhost --json-out-file 1.json --tls "--data-size" "100" --command "SETEX __key__ 10 __value__" --command-key-pattern="R" --command "SET __key__ __value__" --command-key-pattern="R" --command "GET __key__" --command-key-pattern="R" --command "DEL __key__" --command-key-pattern="R" -c 50 -t 2 --hide-histogram --test-time 300'
103+
)
104+
105+
tls_skip_verify = False
106+
tls_cert = "cert.file"
107+
tls_key = "key.file"
108+
(_, benchmark_command_str,) = prepare_memtier_benchmark_parameters(
109+
benchmark_config["clientconfig"],
110+
client_tool,
111+
12000,
112+
"localhost",
113+
local_benchmark_output_filename,
114+
oss_api_enabled,
115+
tls_enabled,
116+
tls_skip_verify,
117+
tls_cert,
118+
tls_key,
119+
)
120+
assert (
121+
benchmark_command_str
122+
== 'memtier_benchmark --port 12000 --server localhost --json-out-file 1.json --tls --cert cert.file --key key.file "--data-size" "100" --command "SETEX __key__ 10 __value__" --command-key-pattern="R" --command "SET __key__ __value__" --command-key-pattern="R" --command "GET __key__" --command-key-pattern="R" --command "DEL __key__" --command-key-pattern="R" -c 50 -t 2 --hide-histogram --test-time 300'
123+
)
124+
125+
tls_cacert = "cacert.file"
126+
(_, benchmark_command_str,) = prepare_memtier_benchmark_parameters(
127+
benchmark_config["clientconfig"],
128+
client_tool,
129+
12000,
130+
"localhost",
131+
local_benchmark_output_filename,
132+
oss_api_enabled,
133+
tls_enabled,
134+
tls_skip_verify,
135+
tls_cert,
136+
tls_key,
137+
tls_cacert,
138+
)
139+
assert (
140+
benchmark_command_str
141+
== 'memtier_benchmark --port 12000 --server localhost --json-out-file 1.json --tls --cert cert.file --key key.file --cacert cacert.file "--data-size" "100" --command "SETEX __key__ 10 __value__" --command-key-pattern="R" --command "SET __key__ __value__" --command-key-pattern="R" --command "GET __key__" --command-key-pattern="R" --command "DEL __key__" --command-key-pattern="R" -c 50 -t 2 --hide-histogram --test-time 300'
142+
)

0 commit comments

Comments
 (0)