Skip to content

Commit 35ad5ed

Browse files
[add] Enabled reusing the same remote env on multiple bench definitions. Fixed semver extraction on remote setups (#91)
1 parent 89178ce commit 35ad5ed

File tree

7 files changed

+135
-47
lines changed

7 files changed

+135
-47
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 = "redisbench-admin"
3-
version = "0.1.68"
3+
version = "0.1.69"
44
description = "Redis benchmark run helper. A wrapper around Redis and Redis Modules benchmark tools ( ftsb_redisearch, memtier_benchmark, redis-benchmark, aibench, etc... )."
55
authors = ["filipecosta90 <[email protected]>"]
66
readme = "README.md"

redisbench_admin/run/common.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from redisbench_admin.utils.remote import (
2323
execute_remote_commands,
2424
fetch_file_from_remote_setup,
25-
extract_redisgraph_version_from_resultdict,
2625
extract_perversion_timeseries_from_results,
2726
push_data_to_redistimeseries,
2827
extract_perbranch_timeseries_from_results,
@@ -274,17 +273,14 @@ def common_exporter_logic(
274273
tf_github_org,
275274
tf_github_repo,
276275
tf_triggering_env,
276+
artifact_version="N/A",
277277
):
278278
if exporter_timemetric_path is not None and len(metrics) > 0:
279279
# extract timestamp
280280
datapoints_timestamp = parse_exporter_timemetric(
281281
exporter_timemetric_path, results_dict
282282
)
283283

284-
rg_version = extract_redisgraph_version_from_resultdict(results_dict)
285-
if rg_version is None:
286-
rg_version = "N/A"
287-
288284
# extract per branch datapoints
289285
(
290286
ok,
@@ -293,7 +289,7 @@ def common_exporter_logic(
293289
datapoints_timestamp,
294290
metrics,
295291
results_dict,
296-
rg_version,
292+
artifact_version,
297293
tf_github_org,
298294
tf_github_repo,
299295
deployment_type,

redisbench_admin/run_local/run_local.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,15 @@ def run_local_command_logic(args):
177177
with open(local_benchmark_output_filename, "r") as json_file:
178178
results_dict = json.load(json_file)
179179

180-
if "kpis" in benchmark_config:
181-
result = validate_result_expectations(
182-
benchmark_config, results_dict, result, expectations_key="kpis"
183-
)
184-
if result is not True:
185-
return_code |= 1
180+
if "kpis" in benchmark_config:
181+
result = validate_result_expectations(
182+
benchmark_config,
183+
results_dict,
184+
result,
185+
expectations_key="kpis",
186+
)
187+
if result is not True:
188+
return_code |= 1
186189
except:
187190
return_code |= 1
188191
logging.critical(

redisbench_admin/run_remote/run_remote.py

Lines changed: 108 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
get_run_full_filename,
4040
fetch_remote_setup_from_config,
4141
execute_remote_commands,
42+
extract_redisgraph_version_from_resultdict,
43+
retrieve_tf_connection_vars,
4244
)
4345

4446
# internal aux vars
@@ -82,6 +84,39 @@ def setup_remote_benchmark_tool_requirements_tsbs_run_queries_redistimeseries(
8284
execute_remote_commands(client_public_ip, username, private_key, commands)
8385

8486

87+
def extract_artifact_version_remote(
88+
server_public_ip, server_public_port, username, private_key
89+
):
90+
commands = [
91+
"redis-cli -h {} -p {} info modules".format(
92+
server_public_ip, server_public_port
93+
),
94+
]
95+
res = execute_remote_commands(server_public_ip, username, private_key, commands)
96+
recv_exit_status, stdout, stderr = res[0]
97+
print(stdout)
98+
version = extract_module_semver_from_info_modules_cmd(stdout)
99+
return version
100+
101+
102+
def extract_module_semver_from_info_modules_cmd(stdout):
103+
version = None
104+
if type(stdout) == str:
105+
info_modules_output = stdout.split("\n")[1:]
106+
else:
107+
info_modules_output = stdout[1:]
108+
for module_detail_line in info_modules_output:
109+
detail_arr = module_detail_line.split(",")
110+
if len(detail_arr) > 1:
111+
module_name = detail_arr[0].split("=")
112+
module_name = module_name[1]
113+
version = detail_arr[1].split("=")[1]
114+
logging.info(
115+
"Detected artifact={}, semver={}.".format(module_name, version)
116+
)
117+
return version
118+
119+
85120
def run_remote_command_logic(args):
86121
tf_bin_path = args.terraform_bin_path
87122
tf_github_org = args.github_org
@@ -263,7 +298,7 @@ def run_remote_command_logic(args):
263298
exporter_timemetric_path,
264299
stream,
265300
)
266-
301+
remote_envs = {}
267302
for usecase_filename in files:
268303
with open(usecase_filename, "r") as stream:
269304
dirname = os.path.dirname(os.path.abspath(usecase_filename))
@@ -284,38 +319,62 @@ def run_remote_command_logic(args):
284319
)
285320

286321
if "remote" in benchmark_config:
287-
remote_setup, deployment_type = fetch_remote_setup_from_config(
288-
benchmark_config["remote"]
289-
)
322+
(
323+
remote_setup,
324+
deployment_type,
325+
remote_id,
326+
) = fetch_remote_setup_from_config(benchmark_config["remote"])
290327
logging.info(
291328
"Deploying test defined in {} on AWS using {}".format(
292329
usecase_filename, remote_setup
293330
)
294331
)
295332
tf_setup_name = "{}{}".format(remote_setup, tf_setup_name_sufix)
296333
logging.info("Using full setup name: {}".format(tf_setup_name))
297-
# check if terraform is present
298-
tf = Terraform(
299-
working_dir=remote_setup,
300-
terraform_bin_path=tf_bin_path,
301-
)
302-
(
303-
return_code,
304-
username,
305-
server_private_ip,
306-
server_public_ip,
307-
server_plaintext_port,
308-
client_private_ip,
309-
client_public_ip,
310-
) = setup_remote_environment(
311-
tf,
312-
tf_github_sha,
313-
tf_github_actor,
314-
tf_setup_name,
315-
tf_github_org,
316-
tf_github_repo,
317-
tf_triggering_env,
318-
)
334+
if remote_id not in remote_envs:
335+
# check if terraform is present
336+
tf = Terraform(
337+
working_dir=remote_setup,
338+
terraform_bin_path=tf_bin_path,
339+
)
340+
(
341+
tf_return_code,
342+
username,
343+
server_private_ip,
344+
server_public_ip,
345+
server_plaintext_port,
346+
client_private_ip,
347+
client_public_ip,
348+
) = setup_remote_environment(
349+
tf,
350+
tf_github_sha,
351+
tf_github_actor,
352+
tf_setup_name,
353+
tf_github_org,
354+
tf_github_repo,
355+
tf_triggering_env,
356+
)
357+
remote_envs[remote_id] = tf
358+
else:
359+
logging.info("Reusing remote setup {}".format(remote_id))
360+
tf = remote_envs[remote_id]
361+
(
362+
tf_return_code,
363+
username,
364+
server_private_ip,
365+
server_public_ip,
366+
server_plaintext_port,
367+
client_private_ip,
368+
client_public_ip,
369+
) = retrieve_tf_connection_vars(None, tf)
370+
commands = [
371+
"redis-cli -h {} -p {} shutdown".format(
372+
server_private_ip, server_plaintext_port
373+
)
374+
]
375+
execute_remote_commands(
376+
server_public_ip, username, private_key, commands
377+
)
319378
# after we've created the env, even on error we should always teardown
320379
# in case of some unexpected error we fail the test
321380
try:
@@ -330,7 +389,9 @@ def run_remote_command_logic(args):
330389
remote_dataset_file,
331390
dirname,
332391
)
333-
392+
artifact_version = extract_artifact_version_remote(
393+
server_public_ip, server_plaintext_port, username, private_key
394+
)
334395
(
335396
benchmark_min_tool_version,
336397
benchmark_min_tool_version_major,
@@ -460,6 +521,19 @@ def run_remote_command_logic(args):
460521
with open(local_benchmark_output_filename, "r") as json_file:
461522
results_dict = json.load(json_file)
462523

524+
# if the benchmark tool is redisgraph-benchmark-go and
525+
# we still dont have the artifact semver we can extract it from the results dict
526+
if (
527+
benchmark_tool == "redisgraph-benchmark-go"
528+
and artifact_version is None
529+
):
530+
artifact_version = extract_redisgraph_version_from_resultdict(
531+
results_dict
532+
)
533+
534+
if artifact_version is None:
535+
artifact_version = "N/A"
536+
463537
if "kpis" in benchmark_config:
464538
result = validate_result_expectations(
465539
benchmark_config,
@@ -514,6 +588,7 @@ def run_remote_command_logic(args):
514588
tf_github_org,
515589
tf_github_repo,
516590
tf_triggering_env,
591+
artifact_version,
517592
)
518593
except:
519594
return_code |= 1
@@ -525,11 +600,12 @@ def run_remote_command_logic(args):
525600
print("-" * 60)
526601
traceback.print_exc(file=sys.stdout)
527602
print("-" * 60)
528-
finally:
529-
# tear-down
530-
logging.info("Tearing down setup")
531-
tf.destroy()
532-
logging.info("Tear-down completed")
603+
604+
for remote_setup_name, tf in remote_envs.items():
605+
# tear-down
606+
logging.info("Tearing down setup {}".format(remote_setup_name))
607+
tf.destroy()
608+
logging.info("Tear-down completed")
533609

534610
exit(return_code)
535611

redisbench_admin/utils/remote.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ def setup_remote_environment(
184184
"triggering_env": tf_triggering_env,
185185
},
186186
)
187+
return retrieve_tf_connection_vars(return_code, tf)
188+
189+
190+
def retrieve_tf_connection_vars(return_code, tf):
187191
tf_output = tf.output()
188192
server_private_ip = tf_output["server_private_ip"]["value"][0]
189193
server_public_ip = tf_output["server_public_ip"]["value"][0]
@@ -404,7 +408,7 @@ def fetch_remote_setup_from_config(
404408
)
405409
git.Repo.clone_from(repo, temporary_dir, branch=branch, depth=1)
406410
terraform_working_dir = temporary_dir + path
407-
return terraform_working_dir, setup_type
411+
return terraform_working_dir, setup_type, setup
408412

409413

410414
def push_data_to_redistimeseries(rts: client, branch_time_series_dict: dict):

tests/test_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_extract_git_vars_passing_repo3():
7979

8080

8181
def test_fetch_remote_setup_from_config():
82-
terraform_working_dir, type = fetch_remote_setup_from_config(
82+
terraform_working_dir, type, _ = fetch_remote_setup_from_config(
8383
[{"type": "oss-standalone"}, {"setup": "redistimeseries-m5d"}]
8484
)
8585
assert type == "oss-standalone"

tests/test_run_remote.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from redisbench_admin.run_remote.run_remote import (
2+
extract_module_semver_from_info_modules_cmd,
3+
)
4+
5+
6+
def test_extract_module_semver_from_info_modules_cmd():
7+
stdout = b"# Modules\r\nmodule:name=search,ver=999999,api=1,filters=0,usedby=[],using=[],options=[]\r\n".decode()
8+
semver = extract_module_semver_from_info_modules_cmd(stdout)
9+
assert semver == "999999"

0 commit comments

Comments
 (0)