-
Notifications
You must be signed in to change notification settings - Fork 108
Add Hud x-token in lambda #7511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a887e2
hidemetadata
yangw-dev 46dfe98
hidemetadata
yangw-dev 6d58023
hidemetadata
yangw-dev 8520168
hidemetadata
yangw-dev acb9a93
hidemetadata
yangw-dev 7d023e2
Merge branch 'main' into addtoken
yangw-dev eb7e78b
hidemetadata
yangw-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| "CLICKHOUSE_ENDPOINT": os.getenv("CLICKHOUSE_ENDPOINT", ""), | ||
| "CLICKHOUSE_PASSWORD": os.getenv("CLICKHOUSE_PASSWORD", ""), | ||
| "CLICKHOUSE_USERNAME": os.getenv("CLICKHOUSE_USERNAME", ""), | ||
| "HUD_INTERNAL_BOT_TOKEN": os.getenv("HUD_INTERNAL_BOT_TOKEN", ""), | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -71,13 +72,15 @@ def __init__( | |
| self, | ||
| config_id: str, | ||
| end_time: int, | ||
| hud_access_token: str = "", | ||
| is_dry_run: bool = False, | ||
| is_pass_check: bool = False, | ||
| ) -> None: | ||
| self.is_dry_run = is_dry_run | ||
| self.is_pass_check = is_pass_check | ||
| self.config_id = config_id | ||
| self.end_time = end_time | ||
| self.hud_access_token = hud_access_token | ||
|
|
||
| def log_info(self, msg: str): | ||
| logger.info("[%s][%s] %s", self.end_time, self.config_id, msg) | ||
|
|
@@ -136,13 +139,13 @@ def process( | |
| f"with frequency {report_freq.get_text()}..." | ||
| ) | ||
|
|
||
| target, ls, le = self.get_target(config, self.end_time) | ||
| target, ls, le = self.get_target(config, self.end_time,self.hud_access_token) | ||
| if not target.time_series: | ||
| self.log_info( | ||
| f"no target data found for time range [{ls},{le}] with frequency {report_freq.get_text()}..." | ||
| ) | ||
| return | ||
| baseline, bs, be = self.get_baseline(config, self.end_time) | ||
| baseline, bs, be = self.get_baseline(config, self.end_time, self.hud_access_token) | ||
|
|
||
| if not baseline.time_series: | ||
| self.log_info( | ||
|
|
@@ -165,7 +168,7 @@ def process( | |
| reportManager.run(cc, ENVS["GITHUB_TOKEN"]) | ||
| return | ||
|
|
||
| def get_target(self, config: BenchmarkConfig, end_time: int): | ||
| def get_target(self, config: BenchmarkConfig, end_time: int, hud_access_token: str): | ||
| data_range = config.policy.range | ||
| target_s = end_time - data_range.comparison_timedelta_s() | ||
| target_e = end_time | ||
|
|
@@ -178,10 +181,16 @@ def get_target(self, config: BenchmarkConfig, end_time: int): | |
| start_time=target_s, | ||
| end_time=target_e, | ||
| source=config.source, | ||
| access_token=hud_access_token, | ||
| ) | ||
| self.log_info( | ||
| f"done. found {len(target_data.time_series)} # of data groups, with time range {target_data.time_range}", | ||
| ) | ||
|
|
||
| if len(target_data.time_series) > 0: | ||
| self.log_info( | ||
| f"peeking the first data: {target_data.time_series[0]}", | ||
| ) | ||
| if not target_data.time_range or not target_data.time_range.end: | ||
| return None, target_s, target_e | ||
|
|
||
|
|
@@ -190,7 +199,7 @@ def get_target(self, config: BenchmarkConfig, end_time: int): | |
| return None, target_s, target_e | ||
| return target_data, target_s, target_e | ||
|
|
||
| def get_baseline(self, config: BenchmarkConfig, end_time: int): | ||
| def get_baseline(self, config: BenchmarkConfig, end_time: int, hud_access_token: str): | ||
| data_range = config.policy.range | ||
| baseline_s = end_time - data_range.total_timedelta_s() | ||
| baseline_e = end_time - data_range.comparison_timedelta_s() | ||
|
|
@@ -204,12 +213,18 @@ def get_baseline(self, config: BenchmarkConfig, end_time: int): | |
| start_time=baseline_s, | ||
| end_time=baseline_e, | ||
| source=config.source, | ||
| access_token=hud_access_token, | ||
| ) | ||
|
|
||
| self.log_info( | ||
| f"Done. found {len(raw_data.time_series)} # of data, with time range {raw_data.time_range}", | ||
| ) | ||
|
|
||
| if len(raw_data.time_series) > 0: | ||
| self.log_info( | ||
| f"peeking the first data: {raw_data.time_series[0]}", | ||
| ) | ||
|
|
||
| baseline_latest_ts = int(isoparse(raw_data.time_range.end).timestamp()) | ||
|
|
||
| if not self.should_use_data(baseline_latest_ts, baseline_e): | ||
|
|
@@ -245,6 +260,7 @@ def _fetch_from_benchmark_ts_api( | |
| config_id: str, | ||
| end_time: int, | ||
| start_time: int, | ||
| access_token: str, | ||
| source: BenchmarkApiSource, | ||
| ): | ||
| str_end_time = format_ts_with_t(end_time) | ||
|
|
@@ -261,7 +277,7 @@ def _fetch_from_benchmark_ts_api( | |
| t0 = time.perf_counter() | ||
| try: | ||
| resp: BenchmarkTimeSeriesApiResponse = ( | ||
| BenchmarkTimeSeriesApiResponse.from_request(url, query) | ||
| BenchmarkTimeSeriesApiResponse.from_request(url, query, access_token) | ||
| ) | ||
|
|
||
| elapsed_ms = (time.perf_counter() - t0) * 1000.0 | ||
|
|
@@ -353,6 +369,7 @@ def _get_latest_record_ts( | |
| def main( | ||
| config_id: str, | ||
| github_access_token: str = "", | ||
| hud_access_token: str = "", | ||
| args: Optional[argparse.Namespace] = None, | ||
| *, | ||
| is_dry_run: bool = False, | ||
|
|
@@ -392,6 +409,7 @@ def main( | |
| end_time=end_time_ts, | ||
| is_dry_run=is_dry_run, | ||
| is_pass_check=is_forced, | ||
| hud_access_token=hud_access_token, | ||
| ) | ||
| processor.process(args=args) | ||
| except Exception as e: | ||
|
|
@@ -411,6 +429,7 @@ def lambda_handler(event: Any, context: Any) -> None: | |
| main( | ||
| config_id=config_id, | ||
| github_access_token=ENVS["GITHUB_TOKEN"], | ||
| hud_access_token=ENVS["HUD_INTERNAL_BOT_TOKEN"], | ||
| ) | ||
| return | ||
|
|
||
|
|
@@ -473,11 +492,16 @@ def parse_args() -> argparse.Namespace: | |
| type=str, | ||
| help="the end time to run, in format of YYYY-MM-DD HH:MM:SS", | ||
| ) | ||
| parser.add_argument( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This looks redundant because it will default to |
||
| "--hud-internal-bot-token", | ||
| type=str, | ||
| default=ENVS["HUD_INTERNAL_BOT_TOKEN"], | ||
| help="the hud internal bot token to access hud api", | ||
| ) | ||
| parser.set_defaults(dry_run=True) # default is True | ||
| args, _ = parser.parse_known_args() | ||
| return args | ||
|
|
||
|
|
||
| def local_run() -> None: | ||
| """ | ||
| method to run in local test environment | ||
|
|
@@ -487,6 +511,7 @@ def local_run() -> None: | |
| # update environment variables for input parameters | ||
| main( | ||
| config_id=args.config_id, | ||
| hud_access_token=args.hud_internal_bot_token, | ||
| github_access_token=args.github_access_token, | ||
| args=args, | ||
| is_dry_run=args.dry_run, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: There are a couple for formatting changes in this PR that are rather unexpected like
access_token:strhere. A good BE task would be to enable linter for python lambda. I'm thinkingruff checkandruff format