Skip to content

Commit 4376dbd

Browse files
[add] Enabled --csv format in redisbench-admin export tool (#228)
* [add] Enabled --csv format in redisbench-admin export tool * [add] included test json for memtier * Bumping version from 0.5.9 to 0.5.10
1 parent 7a48993 commit 4376dbd

File tree

10 files changed

+460
-252
lines changed

10 files changed

+460
-252
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.5.9"
3+
version = "0.5.10"
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]>","Redis Performance Group <[email protected]>"]
66
readme = "README.md"

redisbench_admin/export/args.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def create_export_arguments(parser):
2222
parser.add_argument(
2323
"--exporter-spec-file",
2424
type=str,
25-
required=True,
2625
help="Exporter definition file, containing info of the metrics to extract",
2726
)
2827
parser.add_argument(
@@ -46,7 +45,7 @@ def create_export_arguments(parser):
4645
parser.add_argument(
4746
"--test-name",
4847
type=str,
49-
required=True,
48+
default=None,
5049
help="Test name",
5150
)
5251
parser.add_argument("--github_actor", type=str, default=None, nargs="?", const="")
@@ -65,7 +64,7 @@ def create_export_arguments(parser):
6564
type=str,
6665
default="json",
6766
help="results format of the the benchmark results files to read "
68-
"results from ( either json, redis-benchmark-txt )",
67+
"results from ( either csv, json, redis-benchmark-txt )",
6968
)
7069
parser.add_argument(
7170
"--use-result",

redisbench_admin/export/export.py

Lines changed: 137 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# Copyright (c) 2021., Redis Labs Modules
44
# All rights reserved.
55
#
6-
7-
6+
import csv
87
import json
98
import logging
109
import datetime
@@ -20,6 +19,7 @@
2019
get_defaults,
2120
parse_exporter_timemetric,
2221
)
22+
from redisbench_admin.utils.remote import get_ts_tags_and_name
2323

2424

