Skip to content

Commit 4ea1a6e

Browse files
Enabled commandstats retrieval and store into the TSDB (#274)
1 parent 9f9f047 commit 4ea1a6e

File tree

6 files changed

+74
-6
lines changed

6 files changed

+74
-6
lines changed

docs/export.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Optional arguments:
7373
branch/ref time-series are created (default: None)
7474
--local-dir LOCAL_DIR
7575
local dir to use as storage (default: ./)
76-
--local_file PERF_DAEMON_LOGNAME local_file to write the logs to (default: None)
76+
--logfile PERF_DAEMON_LOGNAME logfile to write the logs to (default: None)
7777
--github_actor [GITHUB_ACTOR]
7878
--github_repo GITHUB_REPO
7979
--github_org GITHUB_ORG

redisbench_admin/run/metrics.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ def extract_results_table(
8484
return results_matrix
8585

8686

87-
def collect_redis_metrics(redis_conns, sections=["memory", "cpu"]):
87+
def collect_redis_metrics(redis_conns, sections=["memory", "cpu", "commandstats"]):
8888
start_time = dt.datetime.utcnow()
8989
start_time_ms = int((start_time - dt.datetime(1970, 1, 1)).total_seconds() * 1000)
9090
res = []
9191
overall = {}
92-
for conn in redis_conns:
92+
multi_shard = False
93+
if len(redis_conns) > 1:
94+
multi_shard = True
95+
for conn_n, conn in enumerate(redis_conns):
9396
conn_res = {}
9497
for section in sections:
9598
info = conn.info(section)
@@ -101,6 +104,14 @@ def collect_redis_metrics(redis_conns, sections=["memory", "cpu"]):
101104
if k not in overall[section]:
102105
overall[section][k] = 0
103106
overall[section][k] += v
107+
if type(v) is dict:
108+
for inner_k, inner_v in v.items():
109+
if type(inner_v) is float or type(inner_v) is int:
110+
final_str_k = "{}_{}".format(k, inner_k)
111+
if multi_shard:
112+
final_str_k += "_shard_{}".format(conn_n + 1)
113+
if final_str_k not in overall[section]:
114+
overall[section][final_str_k] = inner_v
104115

105116
res.append(conn_res)
106117

redisbench_admin/run_remote/run_remote.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,9 @@ def run_remote_command_logic(args, project_name, project_version):
535535
end_time_ms,
536536
_,
537537
overall_end_time_metrics,
538-
) = collect_redis_metrics(redis_conns)
538+
) = collect_redis_metrics(
539+
redis_conns, ["cpu", "memory"]
540+
)
539541
export_redis_metrics(
540542
artifact_version,
541543
end_time_ms,
@@ -549,6 +551,27 @@ def run_remote_command_logic(args, project_name, project_version):
549551
tf_github_repo,
550552
tf_triggering_env,
551553
)
554+
(
555+
end_time_ms,
556+
_,
557+
overall_commandstats_metrics,
558+
) = collect_redis_metrics(
559+
redis_conns, ["commandstats"]
560+
)
561+
export_redis_metrics(
562+
artifact_version,
563+
end_time_ms,
564+
overall_commandstats_metrics,
565+
rts,
566+
setup_name,
567+
setup_type,
568+
test_name,
569+
tf_github_branch,
570+
tf_github_org,
571+
tf_github_repo,
572+
tf_triggering_env,
573+
{"metric-type": "commandstats"},
574+
)
552575

553576
if setup_details["env"] is None:
554577
if args.keep_env_and_topo is False:
@@ -767,6 +790,7 @@ def export_redis_metrics(
767790
tf_github_org,
768791
tf_github_repo,
769792
tf_triggering_env,
793+
metadata_dict=None,
770794
):
771795
datapoint_errors = 0
772796
datapoint_inserts = 0
@@ -818,6 +842,8 @@ def export_redis_metrics(
818842
)
819843
variant_labels_dict["test_name"] = test_name
820844
variant_labels_dict["metric"] = metric_name
845+
if metadata_dict is not None:
846+
variant_labels_dict.update(metadata_dict)
821847

822848
timeseries_dict[tsname_metric] = {
823849
"labels": get_project_ts_tags(

tests/test_metrics.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,20 @@ def test_collect_redis_metrics():
4141
rts.redis.ping()
4242
time_ms, metrics_arr, overall_metrics = collect_redis_metrics([rts.redis])
4343
assert len(metrics_arr) == 1
44-
assert len(metrics_arr[0].keys()) == 2
44+
assert len(metrics_arr[0].keys()) == 3
4545
assert "cpu" in metrics_arr[0].keys()
4646
assert "memory" in metrics_arr[0].keys()
47+
assert "commandstats" in metrics_arr[0].keys()
4748
assert "allocator_active" in metrics_arr[0]["memory"]
49+
assert "cmdstat_ping" in metrics_arr[0]["commandstats"]
4850
allocator_active = metrics_arr[0]["memory"]["allocator_active"]
4951
allocator_active_kv = overall_metrics["memory_allocator_active"]
5052
assert allocator_active == allocator_active_kv
5153

52-
_, _, overall_metrics = collect_redis_metrics([rts.redis, rts.redis])
54+
_, metrics_arr, overall_metrics = collect_redis_metrics([rts.redis, rts.redis])
5355
allocator_active_kv = overall_metrics["memory_allocator_active"]
5456
assert (2 * allocator_active) == allocator_active_kv
57+
assert "cmdstat_ping" in metrics_arr[0]["commandstats"]
58+
assert "cmdstat_ping" in metrics_arr[1]["commandstats"]
59+
assert "commandstats_cmdstat_ping_calls_shard_1" in overall_metrics
60+
assert "commandstats_cmdstat_ping_calls_shard_2" in overall_metrics

tests/test_profilers_schema.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# BSD 3-Clause License
2+
#
3+
# Copyright (c) 2022., Redis Labs Modules
4+
# All rights reserved.
5+
#
6+
from redisbench_admin.profilers.profilers_schema import get_profilers_rts_key_prefix
7+
8+
9+
def test_get_profilers_rts_key_prefix():
10+
triggering_env = "ci"
11+
tf_github_org = "redislabs"
12+
tf_github_repo = "redisbench-admin"
13+
res = get_profilers_rts_key_prefix(triggering_env, tf_github_org, tf_github_repo)
14+
assert res == "ci.benchmarks.redis.com/ci/redislabs/redisbench-admin:profiles"

tests/test_run_remote.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ def test_export_redis_metrics():
7777
tf_github_org,
7878
tf_github_repo,
7979
tf_triggering_env,
80+
{"metric-type": "test-tag"},
81+
)
82+
assert (
83+
rts.info(
84+
"ci.benchmarks.redislabs/env/org/repo/test1/by.version/6.2.3/benchmark_end/commandstats_cmdstat_ping_calls"
85+
).labels["metric-type"]
86+
== "test-tag"
87+
)
88+
assert (
89+
"ci.benchmarks.redislabs/env/org/repo/test1/by.version/6.2.3/benchmark_end/commandstats_cmdstat_ping_calls"
90+
in rts.queryindex(["metric-type=test-tag"])
8091
)
8192
assert datapoint_errors == 0
8293
assert datapoint_inserts == (1 * len(list(overall_end_time_metrics.keys())))

0 commit comments

Comments
 (0)