diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..89635cc --- /dev/null +++ b/.flake8 @@ -0,0 +1,13 @@ +[flake8] +max-line-length = 120 +max-complexity = 10 +select = C,E,F,W,B,B950 +ignore = E203,E501,W503,E722,B001,C901 +exclude = + .git, + test_*, + __pycache__, + *.egg-info, + .nox, + .pytest_cache, + .mypy_cache diff --git a/.github/workflows/poetry-pytest.yml b/.github/workflows/poetry-ci-test-lint.yml similarity index 84% rename from .github/workflows/poetry-pytest.yml rename to .github/workflows/poetry-ci-test-lint.yml index 88e1687..57ca810 100644 --- a/.github/workflows/poetry-pytest.yml +++ b/.github/workflows/poetry-ci-test-lint.yml @@ -7,7 +7,7 @@ on: jobs: pytest: - name: pytest + name: Linting, testing, and compliance runs-on: ubuntu-latest env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true @@ -39,10 +39,13 @@ jobs: run: poetry install if: steps.cache.outputs.cache-hit != 'true' + - name: Check formatting compliance with black + run: poetry run black --check . + + - name: Check PEP8 compliance with flake + run: poetry run flake8 + - name: Test with pytest - env: - DJANGO_SETTINGS_MODULE: project.settings - SECRETS_FILE: .confidential/ci.json run: poetry run pytest --cov redisbench_admin - name: Upload coverage diff --git a/poetry.lock b/poetry.lock index f1d8b52..76454e1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -194,6 +194,20 @@ category = "main" optional = false python-versions = ">=2.6, !=3.0.*, !=3.1.*" +[[package]] +name = "flake8" +version = "3.9.1" +description = "the modular source code checker: pep8 pyflakes and co" +category = "dev" +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" + +[package.dependencies] +importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} +mccabe = ">=0.6.0,<0.7.0" +pycodestyle = ">=2.7.0,<2.8.0" +pyflakes = ">=2.3.0,<2.4.0" + [[package]] name = "gitdb" version = "4.0.5" @@ -280,6 +294,14 @@ decorator = "*" ply = "*" six = "*" +[[package]] +name = "mccabe" +version = "0.6.1" +description = "McCabe checker, plugin for flake8" +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "more-itertools" version = "8.7.0" @@ -372,6 +394,14 @@ category = "main" optional = false python-versions = "*" +[[package]] +name = "pycodestyle" +version = "2.7.0" +description = "Python style guide checker" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + [[package]] name = "pycparser" version = "2.20" @@ -380,6 +410,14 @@ category = "main" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +[[package]] +name = "pyflakes" +version = "2.3.1" +description = "passive checker of Python programs" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + [[package]] name = "pynacl" version = "1.4.0" @@ -663,7 +701,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt [metadata] lock-version = "1.1" python-versions = "^3.6.1" -content-hash = "0b72c047c8eeb44ddc4f817d4ed72212554aded4602f0952cc7555c03cd47f48" +content-hash = "a2f9e5e52e0c98cdda39cdf02180c918648f7182f9511a32e8e1ec1979bae219" [metadata.files] appdirs = [ @@ -834,6 +872,10 @@ decorator = [ {file = "decorator-4.4.2-py2.py3-none-any.whl", hash = "sha256:41fa54c2a0cc4ba648be4fd43cff00aedf5b9465c9bf18d64325bc225f08f760"}, {file = "decorator-4.4.2.tar.gz", hash = "sha256:e3a62f0520172440ca0dcc823749319382e377f37f140a0b99ef45fecb84bfe7"}, ] +flake8 = [ + {file = "flake8-3.9.1-py2.py3-none-any.whl", hash = "sha256:3b9f848952dddccf635be78098ca75010f073bfe14d2c6bda867154bea728d2a"}, + {file = "flake8-3.9.1.tar.gz", hash = "sha256:1aa8990be1e689d96c745c5682b687ea49f2e05a443aff1f8251092b0014e378"}, +] gitdb = [ {file = "gitdb-4.0.5-py3-none-any.whl", hash = "sha256:91f36bfb1ab7949b3b40e23736db18231bf7593edada2ba5c3a174a7b23657ac"}, {file = "gitdb-4.0.5.tar.gz", hash = "sha256:c9e1f2d0db7ddb9a704c2a0217be31214e91a4fe1dea1efad19ae42ba0c285c9"}, @@ -910,6 +952,10 @@ jsonpath-ng = [ {file = "jsonpath-ng-1.5.2.tar.gz", hash = "sha256:144d91379be14d9019f51973bd647719c877bfc07dc6f3f5068895765950c69d"}, {file = "jsonpath_ng-1.5.2-py3-none-any.whl", hash = "sha256:93d1f248be68e485eb6635c3a01b2d681f296dc349d71e37c8755837b8944d36"}, ] +mccabe = [ + {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, + {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, +] more-itertools = [ {file = "more-itertools-8.7.0.tar.gz", hash = "sha256:c5d6da9ca3ff65220c3bfd2a8db06d698f05d4d2b9be57e1deb2be5a45019713"}, {file = "more_itertools-8.7.0-py3-none-any.whl", hash = "sha256:5652a9ac72209ed7df8d9c15daf4e1aa0e3d2ccd3c87f8265a0673cd9cbc9ced"}, @@ -945,10 +991,18 @@ py = [ py-cpuinfo = [ {file = "py-cpuinfo-5.0.0.tar.gz", hash = "sha256:2cf6426f776625b21d1db8397d3297ef7acfa59018f02a8779123f3190f18500"}, ] +pycodestyle = [ + {file = "pycodestyle-2.7.0-py2.py3-none-any.whl", hash = "sha256:514f76d918fcc0b55c6680472f0a37970994e07bbb80725808c17089be302068"}, + {file = "pycodestyle-2.7.0.tar.gz", hash = "sha256:c389c1d06bf7904078ca03399a4816f974a1d590090fecea0c63ec26ebaf1cef"}, +] pycparser = [ {file = "pycparser-2.20-py2.py3-none-any.whl", hash = "sha256:7582ad22678f0fcd81102833f60ef8d0e57288b6b5fb00323d101be910e35705"}, {file = "pycparser-2.20.tar.gz", hash = "sha256:2d475327684562c3a96cc71adf7dc8c4f0565175cf86b6d7a404ff4c771f15f0"}, ] +pyflakes = [ + {file = "pyflakes-2.3.1-py2.py3-none-any.whl", hash = "sha256:7893783d01b8a89811dd72d7dfd4d84ff098e5eed95cfa8905b22bbffe52efc3"}, + {file = "pyflakes-2.3.1.tar.gz", hash = "sha256:f5bc8ecabc05bb9d291eb5203d6810b49040f6ff446a756326104746cc00c1db"}, +] pynacl = [ {file = "PyNaCl-1.4.0-cp27-cp27m-macosx_10_10_x86_64.whl", hash = "sha256:ea6841bc3a76fa4942ce00f3bda7d436fda21e2d91602b9e21b7ca9ecab8f3ff"}, {file = "PyNaCl-1.4.0-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:d452a6746f0a7e11121e64625109bc4468fc3100452817001dbe018bb8b08514"}, diff --git a/pyproject.toml b/pyproject.toml index da3e0aa..2f6cdcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "redisbench-admin" -version = "0.1.59" +version = "0.1.60" description = "Redis benchmark run helper. A wrapper around Redis and Redis Modules benchmark tools ( ftsb_redisearch, memtier_benchmark, redis-benchmark, aibench, etc... )." authors = ["filipecosta90 "] readme = "README.md" @@ -32,6 +32,7 @@ pytest = "^4.6" pytest-cov = "^2.9.0" codecov = "^2.1.4" black = "^20.8b1" +flake8 = "^3.9.1" [build-system] requires = ["poetry>=0.12"] diff --git a/redisbench_admin/cli.py b/redisbench_admin/cli.py index 7b13182..26a818e 100644 --- a/redisbench_admin/cli.py +++ b/redisbench_admin/cli.py @@ -39,10 +39,10 @@ def populate_with_poetry_data(): def main(): - tool = None if len(sys.argv) < 2: print( - "A minimum of 2 arguments is required: redisbench-admin . Use redisbench-admin --help if you need further assistance." + "A minimum of 2 arguments is required: redisbench-admin ." + " Use redisbench-admin --help if you need further assistance." ) sys.exit(1) requested_tool = sys.argv[1] diff --git a/redisbench_admin/export/args.py b/redisbench_admin/export/args.py index 4d00f09..628af73 100644 --- a/redisbench_admin/export/args.py +++ b/redisbench_admin/export/args.py @@ -21,7 +21,8 @@ def create_export_arguments(parser): "--results-format", type=str, default="redis-benchmark", - help="results format of the the benchmark results files to read results from ( either memtier_benchmark, redis-benchmark, or ftsb_redisearch )", + help="results format of the the benchmark results files to read " + "results from ( either memtier_benchmark, redis-benchmark, or ftsb_redisearch )", ) parser.add_argument( "--use-result", diff --git a/redisbench_admin/export/common/common.py b/redisbench_admin/export/common/common.py index 6c57763..44a9887 100644 --- a/redisbench_admin/export/common/common.py +++ b/redisbench_admin/export/common/common.py @@ -56,7 +56,6 @@ def split_tags_string(extra_tags): def split_key_metrics_by_step(key_metrics_specs): key_metrics_by_step = {} for key_metric_spec in key_metrics_specs: - step = None if "step" in key_metric_spec and "metric-name" in key_metric_spec: step = key_metric_spec["step"] metric_name = key_metric_spec["metric-name"] @@ -66,10 +65,10 @@ def split_key_metrics_by_step(key_metrics_specs): return key_metrics_by_step -def get_or_none(dict, property): +def get_or_none(dictionary, prop: str): result = None - if property in dict: - result = dict[property] + if prop in dictionary: + result = dictionary[prop] return result diff --git a/redisbench_admin/export/export.py b/redisbench_admin/export/export.py index 05b98ec..659c47a 100644 --- a/redisbench_admin/export/export.py +++ b/redisbench_admin/export/export.py @@ -16,10 +16,7 @@ def export_command_logic(args): benchmark_files = args.benchmark_result_files local_path = os.path.abspath(args.local_dir) results_format = args.results_format - use_result = args.use_result - included_steps = args.steps.split(",") input_tags_json = args.input_tags_json - start_time_ms = None extra_tags_array = split_tags_string(args.extra_tags) if input_tags_json != "": @@ -37,13 +34,9 @@ def export_command_logic(args): benchmark_results = retrieve_local_or_remote_input_json( benchmark_files, local_path, "--benchmark-result-files", "csv" ) - for filename, benchmark_result in benchmark_results.items(): + for _, benchmark_result in benchmark_results.items(): ok, time_series_dict = redis_benchmark_export_logic( - benchmark_result, - extra_tags_array, - results_type, - time_series_dict, - use_result, + benchmark_result, extra_tags_array, results_type, time_series_dict ) elif results_format == "memtier_benchmark": @@ -58,7 +51,7 @@ def export_command_logic(args): for timeseries_name, time_series in time_series_dict.items(): try: rts.create(timeseries_name, labels=time_series["tags"]) - except redis.exceptions.ResponseError as e: + except redis.exceptions.ResponseError: # if ts already exists continue pass for pos, timestamp in enumerate(time_series["index"]): diff --git a/redisbench_admin/export/redis_benchmark/redis_benchmark_csv_format.py b/redisbench_admin/export/redis_benchmark/redis_benchmark_csv_format.py index 55dbdf3..8a7ef79 100644 --- a/redisbench_admin/export/redis_benchmark/redis_benchmark_csv_format.py +++ b/redisbench_admin/export/redis_benchmark/redis_benchmark_csv_format.py @@ -11,21 +11,22 @@ ) -def warn_if_tag_none(tagName, tagValue, tool, level="Warning"): - if tagValue is None: +def warn_if_tag_none(tag_name, tag_value, tool, level="Warning"): + if tag_value is None: print( - '{}! The tag "{}" is None. Given that {} cannot infer it you should pass it via --extra-tags {}='.format( - level, tagName, tool, tagName + '{}! The tag "{}" is None. Given that {} cannot infer' + " it you should pass it via --extra-tags {}=".format( + level, tag_name, tool, tag_name ) ) -def get_tag_fromextra_tags_array(array, tagName): +def get_tag_fromextra_tags_array(array, tag_name): result = None - for innerDict in array: - inneResult = get_or_none(innerDict, tagName) - if inneResult is not None: - result = inneResult + for inner_dict in array: + inne_result = get_or_none(inner_dict, tag_name) + if inne_result is not None: + result = inne_result return result @@ -50,7 +51,7 @@ def fill_tags_from_passed_array(extra_tags_array): def redis_benchmark_export_logic( - benchmark_result, extra_tags_array, results_type, time_series_dict, use_result + benchmark_result, extra_tags_array, results_type, time_series_dict ): ok = True start_time_ms = get_tag_fromextra_tags_array(extra_tags_array, "start_time_ms") @@ -75,7 +76,6 @@ def redis_benchmark_export_logic( step, ) = fill_tags_from_passed_array(extra_tags_array) - metrics = {} col0_row0 = benchmark_result["col_0"][0] # new format # "test","rps","avg_latency_ms","min_latency_ms","p50_latency_ms","p95_latency_ms","p99_latency_ms","max_latency_ms" diff --git a/redisbench_admin/extract/args.py b/redisbench_admin/extract/args.py index bc088ef..6cbfd57 100644 --- a/redisbench_admin/extract/args.py +++ b/redisbench_admin/extract/args.py @@ -21,7 +21,8 @@ def create_extract_arguments(parser): "--upload-results-s3", default=False, action="store_true", - help="uploads the result files and configuration file to public benchmarks.redislabs bucket. Proper credentials are required", + help="uploads the result files and configuration file to public " + "'benchmarks.redislabs' bucket. Proper credentials are required", ) parser.add_argument( "--cluster-mode", diff --git a/redisbench_admin/run/common.py b/redisbench_admin/run/common.py index 2bc57e3..b0af3e8 100644 --- a/redisbench_admin/run/common.py +++ b/redisbench_admin/run/common.py @@ -5,10 +5,10 @@ import yaml from redisbench_admin.run.redis_benchmark.redis_benchmark import ( - prepareRedisBenchmarkCommand, + prepare_redis_benchmark_command, ) from redisbench_admin.run.redisgraph_benchmark_go.redisgraph_benchmark_go import ( - prepareRedisGraphBenchmarkGoCommand, + prepare_redisgraph_benchmark_go_command, ) from redisbench_admin.run.ycsb.ycsb import prepare_ycsb_benchmark_command from redisbench_admin.utils.benchmark_config import ( @@ -17,12 +17,12 @@ parse_exporter_timemetric, ) from redisbench_admin.utils.remote import ( - executeRemoteCommands, - getFileFromRemoteSetup, - extractRedisGraphVersion, - extractPerVersionTimeSeriesFromResults, - pushDataToRedisTimeSeries, - extractPerBranchTimeSeriesFromResults, + execute_remote_commands, + fetch_file_from_remote_setup, + extract_redisgraph_version_from_resultdict, + extract_perversion_timeseries_from_results, + push_data_to_redistimeseries, + extract_perbranch_timeseries_from_results, ) @@ -41,11 +41,12 @@ def extract_benchmark_tool_settings(benchmark_config): benchmark_tool_source = entry["tool_source"] if "min-tool-version" in entry: benchmark_min_tool_version = entry["min-tool-version"] - p = re.compile("(\\d+)\.(\\d+)\.(\\d+)") + p = re.compile(r"(\d+)\.(\d+)\.(\d+)") m = p.match(benchmark_min_tool_version) if m is None: logging.error( - "Unable to extract semversion from 'min-tool-version'. Will not enforce version" + "Unable to extract semversion from 'min-tool-version'." + " Will not enforce version" ) benchmark_min_tool_version = None else: @@ -71,10 +72,12 @@ def prepare_benchmark_parameters( isremote=False, current_workdir=None, ): + command_arr = None + command_str = None for entry in benchmark_config["clientconfig"]: if "parameters" in entry: if "redis-benchmark" in benchmark_tool: - command_arr, command_str = prepareRedisBenchmarkCommand( + command_arr, command_str = prepare_redis_benchmark_command( benchmark_tool, server_private_ip, server_plaintext_port, entry ) redirect_file = ">{}".format(remote_results_file) @@ -84,7 +87,7 @@ def prepare_benchmark_parameters( if "redisgraph-benchmark-go" in benchmark_tool: if isremote is True: benchmark_tool = "/tmp/redisgraph-benchmark-go" - command_arr, command_str = prepareRedisGraphBenchmarkGoCommand( + command_arr, command_str = prepare_redisgraph_benchmark_go_command( benchmark_tool, server_private_ip, server_plaintext_port, @@ -118,7 +121,7 @@ def run_remote_benchmark( command, ): remote_run_result = False - res = executeRemoteCommands(client_public_ip, username, private_key, [command]) + res = execute_remote_commands(client_public_ip, username, private_key, [command]) recv_exit_status, stdout, stderr = res[0] if recv_exit_status != 0: @@ -127,18 +130,18 @@ def run_remote_benchmark( recv_exit_status ) ) - logging.error("remote process stdout: ".format(stdout)) - logging.error("remote process stderr: ".format(stderr)) + logging.error("remote process stdout: {}".format(stdout)) + logging.error("remote process stderr: {}".format(stderr)) else: logging.info( "Remote process exited normally. Exit code {}. Printing stdout.".format( recv_exit_status ) ) - logging.info("remote process stdout: ".format(stdout)) + logging.info("remote process stdout: {}".format(stdout)) logging.info("Extracting the benchmark results") remote_run_result = True - getFileFromRemoteSetup( + fetch_file_from_remote_setup( client_public_ip, username, private_key, @@ -162,23 +165,23 @@ def merge_default_and_specific_properties_dict_type( ) ) else: + usecase_kpi = None use_case_specific_properties = benchmark_config[propertygroup_keyname] for default_property in default_properties: default_rule, default_details = list(default_property.items())[0] default_condition = list(default_details.values())[0] comparison_key = "{}{}".format(default_rule, default_condition) found = False - found_details = None for usecase_kpi in use_case_specific_properties: usecase_rule, usecase_details = list(usecase_kpi.items())[0] usecase_condition = list(usecase_details.values())[0] usecase_comparison_key = "{}{}".format(usecase_rule, usecase_condition) if comparison_key == usecase_comparison_key: found = True - found_details = usecase_details if found: logging.info( - "Skipping to add default '{}' property ({}) given the file {} had the same specific property ({})".format( + "Skipping to add default '{}' property ({}) given the file {}" + " had the same specific property ({})".format( propertygroup_keyname, default_property, usecase_filename, @@ -202,7 +205,8 @@ def process_default_yaml_properties_file( default_metrics = parse_exporter_metrics_definition(default_config["exporter"]) if len(default_metrics) > 0: logging.info( - "Found RedisTimeSeries default metrics specification. Will include the following metrics on all benchmarks {}".format( + "Found RedisTimeSeries default metrics specification." + " Will include the following metrics on all benchmarks {}".format( " ".join(default_metrics) ) ) @@ -211,7 +215,8 @@ def process_default_yaml_properties_file( ) if exporter_timemetric_path is not None: logging.info( - "Found RedisTimeSeries default time metric specification. Will use the following JSON path to retrieve the test time {}".format( + "Found RedisTimeSeries default time metric specification." + " Will use the following JSON path to retrieve the test time {}".format( exporter_timemetric_path ) ) @@ -243,12 +248,15 @@ def common_exporter_logic( exporter_timemetric_path, results_dict ) - rg_version = extractRedisGraphVersion(results_dict) + rg_version = extract_redisgraph_version_from_resultdict(results_dict) if rg_version is None: rg_version = "N/A" # extract per branch datapoints - (ok, per_version_time_series_dict,) = extractPerVersionTimeSeriesFromResults( + ( + ok, + per_version_time_series_dict, + ) = extract_perversion_timeseries_from_results( datapoints_timestamp, metrics, results_dict, @@ -261,10 +269,10 @@ def common_exporter_logic( ) # push per-branch data - pushDataToRedisTimeSeries(rts, per_version_time_series_dict) + push_data_to_redistimeseries(rts, per_version_time_series_dict) if tf_github_branch is not None and tf_github_branch != "": # extract per branch datapoints - ok, branch_time_series_dict = extractPerBranchTimeSeriesFromResults( + ok, branch_time_series_dict = extract_perbranch_timeseries_from_results( datapoints_timestamp, metrics, results_dict, @@ -276,20 +284,24 @@ def common_exporter_logic( tf_triggering_env, ) # push per-branch data - pushDataToRedisTimeSeries(rts, branch_time_series_dict) + push_data_to_redistimeseries(rts, branch_time_series_dict) else: logging.warning( - "Requested to push data to RedisTimeSeries but no git branch definition was found. git branch value {}".format( + "Requested to push data to RedisTimeSeries but no git" + " branch definition was found. git branch value {}".format( tf_github_branch ) ) else: logging.error( - 'Requested to push data to RedisTimeSeries but no exporter definition was found. Missing "exporter" config.' + "Requested to push data to RedisTimeSeries but " + 'no exporter definition was found. Missing "exporter" config.' ) -def get_start_time_vars(start_time=dt.datetime.utcnow()): +def get_start_time_vars(start_time=None): + if start_time is None: + start_time = dt.datetime.utcnow() start_time_ms = int((start_time - dt.datetime(1970, 1, 1)).total_seconds() * 1000) start_time_str = start_time.strftime("%Y-%m-%d-%H-%M-%S") return start_time, start_time_ms, start_time_str diff --git a/redisbench_admin/run/redis_benchmark/redis_benchmark.py b/redisbench_admin/run/redis_benchmark/redis_benchmark.py index 4fccc77..cf97a2b 100644 --- a/redisbench_admin/run/redis_benchmark/redis_benchmark.py +++ b/redisbench_admin/run/redis_benchmark/redis_benchmark.py @@ -4,11 +4,11 @@ import shlex import subprocess -from redisbench_admin.utils.remote import executeRemoteCommands +from redisbench_admin.utils.remote import execute_remote_commands def redis_benchmark_from_stdout_csv_to_json( - csv_data, start_time_ms, start_time_str, overloadTestName=None + csv_data, start_time_ms, start_time_str, overload_test_name=None ): results_dict = { "Tests": {}, @@ -19,15 +19,15 @@ def redis_benchmark_from_stdout_csv_to_json( header = csv_data[0] for row in csv_data[1:]: test_name = row[0] - if overloadTestName is not None: - test_name = overloadTestName + if overload_test_name is not None: + test_name = overload_test_name results_dict["Tests"][test_name] = {} for pos, value in enumerate(row[1:]): results_dict["Tests"][test_name][header[pos + 1]] = value return results_dict -def prepareRedisBenchmarkCommand( +def prepare_redis_benchmark_command( executable_path: str, server_private_ip: object, server_plaintext_port: object, @@ -35,12 +35,13 @@ def prepareRedisBenchmarkCommand( ): """ Prepares redis-benchmark command parameters + :param executable_path: :param server_private_ip: :param server_plaintext_port: :param benchmark_config: - :return: [string] containing the required command to run the benchmark given the configurations + :return: [string] containing the required command to run + the benchmark given the configurations """ - command_str = "" command_arr = [executable_path] command_arr.extend(["-h", "{}".format(server_private_ip)]) command_arr.extend(["-p", "{}".format(server_plaintext_port)]) @@ -48,6 +49,7 @@ def prepareRedisBenchmarkCommand( # we need the csv output command_arr.extend(["--csv", "-e"]) last_append = None + last_str = "" for k in benchmark_config["parameters"]: if "clients" in k: command_arr.extend(["-c", "{}".format(k["clients"])]) @@ -66,9 +68,8 @@ def prepareRedisBenchmarkCommand( command_arr.extend(last_append) command_str = command_str + " " + last_str logging.info( - "Running the benchmark with the following parameters:\n\tArgs array: {}\n\tArgs str: {}".format( - command_arr, command_str - ) + "Running the benchmark with the following parameters:" + "\n\tArgs array: {}\n\tArgs str: {}".format(command_arr, command_str) ) return command_arr, command_str @@ -87,7 +88,7 @@ def ensure_redis_benchmark_version_from_input( benchmark_tool, version_output ) ) - p = re.compile("redis-benchmark (\d+)\.(\d+)\.(\d+) ") + p = re.compile(r"redis-benchmark (\d+)\.(\d+)\.(\d+)") m = p.match(version_output) if m is None: raise Exception( @@ -150,7 +151,7 @@ def redis_benchmark_ensure_min_version_remote( username, private_key, ): - res = executeRemoteCommands( + res = execute_remote_commands( client_public_ip, username, private_key, ["{} --version".format(benchmark_tool)] ) recv_exit_status, stdout, stderr = res[0] diff --git a/redisbench_admin/run/redisgraph_benchmark_go/redisgraph_benchmark_go.py b/redisbench_admin/run/redisgraph_benchmark_go/redisgraph_benchmark_go.py index 0ec53f7..c6c9d0b 100644 --- a/redisbench_admin/run/redisgraph_benchmark_go/redisgraph_benchmark_go.py +++ b/redisbench_admin/run/redisgraph_benchmark_go/redisgraph_benchmark_go.py @@ -1,7 +1,7 @@ import logging -def prepareRedisGraphBenchmarkGoCommand( +def prepare_redisgraph_benchmark_go_command( executable_path: str, server_private_ip: object, server_plaintext_port: object, @@ -11,10 +11,12 @@ def prepareRedisGraphBenchmarkGoCommand( ): """ Prepares redisgraph-benchmark-go command parameters + :param executable_path: :param server_private_ip: :param server_plaintext_port: :param benchmark_config: :param results_file: + :param is_remote: :return: string containing the required command to run the benchmark given the configurations """ queries_str = [executable_path] diff --git a/redisbench_admin/run/run.py b/redisbench_admin/run/run.py index da9f1bd..82d152f 100644 --- a/redisbench_admin/run/run.py +++ b/redisbench_admin/run/run.py @@ -2,12 +2,9 @@ def run_command_logic(args): - use_case_specific_arguments = dict(args.__dict__) + dict(args.__dict__) # local_path = os.path.abspath(args.local_dir) - is_remote_mode = args.remote - tool = args.tool benchmark_machine_info = cpuinfo.get_cpu_info() - total_cores = benchmark_machine_info["count"] benchmark_infra = { "total-benchmark-machines": 0, "benchmark-machines": {}, diff --git a/redisbench_admin/run/ycsb/ycsb.py b/redisbench_admin/run/ycsb/ycsb.py index 6fba29a..ec467f1 100644 --- a/redisbench_admin/run/ycsb/ycsb.py +++ b/redisbench_admin/run/ycsb/ycsb.py @@ -1,6 +1,3 @@ -import logging - - def prepare_ycsb_benchmark_command( executable_path: str, server_private_ip: object, @@ -10,9 +7,11 @@ def prepare_ycsb_benchmark_command( ): """ Prepares ycsb command parameters + :param executable_path: :param server_private_ip: :param server_plaintext_port: :param benchmark_config: + :param current_workdir: :return: [string] containing the required command to run the benchmark given the configurations """ command_arr = [executable_path] @@ -48,8 +47,8 @@ def prepare_ycsb_benchmark_command( command_arr.extend(["-p", '"redis.port={}"'.format(server_plaintext_port)]) - for property in override_workload_properties: - for k, v in property.items(): + for prop in override_workload_properties: + for k, v in prop.items(): if type(v) == str and v.startswith("./"): v = "{}{}".format(current_workdir, v[1:]) command_arr.extend(["-p", '"{}={}"'.format(k, v)]) diff --git a/redisbench_admin/run_local/run_local.py b/redisbench_admin/run_local/run_local.py index 500e36b..2e5db12 100644 --- a/redisbench_admin/run_local/run_local.py +++ b/redisbench_admin/run_local/run_local.py @@ -1,5 +1,4 @@ import json -import json import logging import os import pathlib @@ -31,7 +30,7 @@ ) from redisbench_admin.utils.remote import ( extract_git_vars, - validateResultExpectations, + validate_result_expectations, ) from redisbench_admin.utils.utils import decompress_file, get_decompressed_filename @@ -47,7 +46,7 @@ def run_local_command_logic(args): ) = extract_git_vars() local_module_file = args.module_path - current_workdir = os.path.abspath(".") + os.path.abspath(".") logging.info("Retrieved the following local info:") logging.info("\tgithub_actor: {}".format(github_actor)) @@ -57,7 +56,6 @@ def run_local_command_logic(args): logging.info("\tgithub_sha: {}".format(github_sha)) return_code = 0 - files = [] default_metrics = [] exporter_timemetric_path = None defaults_filename = "defaults.yml" @@ -96,7 +94,7 @@ def run_local_command_logic(args): for usecase_filename in files: with open(usecase_filename, "r") as stream: - dirname = os.path.dirname(os.path.abspath(usecase_filename)) + os.path.dirname(os.path.abspath(usecase_filename)) redis_process = None benchmark_config = yaml.safe_load(stream) kpis_keyname = "kpis" @@ -108,11 +106,11 @@ def run_local_command_logic(args): test_name = benchmark_config["name"] # after we've spinned Redis, even on error we should always teardown # in case of some unexpected error we fail the test + # noinspection PyBroadException try: dirname = (".",) # setup Redis # copy the rdb to DB machine - dataset = None temporary_dir = tempfile.mkdtemp() logging.info( "Using local temporary dir to spin up Redis Instance. Path: {}".format( @@ -180,7 +178,7 @@ def run_local_command_logic(args): results_dict = json.load(json_file) if "kpis" in benchmark_config: - result = validateResultExpectations( + result = validate_result_expectations( benchmark_config, results_dict, result, expectations_key="kpis" ) if result is not True: @@ -228,7 +226,7 @@ def post_process_benchmark_results( stdout.decode("ascii"), start_time_ms, start_time_str, - overloadTestName="Overall", + overload_test_name="Overall", ) with open(local_benchmark_output_filename, "w") as json_file: json.dump(results_dict, json_file, indent=True) @@ -339,7 +337,6 @@ def which_local(benchmark_tool, executable, full_path, which_benchmark_tool): return which_benchmark_tool for dir_file_triple in os.walk(full_path): current_dir = dir_file_triple[0] - inner_dirs = dir_file_triple[1] inner_files = dir_file_triple[2] for filename in inner_files: full_path_filename = "{}/{}".format(current_dir, filename) diff --git a/redisbench_admin/run_remote/args.py b/redisbench_admin/run_remote/args.py index 58e54a2..308e0a7 100644 --- a/redisbench_admin/run_remote/args.py +++ b/redisbench_admin/run_remote/args.py @@ -40,7 +40,8 @@ def create_run_remote_arguments(parser): "--upload_results_s3", default=False, action="store_true", - help="uploads the result files and configuration file to public ci.benchmarks.redislabs bucket. Proper credentials are required", + help="uploads the result files and configuration file to public " + "'ci.benchmarks.redislabs' bucket. Proper credentials are required", ) parser.add_argument("--redistimesies_host", type=str, default=PERFORMANCE_RTS_HOST) parser.add_argument("--redistimesies_port", type=int, default=PERFORMANCE_RTS_PORT) diff --git a/redisbench_admin/run_remote/run_remote.py b/redisbench_admin/run_remote/run_remote.py index 24d933a..1d39e33 100644 --- a/redisbench_admin/run_remote/run_remote.py +++ b/redisbench_admin/run_remote/run_remote.py @@ -27,21 +27,25 @@ parse_exporter_timemetric_definition, ) from redisbench_admin.utils.redisgraph_benchmark_go import ( - spinUpRemoteRedis, - setupRemoteBenchmarkTool_redisgraph_benchmark_go, + spin_up_standalone_remote_redis, + setup_remote_benchmark_tool_redisgraph_benchmark_go, ) from redisbench_admin.utils.remote import ( extract_git_vars, - validateResultExpectations, + validate_result_expectations, upload_artifacts_to_s3, - setupRemoteEnviroment, - checkAndFixPemStr, + setup_remote_environment, + check_and_fix_pem_str, get_run_full_filename, - fetchRemoteSetupFromConfig, + fetch_remote_setup_from_config, ) # internal aux vars -redisbenchmark_go_link = "https://s3.amazonaws.com/benchmarks.redislabs/redisgraph/redisgraph-benchmark-go/unstable/redisgraph-benchmark-go_linux_amd64" +redisbenchmark_go_link = ( + "https://s3.amazonaws.com/benchmarks.redislabs/" + "redisgraph/redisgraph-benchmark-go/unstable/" + "redisgraph-benchmark-go_linux_amd64" +) remote_dataset_file = "/tmp/dump.rdb" remote_module_file = "/tmp/module.so" local_results_file = "./benchmark-result.out" @@ -59,6 +63,7 @@ EC2_PRIVATE_PEM = os.getenv("EC2_PRIVATE_PEM", None) +# noinspection PyBroadException def run_remote_command_logic(args): tf_bin_path = args.terraform_bin_path tf_github_org = args.github_org @@ -183,7 +188,8 @@ def run_remote_command_logic(args): logging.info("\tgithub_branch: {}".format(tf_github_branch)) if tf_github_branch is None or tf_github_branch == "": logging.error( - "The github branch information is not present! This implies that per-branch data is not pushed to the exporters!" + "The github branch information is not present!" + " This implies that per-branch data is not pushed to the exporters!" ) logging.info("\tgithub_sha: {}".format(tf_github_sha)) logging.info("\ttriggering env: {}".format(tf_triggering_env)) @@ -191,7 +197,7 @@ def run_remote_command_logic(args): logging.info("\tsetup_name sufix: {}".format(tf_setup_name_sufix)) with open(private_key, "w") as tmp_private_key_file: - pem_str = checkAndFixPemStr(EC2_PRIVATE_PEM) + pem_str = check_and_fix_pem_str(EC2_PRIVATE_PEM) tmp_private_key_file.write(pem_str) if os.path.exists(private_key) is False: @@ -205,8 +211,6 @@ def run_remote_command_logic(args): ) return_code = 0 - - files = [] if args.test == "": files = pathlib.Path().glob("*.yml") files = [str(x) for x in files] @@ -257,12 +261,12 @@ def run_remote_command_logic(args): github_repo=tf_github_repo, test_name=test_name, ) - s3_uri = "https://s3.amazonaws.com/{bucket_name}/{bucket_path}".format( + "https://s3.amazonaws.com/{bucket_name}/{bucket_path}".format( bucket_name=s3_bucket_name, bucket_path=s3_bucket_path ) if "remote" in benchmark_config: - remote_setup, deployment_type = fetchRemoteSetupFromConfig( + remote_setup, deployment_type = fetch_remote_setup_from_config( benchmark_config["remote"] ) logging.info( @@ -285,7 +289,7 @@ def run_remote_command_logic(args): server_plaintext_port, client_private_ip, client_public_ip, - ) = setupRemoteEnviroment( + ) = setup_remote_environment( tf, tf_github_sha, tf_github_actor, @@ -298,7 +302,7 @@ def run_remote_command_logic(args): # in case of some unexpected error we fail the test try: # setup Redis - spinUpRemoteRedis( + spin_up_standalone_remote_redis( benchmark_config, server_public_ip, username, @@ -333,7 +337,7 @@ def run_remote_command_logic(args): ) # setup the benchmark tool if benchmark_tool == "redisgraph-benchmark-go": - setupRemoteBenchmarkTool_redisgraph_benchmark_go( + setup_remote_benchmark_tool_redisgraph_benchmark_go( client_public_ip, username, private_key, @@ -406,19 +410,18 @@ def run_remote_command_logic(args): csv_data, start_time_ms, start_time_str, - overloadTestName="Overall", + overload_test_name="Overall", ) with open(local_benchmark_output_filename, "w") as json_file: json.dump(results_dict, json_file, indent=True) # check KPIs result = True - results_dict = None with open(local_benchmark_output_filename, "r") as json_file: results_dict = json.load(json_file) if "kpis" in benchmark_config: - result = validateResultExpectations( + result = validate_result_expectations( benchmark_config, results_dict, result, @@ -475,7 +478,8 @@ def run_remote_command_logic(args): except: return_code |= 1 logging.critical( - "Some unexpected exception was caught during remote work. Failing test...." + "Some unexpected exception was caught " + "during remote work. Failing test...." ) logging.critical(sys.exc_info()[0]) print("-" * 60) @@ -484,7 +488,7 @@ def run_remote_command_logic(args): finally: # tear-down logging.info("Tearing down setup") - tf_output = tf.destroy() + tf.destroy() logging.info("Tear-down completed") exit(return_code) diff --git a/redisbench_admin/utils/local.py b/redisbench_admin/utils/local.py index 85e223a..3ebc4cf 100644 --- a/redisbench_admin/utils/local.py +++ b/redisbench_admin/utils/local.py @@ -54,7 +54,6 @@ def check_dataset_local_requirements( def wait_for_conn(conn, retries=20, command="PING", should_be=True): """Wait until a given Redis connection is ready""" result = False - err1 = "" while retries > 0 and result is False: try: if conn.execute_command(command) == should_be: @@ -62,7 +61,7 @@ def wait_for_conn(conn, retries=20, command="PING", should_be=True): except redis.exceptions.BusyLoadingError: time.sleep(0.1) # give extra 100msec in case of RDB loading except redis.ConnectionError as err: - err1 = str(err) + str(err) except redis.ResponseError as err: err1 = str(err) if not err1.startswith("DENIED"): diff --git a/redisbench_admin/utils/redisearch.py b/redisbench_admin/utils/redisearch.py index af0ee04..ae0f755 100644 --- a/redisbench_admin/utils/redisearch.py +++ b/redisbench_admin/utils/redisearch.py @@ -4,7 +4,8 @@ def check_and_extract_redisearch_info(redis_url): - server_info = None + redisearch_git_sha = None + redisearch_version = None print("Checking RediSearch is reachable at {}".format(redis_url)) try: found_redisearch = False diff --git a/redisbench_admin/utils/redisgraph_benchmark_go.py b/redisbench_admin/utils/redisgraph_benchmark_go.py index 63c0186..5992ddd 100644 --- a/redisbench_admin/utils/redisgraph_benchmark_go.py +++ b/redisbench_admin/utils/redisgraph_benchmark_go.py @@ -1,11 +1,11 @@ from redisbench_admin.utils.remote import ( - checkDatasetRemoteRequirements, - copyFileToRemoteSetup, - executeRemoteCommands, + check_dataset_remote_requirements, + copy_file_to_remote_setup, + execute_remote_commands, ) -def spinUpRemoteRedis( +def spin_up_standalone_remote_redis( benchmark_config, server_public_ip, username, @@ -15,10 +15,8 @@ def spinUpRemoteRedis( remote_dataset_file, dirname=".", ): - res = False # copy the rdb to DB machine - dataset = None - checkDatasetRemoteRequirements( + check_dataset_remote_requirements( benchmark_config, server_public_ip, username, @@ -28,10 +26,10 @@ def spinUpRemoteRedis( ) # copy the module to the DB machine - copyFileToRemoteSetup( + copy_file_to_remote_setup( server_public_ip, username, private_key, local_module_file, remote_module_file ) - executeRemoteCommands( + execute_remote_commands( server_public_ip, username, private_key, @@ -43,14 +41,14 @@ def spinUpRemoteRedis( remote_module_file ) ] - executeRemoteCommands(server_public_ip, username, private_key, commands) + execute_remote_commands(server_public_ip, username, private_key, commands) -def setupRemoteBenchmarkTool_redisgraph_benchmark_go( +def setup_remote_benchmark_tool_redisgraph_benchmark_go( client_public_ip, username, private_key, redisbenchmark_go_link ): commands = [ "wget {} -q -O /tmp/redisgraph-benchmark-go".format(redisbenchmark_go_link), "chmod 755 /tmp/redisgraph-benchmark-go", ] - executeRemoteCommands(client_public_ip, username, private_key, commands) + execute_remote_commands(client_public_ip, username, private_key, commands) diff --git a/redisbench_admin/utils/remote.py b/redisbench_admin/utils/remote.py index 232bbf5..2f5bd53 100644 --- a/redisbench_admin/utils/remote.py +++ b/redisbench_admin/utils/remote.py @@ -9,7 +9,7 @@ import paramiko import pysftp import redis -import redistimeseries.client as Client +import redistimeseries.client as client from git import Repo from jsonpath_ng import parse from python_terraform import Terraform @@ -24,16 +24,15 @@ def get_git_root(path): return git_root -def viewBarSimple(a, b): +def view_bar_simple(a, b): res = a / int(b) * 100 sys.stdout.write("\r Complete precent: %.2f %%" % res) sys.stdout.flush() -def copyFileToRemoteSetup( +def copy_file_to_remote_setup( server_public_ip, username, private_key, local_file, remote_file, dirname=None ): - res = False full_local_path = local_file if dirname is not None: full_local_path = "{}/{}".format(dirname, local_file) @@ -54,7 +53,7 @@ def copyFileToRemoteSetup( private_key=private_key, cnopts=cnopts, ) - srv.put(full_local_path, remote_file, callback=viewBarSimple) + srv.put(full_local_path, remote_file, callback=view_bar_simple) srv.close() logging.info( "Finished Copying file {} to remote server {} ".format( @@ -69,11 +68,10 @@ def copyFileToRemoteSetup( raise Exception( "Local file {} does not exists. aborting...".format(full_local_path) ) - res = False return res -def getFileFromRemoteSetup( +def fetch_file_from_remote_setup( server_public_ip, username, private_key, local_file, remote_file ): logging.info( @@ -86,7 +84,7 @@ def getFileFromRemoteSetup( srv = pysftp.Connection( host=server_public_ip, username=username, private_key=private_key, cnopts=cnopts ) - srv.get(remote_file, local_file, callback=viewBarSimple) + srv.get(remote_file, local_file, callback=view_bar_simple) srv.close() logging.info( "Finished retrieving remote file {} from remote server {} ".format( @@ -95,7 +93,7 @@ def getFileFromRemoteSetup( ) -def executeRemoteCommands(server_public_ip, username, private_key, commands): +def execute_remote_commands(server_public_ip, username, private_key, commands): res = [] k = paramiko.RSAKey.from_private_key_file(private_key) c = paramiko.SSHClient() @@ -114,7 +112,7 @@ def executeRemoteCommands(server_public_ip, username, private_key, commands): return res -def checkDatasetRemoteRequirements( +def check_dataset_remote_requirements( benchmark_config, server_public_ip, username, @@ -132,7 +130,7 @@ def checkDatasetRemoteRequirements( dataset ) ) - res = copyFileToRemoteSetup( + res = copy_file_to_remote_setup( server_public_ip, username, private_key, @@ -143,7 +141,7 @@ def checkDatasetRemoteRequirements( return res -def setupRemoteEnviroment( +def setup_remote_environment( tf: Terraform, tf_github_sha, tf_github_actor, @@ -153,13 +151,13 @@ def setupRemoteEnviroment( tf_triggering_env, ): # key = "benchmarks/infrastructure/tf-oss-redisgraph-standalone-r5.tfstate" - return_code, stdout, stderr = tf.init( + _, _, _ = tf.init( capture_output=True, backend_config={ "key": "benchmarks/infrastructure/{}.tfstate".format(tf_setup_name) }, ) - return_code, stdout, stderr = tf.refresh() + _, _, _ = tf.refresh() tf_output = tf.output() server_private_ip = tf_output["server_private_ip"]["value"][0] server_public_ip = tf_output["server_public_ip"]["value"][0] @@ -204,7 +202,9 @@ def setupRemoteEnviroment( ) -def extract_git_vars(path=get_git_root("."), github_url=None): +def extract_git_vars(path=None, github_url=None): + if path is None: + path = get_git_root(".") github_repo = Repo(path) if github_url is None: github_url = github_repo.remotes[0].config_reader.get("url") @@ -250,7 +250,7 @@ def extract_git_vars(path=get_git_root("."), github_url=None): ) -def validateResultExpectations( +def validate_result_expectations( benchmark_config, results_dict, result, expectations_key="kpis" ): for expectation in benchmark_config[expectations_key]: @@ -329,19 +329,19 @@ def upload_artifacts_to_s3( s3 = boto3.resource("s3") bucket = s3.Bucket(s3_bucket_name) progress = tqdm(unit="files", total=len(artifacts)) - for input in artifacts: + for artifact in artifacts: object_key = "{bucket_path}{filename}".format( - bucket_path=s3_bucket_path, filename=input + bucket_path=s3_bucket_path, filename=artifact ) - bucket.upload_file(input, object_key) + bucket.upload_file(artifact, object_key) object_acl = s3.ObjectAcl(s3_bucket_name, object_key) - response = object_acl.put(ACL=acl) + object_acl.put(ACL=acl) progress.update() progress.close() -def checkAndFixPemStr(EC2_PRIVATE_PEM): - pem_str = EC2_PRIVATE_PEM.replace("-----BEGIN RSA PRIVATE KEY-----", "") +def check_and_fix_pem_str(ec2_private_pem: str): + pem_str = ec2_private_pem.replace("-----BEGIN RSA PRIVATE KEY-----", "") pem_str = pem_str.replace("-----END RSA PRIVATE KEY-----", "") pem_str = pem_str.replace(" ", "\n") pem_str = "-----BEGIN RSA PRIVATE KEY-----\n" + pem_str @@ -360,32 +360,35 @@ def get_run_full_filename( test_name, github_sha, ): - benchmark_output_filename = "{start_time_str}-{github_org}-{github_repo}-{github_branch}-{test_name}-{deployment_type}-{github_sha}.json".format( - start_time_str=start_time_str, - github_org=github_org, - github_repo=github_repo, - github_branch=github_branch, - test_name=test_name, - deployment_type=deployment_type, - github_sha=github_sha, + benchmark_output_filename = ( + "{start_time_str}-{github_org}-{github_repo}-{github_branch}" + "-{test_name}-{deployment_type}-{github_sha}.json".format( + start_time_str=start_time_str, + github_org=github_org, + github_repo=github_repo, + github_branch=github_branch, + test_name=test_name, + deployment_type=deployment_type, + github_sha=github_sha, + ) ) return benchmark_output_filename -def fetchRemoteSetupFromConfig( +def fetch_remote_setup_from_config( remote_setup_config, repo="https://github.com/RedisLabsModules/testing-infrastructure.git", branch="master", ): - type = None + setup_type = None setup = None for remote_setup_property in remote_setup_config: if "type" in remote_setup_property: - type = remote_setup_property["type"] + setup_type = remote_setup_property["type"] if "setup" in remote_setup_property: setup = remote_setup_property["setup"] # fetch terraform folder - path = "/terraform/{}-{}".format(type, setup) + path = "/terraform/{}-{}".format(setup_type, setup) temporary_dir = tempfile.mkdtemp() logging.info( "Fetching infrastructure definition from git repo {}/{} (branch={})".format( @@ -394,10 +397,10 @@ def fetchRemoteSetupFromConfig( ) git.Repo.clone_from(repo, temporary_dir, branch=branch, depth=1) terraform_working_dir = temporary_dir + path - return terraform_working_dir, type + return terraform_working_dir, setup_type -def pushDataToRedisTimeSeries(rts: Client, branch_time_series_dict: dict): +def push_data_to_redistimeseries(rts: client, branch_time_series_dict: dict): datapoint_errors = 0 datapoint_inserts = 0 for timeseries_name, time_series in branch_time_series_dict.items(): @@ -408,7 +411,7 @@ def pushDataToRedisTimeSeries(rts: Client, branch_time_series_dict: dict): ) ) rts.create(timeseries_name, labels=time_series["labels"]) - except redis.exceptions.ResponseError as e: + except redis.exceptions.ResponseError: logging.warning( "Timeseries named {} already exists".format(timeseries_name) ) @@ -433,7 +436,7 @@ def pushDataToRedisTimeSeries(rts: Client, branch_time_series_dict: dict): return datapoint_errors, datapoint_inserts -def extractRedisGraphVersion(results_dict: dict): +def extract_redisgraph_version_from_resultdict(results_dict: dict): version = None if "DBSpecificConfigs" in results_dict: if "RedisGraphVersion" in results_dict["DBSpecificConfigs"]: @@ -441,7 +444,7 @@ def extractRedisGraphVersion(results_dict: dict): return version -def extractPerVersionTimeSeriesFromResults( +def extract_perversion_timeseries_from_results( datapoints_timestamp: int, metrics: list, results_dict: dict, @@ -468,14 +471,18 @@ def extractPerVersionTimeSeriesFromResults( "triggering_env": tf_triggering_env, "metric": metric_name, } - ts_name = "ci.benchmarks.redislabs/by.version/{triggering_env}/{github_org}/{github_repo}/{test_name}/{deployment_type}/{version}/{metric}".format( - version=project_version, - github_org=tf_github_org, - github_repo=tf_github_repo, - deployment_type=deployment_type, - test_name=test_name, - triggering_env=tf_triggering_env, - metric=metric_name, + ts_name = ( + "ci.benchmarks.redislabs/by.version/" + "{triggering_env}/{github_org}/{github_repo}/" + "{test_name}/{deployment_type}/{version}/{metric}".format( + version=project_version, + github_org=tf_github_org, + github_repo=tf_github_repo, + deployment_type=deployment_type, + test_name=test_name, + triggering_env=tf_triggering_env, + metric=metric_name, + ) ) branch_time_series_dict[ts_name] = { @@ -485,7 +492,7 @@ def extractPerVersionTimeSeriesFromResults( return True, branch_time_series_dict -def extractPerBranchTimeSeriesFromResults( +def extract_perbranch_timeseries_from_results( datapoints_timestamp: int, metrics: list, results_dict: dict, @@ -512,14 +519,18 @@ def extractPerBranchTimeSeriesFromResults( "triggering_env": tf_triggering_env, "metric": metric_name, } - ts_name = "ci.benchmarks.redislabs/by.branch/{triggering_env}/{github_org}/{github_repo}/{test_name}/{deployment_type}/{branch}/{metric}".format( - branch=str(tf_github_branch), - github_org=tf_github_org, - github_repo=tf_github_repo, - deployment_type=deployment_type, - test_name=test_name, - triggering_env=tf_triggering_env, - metric=metric_name, + ts_name = ( + "ci.benchmarks.redislabs/by.branch/" + "{triggering_env}/{github_org}/{github_repo}/" + "{test_name}/{deployment_type}/{branch}/{metric}".format( + branch=str(tf_github_branch), + github_org=tf_github_org, + github_repo=tf_github_repo, + deployment_type=deployment_type, + test_name=test_name, + triggering_env=tf_triggering_env, + metric=metric_name, + ) ) branch_time_series_dict[ts_name] = { diff --git a/redisbench_admin/utils/results.py b/redisbench_admin/utils/results.py index 7e3f86d..6c1bc26 100644 --- a/redisbench_admin/utils/results.py +++ b/redisbench_admin/utils/results.py @@ -16,16 +16,18 @@ def get_key_results_and_values(results_json, step, use_result): return selected_run, metrics -def from_resultsDF_to_key_results_dict(resultsDataFrame, step, step_df_dict): - key_results_dict = {"table": json.loads(resultsDataFrame.to_json(orient="records"))} - best_result = resultsDataFrame.head(n=1) - worst_result = resultsDataFrame.tail(n=1) +def from_results_dataframe_to_key_results_dict(results_dataframe, step, step_df_dict): + key_results_dict = { + "table": json.loads(results_dataframe.to_json(orient="records")) + } + best_result = results_dataframe.head(n=1) + worst_result = results_dataframe.tail(n=1) first_sorting_col = step_df_dict[step]["sorting_metric_names"][0] - first_sorting_median = resultsDataFrame[first_sorting_col].median() + first_sorting_median = results_dataframe[first_sorting_col].median() result_index = ( - resultsDataFrame[first_sorting_col].sub(first_sorting_median).abs().idxmin() + results_dataframe[first_sorting_col].sub(first_sorting_median).abs().idxmin() ) - median_result = resultsDataFrame.loc[[result_index]] + median_result = results_dataframe.loc[[result_index]] key_results_dict["best-result"] = json.loads(best_result.to_json(orient="records")) key_results_dict["median-result"] = json.loads( median_result.to_json(orient="records") @@ -34,7 +36,7 @@ def from_resultsDF_to_key_results_dict(resultsDataFrame, step, step_df_dict): worst_result.to_json(orient="records") ) key_results_dict["reliability-analysis"] = { - "var": json.loads(resultsDataFrame.var().to_json()), - "stddev": json.loads(resultsDataFrame.std().to_json()), + "var": json.loads(results_dataframe.var().to_json()), + "stddev": json.loads(results_dataframe.std().to_json()), } return key_results_dict diff --git a/redisbench_admin/utils/utils.py b/redisbench_admin/utils/utils.py index 108e82e..226119a 100644 --- a/redisbench_admin/utils/utils.py +++ b/redisbench_admin/utils/utils.py @@ -21,13 +21,13 @@ def upload_artifacts_to_s3(artifacts, s3_bucket_name, s3_bucket_path): s3 = boto3.resource("s3") bucket = s3.Bucket(s3_bucket_name) progress = tqdm(unit="files", total=len(artifacts)) - for input in artifacts: + for artifact in artifacts: object_key = "{bucket_path}{filename}".format( - bucket_path=s3_bucket_path, filename=input + bucket_path=s3_bucket_path, filename=artifact ) - bucket.upload_file(input, object_key) + bucket.upload_file(artifact, object_key) object_acl = s3.ObjectAcl(s3_bucket_name, object_key) - response = object_acl.put(ACL="public-read") + object_acl.put(ACL="public-read") progress.update() progress.close() @@ -90,8 +90,8 @@ def decompress_file(compressed_filename: str, path=None): return uncompressed_filename -def find_json_path(element, json): - return reduce(operator.getitem, element.split("."), json) +def find_json_path(element, json_dict): + return reduce(operator.getitem, element.split("."), json_dict) def ts_milli(at_dt): @@ -99,10 +99,9 @@ def ts_milli(at_dt): def retrieve_local_or_remote_input_json( - config_filename, local_path, option_name, format="json", csv_header=False + config_filename, local_path, option_name, input_format="json", csv_header=False ): benchmark_config = {} - if config_filename.startswith("http"): print( "retrieving benchmark config file from remote url {}".format( @@ -111,7 +110,8 @@ def retrieve_local_or_remote_input_json( ) r = requests.get(config_filename) benchmark_config[config_filename] = r.json() - remote_filename = config_filename[config_filename.rfind("/") + 1 :] + filename_start_pos = config_filename.rfind("/") + 1 + remote_filename = config_filename[filename_start_pos:] local_config_file = "{}/{}".format(local_path, remote_filename) open(local_config_file, "wb").write(r.content) print( @@ -143,37 +143,41 @@ def retrieve_local_or_remote_input_json( my_bucket.download_file(object_summary.key, local_config_file) with open(local_config_file, "r") as local_file: read_json_or_csv( - benchmark_config, config_filename, format, local_file, csv_header + benchmark_config, + config_filename, + input_format, + local_file, + csv_header, ) else: with open(config_filename, "r") as local_file: read_json_or_csv( - benchmark_config, config_filename, format, local_file, csv_header + benchmark_config, config_filename, input_format, local_file, csv_header ) return benchmark_config def read_json_or_csv( - benchmark_config, config_filename, format, local_file, csv_has_header + benchmark_config, config_filename, read_format, local_file, csv_has_header ): - if format == "json": + if read_format == "json": benchmark_config[config_filename] = json.load(local_file) - if format == "csv": + if read_format == "csv": reader = csv.reader(local_file) header_array = [] - dict = {} + res_dict = {} header_row = next(reader) body_rows = [x for x in reader] if csv_has_header: for col in header_row: - dict[col] = [] + res_dict[col] = [] header_array.append(col) else: for pos, _ in enumerate(header_row): col_name = "col_{}".format(pos) - dict[col_name] = [] + res_dict[col_name] = [] header_array.append(col_name) newbd = [header_row] for x in body_rows: @@ -183,5 +187,5 @@ def read_json_or_csv( for row in body_rows: for col_pos, col in enumerate(row): col_name = header_array[col_pos] - dict[col_name].append(col) - benchmark_config[config_filename] = dict + res_dict[col_name].append(col) + benchmark_config[config_filename] = res_dict diff --git a/tests/test_redis_benchmark.py b/tests/test_redis_benchmark.py index 72f13b1..a453457 100644 --- a/tests/test_redis_benchmark.py +++ b/tests/test_redis_benchmark.py @@ -3,7 +3,7 @@ import yaml from redisbench_admin.run.redis_benchmark.redis_benchmark import ( - prepareRedisBenchmarkCommand, + prepare_redis_benchmark_command, redis_benchmark_ensure_min_version_local, redis_benchmark_from_stdout_csv_to_json, ) @@ -14,7 +14,7 @@ def test_prepare_redis_benchmark_command(): benchmark_config = yaml.safe_load(yml_file) for k in benchmark_config["clientconfig"]: if "parameters" in k: - command_arr, command_str = prepareRedisBenchmarkCommand( + command_arr, command_str = prepare_redis_benchmark_command( "redis-benchmark", "localhost", "6380", k ) assert ( diff --git a/tests/test_redis_benchmark_csv_format.py b/tests/test_redis_benchmark_csv_format.py index a98f061..4b908f7 100644 --- a/tests/test_redis_benchmark_csv_format.py +++ b/tests/test_redis_benchmark_csv_format.py @@ -29,4 +29,4 @@ def test_redis_benchmark_export_logic(): with open("./tests/test_data/redis-benchmark-6.2.0-csv.out", "r") as csv_file: csv_data = csv_file.read() results_dict = redis_benchmark_from_stdout_csv_to_json(csv_data, 1, "1") - redis_benchmark_export_logic(results_dict, [], None, {}, False) + redis_benchmark_export_logic(results_dict, [], None, {}) diff --git a/tests/test_redisgraph_benchmark_go.py b/tests/test_redisgraph_benchmark_go.py index 64d3a1a..1fb8143 100644 --- a/tests/test_redisgraph_benchmark_go.py +++ b/tests/test_redisgraph_benchmark_go.py @@ -1,7 +1,7 @@ import yaml from redisbench_admin.run.redisgraph_benchmark_go.redisgraph_benchmark_go import ( - prepareRedisGraphBenchmarkGoCommand, + prepare_redisgraph_benchmark_go_command, ) @@ -10,7 +10,7 @@ def test_prepare_redis_graph_benchmark_go_command(): benchmark_config = yaml.safe_load(yml_file) for k in benchmark_config["clientconfig"]: if "parameters" in k: - command_arr, command_str = prepareRedisGraphBenchmarkGoCommand( + command_arr, command_str = prepare_redisgraph_benchmark_go_command( "redisgraph-benchmark-go", "localhost", "6380", k, "result.txt" ) assert ( diff --git a/tests/test_remote.py b/tests/test_remote.py index 98cccbb..04ad6cc 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -1,4 +1,7 @@ -from redisbench_admin.utils.remote import extract_git_vars, fetchRemoteSetupFromConfig +from redisbench_admin.utils.remote import ( + extract_git_vars, + fetch_remote_setup_from_config, +) def test_extract_git_vars(): @@ -76,7 +79,7 @@ def test_extract_git_vars_passing_repo3(): def test_fetch_remote_setup_from_config(): - terraform_working_dir, type = fetchRemoteSetupFromConfig( + terraform_working_dir, type = fetch_remote_setup_from_config( [{"type": "oss-standalone"}, {"setup": "redistimeseries-m5d"}] ) assert type == "oss-standalone"