11import os
22import pandas as pd
3+ import redis
4+
35from redisbench_admin .compare .compare import get_key_results_and_values
46from redisbench_admin .utils .utils import retrieve_local_or_remote_input_json
57import matplotlib .pyplot as plt
68import seaborn as sns
9+
710sns .set (style = "darkgrid" )
811from redistimeseries .client import Client
912
13+
1014def get_timeserie_name (labels_kv_array ):
1115 name = ""
1216 for label_kv in labels_kv_array :
1317 k = list (label_kv .keys ())[0 ]
1418 v = list (label_kv .values ())[0 ]
15- k = prepare_tags (k )
19+ k = prepare_tags (k )
1620 v = prepare_tags (v )
1721 if name != "" :
1822 name += ":"
@@ -47,7 +51,7 @@ def extract_benchmark_config_details(benchmark_result):
4751 specifications_version = benchmark_config ["specifications-version" ]
4852 testcase_description = benchmark_config ["description" ]
4953 key_metrics_specs = benchmark_config ["key-metrics" ]
50- return testcase_name , specifications_version , testcase_description ,key_metrics_specs
54+ return testcase_name , specifications_version , testcase_description , key_metrics_specs
5155
5256
5357def extract_key_configs (benchmark_result ):
@@ -66,14 +70,14 @@ def extract_key_configs(benchmark_result):
6670 return deployment_type , deployment_shards , project , project_version , git_sha
6771
6872
69- def add_datapoint (time_series_dict , broader_ts_name , start_time_ms , metric_value , tags_array ):
73+ def add_datapoint (time_series_dict , broader_ts_name , start_time_ms , metric_value , tags_array ):
7074 if broader_ts_name not in time_series_dict :
7175 tags_dict = {}
7276 for tag_kv in tags_array :
7377 k = list (tag_kv .keys ())[0 ]
7478 v = list (tag_kv .values ())[0 ]
75- tags_dict [k ]= v
76- time_series_dict [broader_ts_name ]= {"index" :[],"data" :[],"tags-array" :tags_array , "tags" :tags_dict }
79+ tags_dict [k ] = v
80+ time_series_dict [broader_ts_name ] = {"index" : [], "data" : [], "tags-array" : tags_array , "tags" : tags_dict }
7781 time_series_dict [broader_ts_name ]["index" ].append (start_time_ms )
7882 time_series_dict [broader_ts_name ]["data" ].append (metric_value )
7983
@@ -85,9 +89,9 @@ def split_tags_string(extra_tags):
8589 for extra_tag in extra_tags :
8690 kv = extra_tag .split ("=" )
8791 if len (kv ) == 2 :
88- k = prepare_tags (kv [0 ])
92+ k = prepare_tags (kv [0 ])
8993 v = prepare_tags (kv [1 ])
90- result .append ({k :v })
94+ result .append ({k : v })
9195 return result
9296
9397
@@ -99,33 +103,36 @@ def split_key_metrics_by_step(key_metrics_specs):
99103 step = key_metric_spec ["step" ]
100104 metric_name = key_metric_spec ["metric-name" ]
101105 if step not in key_metrics_by_step :
102- key_metrics_by_step [step ]= {}
103- key_metrics_by_step [step ][metric_name ]= key_metric_spec
106+ key_metrics_by_step [step ] = {}
107+ key_metrics_by_step [step ][metric_name ] = key_metric_spec
104108 return key_metrics_by_step
105109
106- def get_or_None (dict ,property ):
110+
111+ def get_or_None (dict , property ):
107112 result = None
108113 if property in dict :
109114 result = dict [property ]
110115 return result
111116
117+
112118def get_metric_detail (key_metric_spec ):
113- metric_step = get_or_None ( key_metric_spec , "step" )
114- metric_family = get_or_None ( key_metric_spec , "metric-family" )
119+ metric_step = get_or_None (key_metric_spec , "step" )
120+ metric_family = get_or_None (key_metric_spec , "metric-family" )
115121 metric_json_path = get_or_None (key_metric_spec , "metric-json-path" )
116- metric_name = get_or_None ( key_metric_spec , "metric-name" )
117- metric_unit = get_or_None ( key_metric_spec , "unit" )
118- metric_type = get_or_None ( key_metric_spec , "metric-type" )
119- metric_comparison = get_or_None ( key_metric_spec , "comparison" )
120- metric_per_step_comparison_priority = get_or_None ( key_metric_spec , "per-step-comparison-metric-priority" )
121- return metric_step ,metric_family ,metric_json_path ,metric_name ,metric_unit ,metric_type ,metric_comparison ,metric_per_step_comparison_priority
122+ metric_name = get_or_None (key_metric_spec , "metric-name" )
123+ metric_unit = get_or_None (key_metric_spec , "unit" )
124+ metric_type = get_or_None (key_metric_spec , "metric-type" )
125+ metric_comparison = get_or_None (key_metric_spec , "comparison" )
126+ metric_per_step_comparison_priority = get_or_None (key_metric_spec , "per-step-comparison-metric-priority" )
127+ return metric_step , metric_family , metric_json_path , metric_name , metric_unit , metric_type , metric_comparison , metric_per_step_comparison_priority
128+
122129
123130def export_command_logic (args ):
124131 benchmark_files = args .benchmark_result_files
125132 local_path = os .path .abspath (args .local_dir )
126133 use_result = args .use_result
127134 included_steps = args .steps .split ("," )
128-
135+
129136 extra_tags_array = split_tags_string (args .extra_tags )
130137 print (extra_tags_array )
131138 results_type = "key-results"
@@ -134,10 +141,12 @@ def export_command_logic(args):
134141 for filename , benchmark_result in benchmark_results .items ():
135142 print (filename )
136143 key_result_steps = benchmark_result [results_type ].keys ()
137- testcase_name , specifications_version , testcase_description ,key_metrics_specs = extract_benchmark_config_details (benchmark_result )
144+ testcase_name , specifications_version , testcase_description , key_metrics_specs = extract_benchmark_config_details (
145+ benchmark_result )
138146 key_metrics_specs_per_step = split_key_metrics_by_step (key_metrics_specs )
139147 deployment_type , deployment_shards , project , project_version , git_sha = extract_key_configs (benchmark_result )
140- start_time_ms , start_time_humanized , end_time_ms , end_time_humanized , duration_ms , duration_humanized = extract_benchmark_run_info_details (benchmark_result )
148+ start_time_ms , start_time_humanized , end_time_ms , end_time_humanized , duration_ms , duration_humanized = extract_benchmark_run_info_details (
149+ benchmark_result )
141150
142151 for step in key_result_steps :
143152 common_broader_kv_tags = [
@@ -168,8 +177,7 @@ def export_command_logic(args):
168177 git_sha_ts_name = get_timeserie_name (git_sha_kv )
169178
170179 key_metric_spec = key_metrics_specs [metric_name ]
171- metric_step , metric_family , _ , _ , metric_unit , _ , _ ,_ = get_metric_detail (key_metric_spec )
172-
180+ metric_step , metric_family , _ , _ , metric_unit , _ , _ , _ = get_metric_detail (key_metric_spec )
173181
174182 # add_datapoint(time_series_dict,broader_ts_name,start_time_ms,metric_value,tags_kv)
175183 # add_datapoint(time_series_dict, version_ts_name, start_time_ms, metric_value, tags_kv)
@@ -178,30 +186,18 @@ def export_command_logic(args):
178186 git_sha_tags_kv .extend (
179187 [{"metric-step" : metric_step }, {"metric-family" : metric_family }, {"metric-unit" : metric_unit }])
180188 add_datapoint (time_series_dict , git_sha_ts_name , start_time_ms , metric_value , git_sha_tags_kv )
181- # print(broader_ts_name)
182- # print(version_ts_name)
183- # print(git_sha_ts_name)
184- # print(time_series_dict)
185- rts = Client ()
189+ rts = Client (host = args .host ,port = args .port ,password = args .password )
186190 for timeseries_name , time_series in time_series_dict .items ():
187- rts .create (timeseries_name ,labels = time_series ['tags' ])
188- for pos ,timestamp in enumerate (time_series ['index' ]):
191+ try :
192+ rts .create (timeseries_name , labels = time_series ['tags' ])
193+ except redis .exceptions .ResponseError :
194+ # if ts already exists continue
195+ pass
196+ for pos , timestamp in enumerate (time_series ['index' ]):
189197 value = time_series ['data' ][pos ]
190- rts .add (timeseries_name , timestamp , value )
191-
192- #
193- # index = pd.to_datetime(time_series['index'], unit='ms')
194- # df = pd.Series(time_series['data'], index=index)
195- # print(df)
196-
197- # import matplotlib.pyplot as plt
198- # fig, ax = plt.subplots()
199- # # Plot the responses for different events and regions
200- # sns.lineplot( x="timepoint", y="signal",
201- # data=df, ax=ax)
202- # bottom, top = plt.ylim()
203- # plt.ylim(0,top)
204- # plt.savefig('{}.png'.format(timeseries_name))
205-
206-
198+ try :
199+ rts .add (timeseries_name , timestamp , value )
200+ except redis .exceptions .ResponseError :
201+ # if ts already exists continue
202+ pass
207203
0 commit comments