2525
def export_command_logic(args, project_name, project_version):
@@ -28,47 +28,47 @@ def export_command_logic(args, project_name, project_version):
2828
project_name=project_name, project_version=project_version
2929
)
3030
)
31+
timeseries_dict = None
3132
benchmark_file = args.benchmark_result_file
33+
test_name = args.test_name
34+
deployment_version = args.deployment_version
35+
triggering_env = args.triggering_env
36+
deployment_name = args.deployment_name
37+
deployment_type = args.deployment_type
3238
results_format = args.results_format
33-
(_, tf_github_branch, tf_github_org, tf_github_repo, _,) = git_vars_crosscheck(
39+
(_, github_branch, github_org, github_repo, _,) = git_vars_crosscheck(
3440
None, args.github_branch, args.github_org, args.github_repo, None
3541
)
36-
results_dict = {}
37-
if results_format == "json":
38-
with open(benchmark_file, "r") as json_file:
39-
results_dict = json.load(json_file)
40-
extra_tags_dict = split_tags_string(args.extra_tags)
41-
logging.info("Using the following extra tags: {}".format(extra_tags_dict))
42-
43-
logging.info(
44-
"Checking connection to RedisTimeSeries to host: {}:{}".format(
45-
args.redistimeseries_host, args.redistimeseries_port
46-
)
47-
)
48-
rts = Client(
49-
host=args.redistimeseries_host,
50-
port=args.redistimeseries_port,
51-
password=args.redistimeseries_pass,
52-
)
53-
try:
54-
rts.redis.ping()
55-
except redis.exceptions.ConnectionError as e:
42+
exporter_timemetric_path = None
43+
metrics = []
44+
exporter_spec_file = args.exporter_spec_file
45+
if github_branch is None and deployment_version is None:
5646
logging.error(
57-
"Error while connecting to RedisTimeSeries data sink at: {}:{}. Error: {}".format(
58-
args.redistimeseries_host, args.redistimeseries_port, e.__str__()
59-
)
47+
"You need to specify at least one (or more) of --deployment-version --github_branch arguments"
6048
)
6149
exit(1)
50+
if results_format != "csv":
51+
if exporter_spec_file is None:
52+
logging.error(
53+
"--exporter-spec-file is required for all formats with exception of csv"
54+
)
55+
exit(1)
56+
else:
57+
(
58+
_,
59+
metrics,
60+
exporter_timemetric_path,
61+
_,
62+
_,
63+
) = get_defaults(exporter_spec_file)
6264

63-
benchmark_duration_seconds = None
64-
exporter_spec_file = args.exporter_spec_file
65-
(
66-
_,
67-
metrics,
68-
exporter_timemetric_path,
69-
_,
70-
_,
71-
) = get_defaults(exporter_spec_file)
65+
extra_tags_dict = split_tags_string(args.extra_tags)
66+
logging.info("Using the following extra tags: {}".format(extra_tags_dict))
67+
68+
results_dict = {}
69+
if results_format == "json":
70+
with open(benchmark_file, "r") as json_file:
71+
results_dict = json.load(json_file)
7272
if args.override_test_time:
7373
datapoints_timestamp = int(args.override_test_time.timestamp() * 1000.0)
7474
logging.info(
@@ -94,26 +94,120 @@ def export_command_logic(args, project_name, project_version):
9494
datapoints_timestamp
9595
)
9696
)
97+
break_by_dict = {}
98+
if deployment_version is not None:
99+
break_by_dict.update({"version": deployment_version})
100+
if github_branch is not None:
101+
break_by_dict.update({"branch": github_branch})
102+
if results_format == "csv":
103+
logging.info("Parsing CSV format from {}".format(benchmark_file))
104+
timeseries_dict = export_opereto_csv_to_timeseries_dict(
105+
benchmark_file,
106+
break_by_dict,
107+
datapoints_timestamp,
108+
deployment_name,
109+
deployment_type,
110+
extra_tags_dict,
111+
github_org,
112+
github_repo,
113+
triggering_env,
114+
)
115+
logging.info("Parsed a total of {} metrics".format(len(timeseries_dict.keys())))
116+
logging.info(
117+
"Checking connection to RedisTimeSeries to host: {}:{}".format(
118+
args.redistimeseries_host, args.redistimeseries_port
119+
)
120+
)
121+
rts = Client(
122+
host=args.redistimeseries_host,
123+
port=args.redistimeseries_port,
124+
password=args.redistimeseries_pass,
125+
)
126+
try:
127+
rts.redis.ping()
128+
except redis.exceptions.ConnectionError as e:
129+
logging.error(
130+
"Error while connecting to RedisTimeSeries data sink at: {}:{}. Error: {}".format(
131+
args.redistimeseries_host, args.redistimeseries_port, e.__str__()
132+
)
133+
)
134+
exit(1)
135+
136+
benchmark_duration_seconds = None
97137

