3232 "CLICKHOUSE_ENDPOINT" : os .getenv ("CLICKHOUSE_ENDPOINT" , "" ),
3333 "CLICKHOUSE_PASSWORD" : os .getenv ("CLICKHOUSE_PASSWORD" , "" ),
3434 "CLICKHOUSE_USERNAME" : os .getenv ("CLICKHOUSE_USERNAME" , "" ),
35+ "HUD_INTERNAL_BOT_TOKEN" : os .getenv ("HUD_INTERNAL_BOT_TOKEN" , "" ),
3536}
3637
3738
@@ -71,13 +72,15 @@ def __init__(
7172 self ,
7273 config_id : str ,
7374 end_time : int ,
75+ hud_access_token : str = "" ,
7476 is_dry_run : bool = False ,
7577 is_pass_check : bool = False ,
7678 ) -> None :
7779 self .is_dry_run = is_dry_run
7880 self .is_pass_check = is_pass_check
7981 self .config_id = config_id
8082 self .end_time = end_time
83+ self .hud_access_token = hud_access_token
8184
8285 def log_info (self , msg : str ):
8386 logger .info ("[%s][%s] %s" , self .end_time , self .config_id , msg )
@@ -136,13 +139,15 @@ def process(
136139 f"with frequency { report_freq .get_text ()} ..."
137140 )
138141
139- target , ls , le = self .get_target (config , self .end_time )
142+ target , ls , le = self .get_target (config , self .end_time , self . hud_access_token )
140143 if not target .time_series :
141144 self .log_info (
142145 f"no target data found for time range [{ ls } ,{ le } ] with frequency { report_freq .get_text ()} ..."
143146 )
144147 return
145- baseline , bs , be = self .get_baseline (config , self .end_time )
148+ baseline , bs , be = self .get_baseline (
149+ config , self .end_time , self .hud_access_token
150+ )
146151
147152 if not baseline .time_series :
148153 self .log_info (
@@ -165,7 +170,7 @@ def process(
165170 reportManager .run (cc , ENVS ["GITHUB_TOKEN" ])
166171 return
167172
168- def get_target (self , config : BenchmarkConfig , end_time : int ):
173+ def get_target (self , config : BenchmarkConfig , end_time : int , hud_access_token : str ):
169174 data_range = config .policy .range
170175 target_s = end_time - data_range .comparison_timedelta_s ()
171176 target_e = end_time
@@ -178,10 +183,16 @@ def get_target(self, config: BenchmarkConfig, end_time: int):
178183 start_time = target_s ,
179184 end_time = target_e ,
180185 source = config .source ,
186+ access_token = hud_access_token ,
181187 )
182188 self .log_info (
183189 f"done. found { len (target_data .time_series )} # of data groups, with time range { target_data .time_range } " ,
184190 )
191+
192+ if len (target_data .time_series ) > 0 :
193+ self .log_info (
194+ f"peeking the first data: { target_data .time_series [0 ]} " ,
195+ )
185196 if not target_data .time_range or not target_data .time_range .end :
186197 return None , target_s , target_e
187198
@@ -190,7 +201,9 @@ def get_target(self, config: BenchmarkConfig, end_time: int):
190201 return None , target_s , target_e
191202 return target_data , target_s , target_e
192203
193- def get_baseline (self , config : BenchmarkConfig , end_time : int ):
204+ def get_baseline (
205+ self , config : BenchmarkConfig , end_time : int , hud_access_token : str
206+ ):
194207 data_range = config .policy .range
195208 baseline_s = end_time - data_range .total_timedelta_s ()
196209 baseline_e = end_time - data_range .comparison_timedelta_s ()
@@ -204,12 +217,18 @@ def get_baseline(self, config: BenchmarkConfig, end_time: int):
204217 start_time = baseline_s ,
205218 end_time = baseline_e ,
206219 source = config .source ,
220+ access_token = hud_access_token ,
207221 )
208222
209223 self .log_info (
210224 f"Done. found { len (raw_data .time_series )} # of data, with time range { raw_data .time_range } " ,
211225 )
212226
227+ if len (raw_data .time_series ) > 0 :
228+ self .log_info (
229+ f"peeking the first data: { raw_data .time_series [0 ]} " ,
230+ )
231+
213232 baseline_latest_ts = int (isoparse (raw_data .time_range .end ).timestamp ())
214233
215234 if not self .should_use_data (baseline_latest_ts , baseline_e ):
@@ -245,6 +264,7 @@ def _fetch_from_benchmark_ts_api(
245264 config_id : str ,
246265 end_time : int ,
247266 start_time : int ,
267+ access_token : str ,
248268 source : BenchmarkApiSource ,
249269 ):
250270 str_end_time = format_ts_with_t (end_time )
@@ -261,7 +281,7 @@ def _fetch_from_benchmark_ts_api(
261281 t0 = time .perf_counter ()
262282 try :
263283 resp : BenchmarkTimeSeriesApiResponse = (
264- BenchmarkTimeSeriesApiResponse .from_request (url , query )
284+ BenchmarkTimeSeriesApiResponse .from_request (url , query , access_token )
265285 )
266286
267287 elapsed_ms = (time .perf_counter () - t0 ) * 1000.0
@@ -353,6 +373,7 @@ def _get_latest_record_ts(
353373def main (
354374 config_id : str ,
355375 github_access_token : str = "" ,
376+ hud_access_token : str = "" ,
356377 args : Optional [argparse .Namespace ] = None ,
357378 * ,
358379 is_dry_run : bool = False ,
@@ -392,6 +413,7 @@ def main(
392413 end_time = end_time_ts ,
393414 is_dry_run = is_dry_run ,
394415 is_pass_check = is_forced ,
416+ hud_access_token = hud_access_token ,
395417 )
396418 processor .process (args = args )
397419 except Exception as e :
@@ -411,6 +433,7 @@ def lambda_handler(event: Any, context: Any) -> None:
411433 main (
412434 config_id = config_id ,
413435 github_access_token = ENVS ["GITHUB_TOKEN" ],
436+ hud_access_token = ENVS ["HUD_INTERNAL_BOT_TOKEN" ],
414437 )
415438 return
416439
@@ -473,6 +496,12 @@ def parse_args() -> argparse.Namespace:
473496 type = str ,
474497 help = "the end time to run, in format of YYYY-MM-DD HH:MM:SS" ,
475498 )
499+ parser .add_argument (
500+ "--hud-internal-bot-token" ,
501+ type = str ,
502+ default = ENVS ["HUD_INTERNAL_BOT_TOKEN" ],
503+ help = "the hud internal bot token to access hud api" ,
504+ )
476505 parser .set_defaults (dry_run = True ) # default is True
477506 args , _ = parser .parse_known_args ()
478507 return args
@@ -487,6 +516,7 @@ def local_run() -> None:
487516 # update environment variables for input parameters
488517 main (
489518 config_id = args .config_id ,
519+ hud_access_token = args .hud_internal_bot_token ,
490520 github_access_token = args .github_access_token ,
491521 args = args ,
492522 is_dry_run = args .dry_run ,
0 commit comments