Skip to content

Commit 5622c7a

Browse files
Added --required-module to local/remote runs to enable faster failures in case of missing module (#93)
* [add] Added --required-module to local/remote runs to enable faster failures in case of missing module * Bumping version from 0.1.69 to 0.1.70
1 parent 35ad5ed commit 5622c7a

File tree

7 files changed

+79
-9
lines changed

7 files changed

+79
-9
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.69"
3+
version = "0.1.70"
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_local/args.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,12 @@ def create_run_local_arguments(parser):
1212
default="",
1313
help="specify a test to run. By default will run all of them.",
1414
)
15+
parser.add_argument(
16+
"--required-module",
17+
default=None,
18+
action="append",
19+
help="path to the module file. "
20+
"You can use `--required-module` more than once",
21+
)
1522
parser.add_argument("--port", type=int, default=6379)
1623
return parser

redisbench_admin/run_local/run_local.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sys
88
import tempfile
99

10+
import redis
1011
import wget
1112
import yaml
1213

@@ -22,6 +23,9 @@
2223
redis_benchmark_ensure_min_version_local,
2324
)
2425
from redisbench_admin.run.ycsb.ycsb import post_process_ycsb_results
26+
from redisbench_admin.run_remote.run_remote import (
27+
extract_module_semver_from_info_modules_cmd,
28+
)
2529
from redisbench_admin.utils.local import (
2630
spin_up_local_redis,
2731
get_local_run_full_filename,
@@ -47,6 +51,7 @@ def run_local_command_logic(args):
4751

4852
local_module_file = args.module_path
4953
os.path.abspath(".")
54+
required_modules = args.required_module
5055

5156
logging.info("Retrieved the following local info:")
5257
logging.info("\tgithub_actor: {}".format(github_actor))
@@ -126,6 +131,29 @@ def run_local_command_logic(args):
126131
)
127132
if is_process_alive(redis_process) is False:
128133
raise Exception("Redis process is not alive. Failing test.")
134+
135+
r = redis.StrictRedis(port=args.port)
136+
stdout = r.execute_command("info modules")
137+
print(stdout)
138+
(
139+
module_names,
140+
_,
141+
) = extract_module_semver_from_info_modules_cmd(stdout)
142+
if len(required_modules) > 0:
143+
logging.info(
144+
"Checking if the following required modules {} are present".format(
145+
required_modules
146+
)
147+
)
148+
for required_module in required_modules:
149+
if required_module not in module_names:
150+
raise Exception(
151+
"Unable to detect required module {} in {}. Aborting...".format(
152+
required_module,
153+
module_names,
154+
)
155+
)
156+
129157
# setup the benchmark
130158
start_time, start_time_ms, start_time_str = get_start_time_vars()
131159
local_benchmark_output_filename = get_local_run_full_filename(

redisbench_admin/run_remote/args.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def create_run_remote_arguments(parser):
2626
parser.add_argument("--github_repo", type=str, default=None)
2727
parser.add_argument("--github_org", type=str, default=None)
2828
parser.add_argument("--github_sha", type=str, default=None, nargs="?", const="")
29+
parser.add_argument(
30+
"--required-module",
31+
default=None,
32+
action="append",
33+
help="path to the module file. "
34+
"You can use `--required-module` more than once",
35+
)
2936
parser.add_argument("--github_branch", type=str, default=None, nargs="?", const="")
3037
parser.add_argument("--triggering_env", type=str, default=socket.gethostname())
3138
parser.add_argument("--terraform_bin_path", type=str, default=TERRAFORM_BIN_PATH)

redisbench_admin/run_remote/run_remote.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,15 @@ def extract_artifact_version_remote(
9595
res = execute_remote_commands(server_public_ip, username, private_key, commands)
9696
recv_exit_status, stdout, stderr = res[0]
9797
print(stdout)
98-
version = extract_module_semver_from_info_modules_cmd(stdout)
99-
return version
98+
module_name, version = extract_module_semver_from_info_modules_cmd(stdout)
99+
return module_name, version
100100

101101

102102
def extract_module_semver_from_info_modules_cmd(stdout):
103-
version = None
103+
versions = []
104+
module_names = []
105+
if type(stdout) == bytes:
106+
stdout = stdout.decode()
104107
if type(stdout) == str:
105108
info_modules_output = stdout.split("\n")[1:]
106109
else:
@@ -114,7 +117,9 @@ def extract_module_semver_from_info_modules_cmd(stdout):
114117
logging.info(
115118
"Detected artifact={}, semver={}.".format(module_name, version)
116119
)
117-
return version
120+
module_names.append(module_name)
121+
versions.append(version)
122+
return module_names, versions
118123

119124

120125
def run_remote_command_logic(args):
@@ -124,6 +129,7 @@ def run_remote_command_logic(args):
124129
tf_github_repo = args.github_repo
125130
tf_github_sha = args.github_sha
126131
tf_github_branch = args.github_branch
132+
required_modules = args.required_module
127133

128134
if tf_github_org is None:
129135
(
@@ -389,9 +395,27 @@ def run_remote_command_logic(args):
389395
remote_dataset_file,
390396
dirname,
391397
)
392-
artifact_version = extract_artifact_version_remote(
398+
module_names, artifact_versions = extract_artifact_version_remote(
393399
server_public_ip, server_plaintext_port, username, private_key
394400
)
401+
if len(required_modules) > 0:
402+
logging.info(
403+
"Checking if the following required modules {} are present".format(
404+
required_modules
405+
)
406+
)
407+
for required_module in required_modules:
408+
if required_module not in module_names:
409+
raise Exception(
410+
"Unable to detect required module {} in {}, using remote DB with IP {}, PORT {}. Aborting...".format(
411+
required_module,
412+
module_names,
413+
server_public_ip,
414+
server_plaintext_port,
415+
)
416+
)
417+
418+
artifact_version = artifact_versions[0]
395419
(
396420
benchmark_min_tool_version,
397421
benchmark_min_tool_version_major,

redisbench_admin/utils/local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def spin_up_local_redis(
9494
)
9595
)
9696
redis_process = subprocess.Popen(command)
97-
result = wait_for_conn(redis.StrictRedis())
97+
result = wait_for_conn(redis.StrictRedis(port=port))
9898
if result is True:
9999
logging.info("Redis available")
100100
return redis_process

tests/test_run_remote.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55

66
def test_extract_module_semver_from_info_modules_cmd():
77
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"
8+
module_name, semver = extract_module_semver_from_info_modules_cmd(stdout)
9+
assert semver[0] == "999999"
10+
assert module_name[0] == "search"
11+
module_name, semver = extract_module_semver_from_info_modules_cmd(b"")
12+
assert semver == []
13+
assert module_name == []

0 commit comments

Comments
 (0)