98138
timeseries_test_sucess_flow(
99139
True,
100-
args.deployment_version,
140+
deployment_version,
101141
None,
102142
benchmark_duration_seconds,
103143
None,
104144
metrics,
105-
args.deployment_name,
106-
args.deployment_type,
145+
deployment_name,
146+
deployment_type,
107147
exporter_timemetric_path,
108148
results_dict,
109149
rts,
110150
datapoints_timestamp,
111-
args.test_name,
112-
tf_github_branch,
113-
tf_github_org,
114-
tf_github_repo,
115-
args.triggering_env,
151+
test_name,
152+
github_branch,
153+
github_org,
154+
github_repo,
155+
triggering_env,
116156
extra_tags_dict,
117157
None,
118158
None,
159+
timeseries_dict,
119160
)
161+
162+
163+
def export_opereto_csv_to_timeseries_dict(
164+
benchmark_file,
165+
break_by_dict,
166+
datapoints_timestamp,
167+
deployment_name,
168+
deployment_type,
169+
extra_tags_dict,
170+
tf_github_org,
171+
tf_github_repo,
172+
triggering_env,
173+
):
174+
results_dict = {}
175+
with open(benchmark_file, "r") as csv_file:
176+
full_csv = list(csv.reader(csv_file, delimiter=",", quoting=csv.QUOTE_ALL))
177+
if len(full_csv) >= 2:
178+
header = full_csv[0]
179+
metrics = header[1:]
180+
for row in full_csv[1:]:
181+
assert len(row) == len(header)
182+
test_name = row[0]
183+
for metric_pos, metric_name in enumerate(metrics):
184+
metric_v_pos = 1 + metric_pos
185+
if metric_v_pos < len(row):
186+
metric_value = row[metric_v_pos]
187+
188+
for break_by_key, break_by_value in break_by_dict.items():
189+
break_by_str = "by.{}".format(break_by_key)
190+
timeserie_tags, ts_name = get_ts_tags_and_name(
191+
break_by_key,
192+
break_by_str,
193+
break_by_value,
194+
None,
195+
deployment_name,
196+
deployment_type,
197+
extra_tags_dict,
198+
metric_name,
199+
metric_name,
200+
metric_name,
201+
triggering_env,
202+
test_name,
203+
metric_name,
204+
tf_github_org,
205+
tf_github_repo,
206+
triggering_env,
207+
False,
208+
)
209+
results_dict[ts_name] = {
210+
"labels": timeserie_tags.copy(),
211+
"data": {datapoints_timestamp: metric_value},
212+
}
213+
return results_dict

redisbench_admin/run/common.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
)
4040
from redisbench_admin.utils.remote import (
4141
extract_perversion_timeseries_from_results,
42-
push_data_to_redistimeseries,
4342
extract_perbranch_timeseries_from_results,
4443
)
4544

@@ -214,7 +213,6 @@ def common_exporter_logic(
214213
exporter_timemetric_path,
215214
metrics,
216215
results_dict,
217-
rts,
218216
test_name,
219217
tf_github_branch,
220218
tf_github_org,
@@ -226,8 +224,8 @@ def common_exporter_logic(
226224
running_platform=None,
227225
datapoints_timestamp=None,
228226
):
229-
per_version_time_series_dict = None
230-
per_branch_time_series_dict = None
227+
per_version_time_series_dict = {}
228+
per_branch_time_series_dict = {}
231229
testcase_metric_context_paths = []
232230

233231
if exporter_timemetric_path is not None and len(metrics) > 0:
@@ -243,7 +241,7 @@ def common_exporter_logic(
243241
):
244242
# extract per-version datapoints
245243
(
246-
ok,
244+
_,
247245
per_version_time_series_dict,
248246
) = extract_perversion_timeseries_from_results(
249247
datapoints_timestamp,
@@ -261,12 +259,9 @@ def common_exporter_logic(
261259
running_platform,
262260
testcase_metric_context_paths,
263261
)
264-
if ok:
265-
# push per-version data
266-
push_data_to_redistimeseries(rts, per_version_time_series_dict)
267262
if tf_github_branch is not None and tf_github_branch != "":
268263
# extract per branch datapoints
269-
ok, per_branch_time_series_dict = extract_perbranch_timeseries_from_results(
264+
_, per_branch_time_series_dict = extract_perbranch_timeseries_from_results(
270265
datapoints_timestamp,
271266
metrics,
272267
results_dict,
@@ -282,9 +277,6 @@ def common_exporter_logic(
282277
running_platform,
283278
testcase_metric_context_paths,
284279
)
285-
if ok:
286-
# push per-branch data
287-
push_data_to_redistimeseries(rts, per_branch_time_series_dict)
288280
else:
289281
logging.warning(
290282
"Requested to push data to RedisTimeSeries but no git"

0 commit comments

Comments
 (0)