33# Copyright (c) 2021., Redis Labs Modules
44# All rights reserved.
55#
6-
7-
6+ import csv
87import json
98import logging
109import datetime
2019 get_defaults ,
2120 parse_exporter_timemetric ,
2221)
22+ from redisbench_admin .utils .remote import get_ts_tags_and_name
2323
2424
2525def 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
0 commit comments