diff --git a/docs/export.md b/docs/export.md index e2bfc10..a851836 100644 --- a/docs/export.md +++ b/docs/export.md @@ -73,7 +73,7 @@ Optional arguments: branch/ref time-series are created (default: None) --local-dir LOCAL_DIR local dir to use as storage (default: ./) - --local_file PERF_DAEMON_LOGNAME local_file to write the logs to (default: None) + --logfile PERF_DAEMON_LOGNAME logfile to write the logs to (default: None) --github_actor [GITHUB_ACTOR] --github_repo GITHUB_REPO --github_org GITHUB_ORG diff --git a/redisbench_admin/run/metrics.py b/redisbench_admin/run/metrics.py index 3005d6e..1b1863d 100644 --- a/redisbench_admin/run/metrics.py +++ b/redisbench_admin/run/metrics.py @@ -84,12 +84,15 @@ def extract_results_table( return results_matrix -def collect_redis_metrics(redis_conns, sections=["memory", "cpu"]): +def collect_redis_metrics(redis_conns, sections=["memory", "cpu", "commandstats"]): start_time = dt.datetime.utcnow() start_time_ms = int((start_time - dt.datetime(1970, 1, 1)).total_seconds() * 1000) res = [] overall = {} - for conn in redis_conns: + multi_shard = False + if len(redis_conns) > 1: + multi_shard = True + for conn_n, conn in enumerate(redis_conns): conn_res = {} for section in sections: info = conn.info(section) @@ -101,6 +104,14 @@ def collect_redis_metrics(redis_conns, sections=["memory", "cpu"]): if k not in overall[section]: overall[section][k] = 0 overall[section][k] += v + if type(v) is dict: + for inner_k, inner_v in v.items(): + if type(inner_v) is float or type(inner_v) is int: + final_str_k = "{}_{}".format(k, inner_k) + if multi_shard: + final_str_k += "_shard_{}".format(conn_n + 1) + if final_str_k not in overall[section]: + overall[section][final_str_k] = inner_v res.append(conn_res) diff --git a/redisbench_admin/run_remote/run_remote.py b/redisbench_admin/run_remote/run_remote.py index cdd17ce..063d8a7 100644 --- a/redisbench_admin/run_remote/run_remote.py +++ b/redisbench_admin/run_remote/run_remote.py @@ -535,7 +535,9 @@ def run_remote_command_logic(args, project_name, project_version): end_time_ms, _, overall_end_time_metrics, - ) = collect_redis_metrics(redis_conns) + ) = collect_redis_metrics( + redis_conns, ["cpu", "memory"] + ) export_redis_metrics( artifact_version, end_time_ms, @@ -549,6 +551,27 @@ def run_remote_command_logic(args, project_name, project_version): tf_github_repo, tf_triggering_env, ) + ( + end_time_ms, + _, + overall_commandstats_metrics, + ) = collect_redis_metrics( + redis_conns, ["commandstats"] + ) + export_redis_metrics( + artifact_version, + end_time_ms, + overall_commandstats_metrics, + rts, + setup_name, + setup_type, + test_name, + tf_github_branch, + tf_github_org, + tf_github_repo, + tf_triggering_env, + {"metric-type": "commandstats"}, + ) if setup_details["env"] is None: if args.keep_env_and_topo is False: @@ -767,6 +790,7 @@ def export_redis_metrics( tf_github_org, tf_github_repo, tf_triggering_env, + metadata_dict=None, ): datapoint_errors = 0 datapoint_inserts = 0 @@ -818,6 +842,8 @@ def export_redis_metrics( ) variant_labels_dict["test_name"] = test_name variant_labels_dict["metric"] = metric_name + if metadata_dict is not None: + variant_labels_dict.update(metadata_dict) timeseries_dict[tsname_metric] = { "labels": get_project_ts_tags( diff --git a/tests/test_metrics.py b/tests/test_metrics.py index f2d3fcb..82e3d7f 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -41,14 +41,20 @@ def test_collect_redis_metrics(): rts.redis.ping() time_ms, metrics_arr, overall_metrics = collect_redis_metrics([rts.redis]) assert len(metrics_arr) == 1 - assert len(metrics_arr[0].keys()) == 2 + assert len(metrics_arr[0].keys()) == 3 assert "cpu" in metrics_arr[0].keys() assert "memory" in metrics_arr[0].keys() + assert "commandstats" in metrics_arr[0].keys() assert "allocator_active" in metrics_arr[0]["memory"] + assert "cmdstat_ping" in metrics_arr[0]["commandstats"] allocator_active = metrics_arr[0]["memory"]["allocator_active"] allocator_active_kv = overall_metrics["memory_allocator_active"] assert allocator_active == allocator_active_kv - _, _, overall_metrics = collect_redis_metrics([rts.redis, rts.redis]) + _, metrics_arr, overall_metrics = collect_redis_metrics([rts.redis, rts.redis]) allocator_active_kv = overall_metrics["memory_allocator_active"] assert (2 * allocator_active) == allocator_active_kv + assert "cmdstat_ping" in metrics_arr[0]["commandstats"] + assert "cmdstat_ping" in metrics_arr[1]["commandstats"] + assert "commandstats_cmdstat_ping_calls_shard_1" in overall_metrics + assert "commandstats_cmdstat_ping_calls_shard_2" in overall_metrics diff --git a/tests/test_profilers_schema.py b/tests/test_profilers_schema.py new file mode 100644 index 0000000..d4eebb0 --- /dev/null +++ b/tests/test_profilers_schema.py @@ -0,0 +1,14 @@ +# BSD 3-Clause License +# +# Copyright (c) 2022., Redis Labs Modules +# All rights reserved. +# +from redisbench_admin.profilers.profilers_schema import get_profilers_rts_key_prefix + + +def test_get_profilers_rts_key_prefix(): + triggering_env = "ci" + tf_github_org = "redislabs" + tf_github_repo = "redisbench-admin" + res = get_profilers_rts_key_prefix(triggering_env, tf_github_org, tf_github_repo) + assert res == "ci.benchmarks.redis.com/ci/redislabs/redisbench-admin:profiles" diff --git a/tests/test_run_remote.py b/tests/test_run_remote.py index eb01afe..c8acf69 100644 --- a/tests/test_run_remote.py +++ b/tests/test_run_remote.py @@ -77,6 +77,17 @@ def test_export_redis_metrics(): tf_github_org, tf_github_repo, tf_triggering_env, + {"metric-type": "test-tag"}, + ) + assert ( + rts.info( + "ci.benchmarks.redislabs/env/org/repo/test1/by.version/6.2.3/benchmark_end/commandstats_cmdstat_ping_calls" + ).labels["metric-type"] + == "test-tag" + ) + assert ( + "ci.benchmarks.redislabs/env/org/repo/test1/by.version/6.2.3/benchmark_end/commandstats_cmdstat_ping_calls" + in rts.queryindex(["metric-type=test-tag"]) ) assert datapoint_errors == 0 assert datapoint_inserts == (1 * len(list(overall_end_time_metrics.keys())))