Skip to content

Commit afab8fe

Browse files
Introduce run-async subtool (#391)
* feature/callback: add callback in to run_remote logic * feature/callback: test fix for gnupg * feature/callback: remove cat gpg.conf command from action * feature/callback: try another way of fix gnupg problem * feature/callback: remove actions-setup-docker * feature/callback: different poetry install * feature/callback: shell way to install poetry * feature/callback: try another actions lib to install poetry * feature/callback: fix file * feature/callback: poetry version * feature/callback: test ci without python3.6 * feature/callback: fix formatting * feature/callback: fix what flake8 found * feature/callback: add callback url * feature/callback: change github env variable name to avoid problem with github actions env * feature/callback: remove branch, workflow id from request, make github token not required * feature/callback: fix callback url formatting * feature/callback: callback_headers statement in function * feature/async-run: add async run * feature/async-run: private key fix * feature/async-run: return actual poetry lock * feature/async-run: delete poetry.lock file * feature/async-run: poetry.lock from master * feature/async-run: remove callback action * feature/async-run: fix path * feature/async-run: fix path * feature/async-run: fix path for python * feature/async-run: command line, terraform install * feature/async-run: add sudo * feature/async-run: add /dev/null redirect for useless stdout from gpg * feature/async-run: add copy of private key in right directory * feature/async-run: rename pem file naming, file writing change * feature/async-run: fixing pem formatting * feature/async-run: module path * feature/async-run: module copy fix and module path fix * feature/async-run: docker redis, add info in output of copy files * feature/async-run: docker redis install fix * feature/async-run: fix for branches with slash * feature/async-run: fix for branches with slash, add sudo to docker run * feature/async-run: remove fix for branch with slashes * feature/async-run: add run for service, add github token pass to run variables * feature/async-run: token env variable pass, code format * feature/async-run: remove duplicate code * feature/async-run: testing infrastructure repo url * feature/async-run: cleanup code * feature/async-run: cleanup and fix diff between master * feature/async-run: remove unused files * feature/async-run: fix formatting * feature/async-run: flake8 formatting * feature/async-run: fix commands * feature/async-run: fix commands * feature/async-run: return commands * feature/async-run: add job name env pass * feature/async-run: add job name parameter * Updated run-async not to run stack * Bumping version from 0.9.55 to 0.10.0 --------- Co-authored-by: filipe oliveira <filipecosta.90@gmail.com>
1 parent ed20d5c commit afab8fe

File tree

9 files changed

+1021
-1
lines changed

9 files changed

+1021
-1
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.9.55"
3+
version = "0.10.0"
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 <filipecosta.90@gmail.com>","Redis Performance Group <performance@redis.com>"]
66
readme = "README.md"

redisbench_admin/cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from redisbench_admin.extract.extract import extract_command_logic
2222
from redisbench_admin.grafana_api.args import create_grafana_api_arguments
2323
from redisbench_admin.grafana_api.grafana_api import grafana_api_command_logic
24+
from redisbench_admin.run_async.run_async import run_async_command_logic
2425
from redisbench_admin.run_local.args import create_run_local_arguments
2526
from redisbench_admin.run_local.run_local import run_local_command_logic
2627
from redisbench_admin.run_remote.args import create_run_remote_arguments
@@ -76,6 +77,8 @@ def main():
7677

7778
if requested_tool == "run-remote":
7879
parser = create_run_remote_arguments(parser)
80+
elif requested_tool == "run-async":
81+
parser = create_run_remote_arguments(parser)
7982
elif requested_tool == "run-local":
8083
parser = create_run_local_arguments(parser)
8184
elif requested_tool == "extract":
@@ -100,6 +103,7 @@ def main():
100103
"compare",
101104
"run-local",
102105
"run-remote",
106+
"run-async",
103107
"deploy",
104108
"export",
105109
"extract",
@@ -143,6 +147,8 @@ def main():
143147
run_local_command_logic(args, project_name, project_version)
144148
if requested_tool == "run-remote":
145149
run_remote_command_logic(args, project_name, project_version)
150+
if requested_tool == "run-async":
151+
run_async_command_logic(argv, args, project_name, project_version)
146152
if requested_tool == "export":
147153
export_command_logic(args, project_name, project_version)
148154
if requested_tool == "extract":
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Apache License Version 2.0
2+
#
3+
# Copyright (c) 2021., Redis Labs Modules
4+
# All rights reserved.
5+
#
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# BSD 3-Clause License
2+
#
3+
# Copyright (c) 2021., Redis Labs Modules
4+
# All rights reserved.
5+
#
6+
import logging
7+
import tarfile
8+
9+
from redisbench_admin.run_async.terraform import (
10+
retrieve_inventory_info,
11+
terraform_spin_or_reuse_env,
12+
)
13+
14+
15+
def tar_files(filename="archive.tar", path="./../../"):
16+
logging.info("Creating tar archive: {} for path {}".format(filename, path))
17+
with tarfile.open(filename, "w") as tar:
18+
tar.add(path, arcname=".")
19+
return filename
20+
21+
22+
def async_env_setup(
23+
args,
24+
benchmark_config,
25+
remote_envs,
26+
repetition,
27+
test_name,
28+
tf_bin_path,
29+
tf_github_actor,
30+
tf_github_org,
31+
tf_github_repo,
32+
tf_github_sha,
33+
tf_setup_name_sufix,
34+
tf_triggering_env,
35+
tf_timeout_secs=7200,
36+
tf_override_name=None,
37+
tf_folder_path=None,
38+
):
39+
server_plaintext_port = args.db_port
40+
db_ssh_port = args.db_ssh_port
41+
client_ssh_port = args.client_ssh_port
42+
username = args.user
43+
if args.inventory is not None:
44+
(
45+
status,
46+
client_public_ip,
47+
server_private_ip,
48+
server_public_ip,
49+
) = retrieve_inventory_info(args.inventory)
50+
if status is False:
51+
logging.error(
52+
"Missing one of the required keys for inventory usage. Exiting..."
53+
)
54+
exit(1)
55+
logging.info("Using the following connection addresses.")
56+
logging.info("client_public_ip={}".format(client_public_ip))
57+
logging.info("server_public_ip={}".format(server_public_ip))
58+
logging.info("server_private_ip={}".format(server_private_ip))
59+
else:
60+
(
61+
client_public_ip,
62+
_,
63+
_,
64+
server_private_ip,
65+
server_public_ip,
66+
username,
67+
) = terraform_spin_or_reuse_env(
68+
benchmark_config,
69+
remote_envs,
70+
repetition,
71+
test_name,
72+
tf_bin_path,
73+
tf_github_actor,
74+
tf_github_org,
75+
tf_github_repo,
76+
tf_github_sha,
77+
tf_setup_name_sufix,
78+
tf_triggering_env,
79+
tf_timeout_secs,
80+
tf_override_name,
81+
tf_folder_path,
82+
)
83+
return (
84+
client_public_ip,
85+
server_plaintext_port,
86+
server_private_ip,
87+
server_public_ip,
88+
db_ssh_port,
89+
client_ssh_port,
90+
username,
91+
)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from redisbench_admin.utils.benchmark_config import (
2+
prepare_benchmark_definitions,
3+
process_benchmark_definitions_remote_timeouts,
4+
)
5+
6+
7+
class BenchmarkClass:
8+
def __init__(
9+
self,
10+
benchmark_defs_result=None,
11+
benchmark_definitions=None,
12+
default_metrics=None,
13+
exporter_timemetric_path=None,
14+
default_specs=None,
15+
clusterconfig=None,
16+
remote_envs_timeout=None,
17+
benchmark_runs_plan=None,
18+
):
19+
self.benchmark_defs_result = benchmark_defs_result
20+
self.benchmark_definitions = benchmark_definitions
21+
self.default_metrics = default_metrics
22+
self.exporter_timemetric_path = exporter_timemetric_path
23+
self.default_specs = default_specs
24+
self.clusterconfig = clusterconfig
25+
self.benchmark_artifacts_table_headers = [
26+
"Setup",
27+
"Test-case",
28+
"Artifact",
29+
"link",
30+
]
31+
self.benchmark_artifacts_table_name = "Benchmark client artifacts"
32+
self.benchmark_runs_plan = benchmark_runs_plan
33+
34+
self.remote_envs_timeout = remote_envs_timeout
35+
36+
def prepare_benchmark_definitions(self, args):
37+
(
38+
self.benchmark_defs_result,
39+
self.benchmark_definitions,
40+
self.default_metrics,
41+
self.exporter_timemetric_path,
42+
self.default_specs,
43+
self.clusterconfig,
44+
) = prepare_benchmark_definitions(args)
45+
46+
def populate_remote_envs_timeout(self):
47+
self.remote_envs_timeout = process_benchmark_definitions_remote_timeouts(
48+
self.benchmark_definitions
49+
)

redisbench_admin/run_async/log.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# BSD 3-Clause License
2+
#
3+
# Copyright (c) 2021., Redis Labs Modules
4+
# All rights reserved.
5+
#
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import jinja2
2+
3+
4+
def renderServiceFile(access_key, region, secret_key, gh_token, job_name, args, argv):
5+
environment = jinja2.Environment()
6+
template = environment.from_string(
7+
"""[Unit]
8+
Description=Redisbench-admin run service
9+
10+
[Service]
11+
Type=oneshot
12+
Environment="PATH=/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
13+
Environment="AWS_ACCESS_KEY_ID={{access_key}}"
14+
Environment="AWS_DEFAULT_REGION={{region}}"
15+
Environment="AWS_SECRET_ACCESS_KEY={{secret_key}}"
16+
{% if gh_token != None %}Environment="GH_TOKEN={{gh_token}}"{% endif %}
17+
{% if job_name != None %}Environment="CIRCLE_JOB={{job_name}}"{% endif %}
18+
WorkingDirectory=/home/ubuntu/work_dir/tests/benchmarks
19+
Type=simple
20+
User=ubuntu
21+
ExecStart=/home/ubuntu/work_dir/redisbench-admin/.venv/bin/python /home/ubuntu/work_dir/redisbench-admin/run.py run-remote {{args}}
22+
23+
[Install]
24+
WantedBy=multi-user.target
25+
"""
26+
)
27+
if "--private_key" not in argv:
28+
argv.append("--private_key")
29+
argv.append("/home/ubuntu/work_dir/tests/benchmarks/benchmarks.redislabs.pem")
30+
else:
31+
argv[
32+
argv.index(args.private_key)
33+
] = "/home/ubuntu/work_dir/tests/benchmarks/benchmarks.redislabs.pem"
34+
if len(args.module_path) != 0:
35+
argv[argv.index(args.module_path[0])] = (
36+
"/home/ubuntu/work_dir/tests/benchmarks/"
37+
+ args.module_path[0].split("/")[-1]
38+
)
39+
argv_str = " ".join(argv)
40+
with open("redisbench-admin.service", mode="w", encoding="utf-8") as results:
41+
results.write(
42+
template.render(
43+
access_key=access_key,
44+
region=region,
45+
secret_key=secret_key,
46+
gh_token=gh_token,
47+
job_name=job_name,
48+
args=argv_str,
49+
)
50+
)
51+
52+
53+
def renderRunFile():
54+
with open("run.py", mode="w", encoding="utf-8") as run_file:
55+
run_file.write(
56+
"""#!/usr/local/bin/python
57+
# -*- coding: utf-8 -*-
58+
import re
59+
import sys
60+
from redisbench_admin.cli import main
61+
62+
if __name__ == "__main__":
63+
sys.argv[0] = re.sub(r"(-script\\.pyw|\\.exe)?$", "", sys.argv[0])
64+
sys.exit(main())
65+
"""
66+
)
67+
68+
69+
def savePemFile(pem_data):
70+
with open("benchmarks.redislabs.pem", mode="w", encoding="utf-8") as pem_file:
71+
pem_data = pem_data.replace("-----BEGIN RSA PRIVATE KEY-----", "")
72+
pem_data = pem_data.replace("-----END RSA PRIVATE KEY-----", "")
73+
pem_data = pem_data.replace(" ", "\n")
74+
pem_data = (
75+
"-----BEGIN RSA PRIVATE KEY-----"
76+
+ pem_data
77+
+ "-----END RSA PRIVATE KEY-----"
78+
)
79+
pem_file.write(pem_data)

0 commit comments

Comments
 (0)