fix(scripts): avoid GitHub API rate limit when resolving latest TiDB version (macOS)#3961
Conversation
|
Skipping CI for Draft Pull Request. |
Summary of ChangesHello @wlwilliamx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue in the macOS integration test binaries download script where anonymous GitHub API requests for the latest TiDB version were frequently hitting rate limits, leading to test failures. By switching the version resolution mechanism to leverage the 'releases/latest' redirect URL, the script now employs a more stable and reliable method to obtain the most recent TiDB tag, ensuring uninterrupted execution of integration tests. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates the script for downloading macOS integration test binaries to avoid GitHub API rate-limiting. The change cleverly switches from parsing the GitHub API JSON response to resolving the /releases/latest redirect URL to determine the latest TiDB version. This is a more robust approach. My review includes a fix for a bug in the wget implementation that would cause it to fail, and an improvement to the curl implementation for better error handling and clarity. Overall, this is a great improvement.
| latest_version=$(wget -qO- https://api.github.com/repos/pingcap/tidb/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') | ||
| effective_url=$( | ||
| wget --spider --server-response --max-redirect=20 --timeout=10 --tries=3 \ | ||
| "$latest_url" 2>&1 | awk '/^ Location: / {url=$2} END {print url}' | tr -d '\r' || true |
There was a problem hiding this comment.
The awk command uses a case-sensitive pattern /^ Location: / to parse the wget output. HTTP headers are case-insensitive, and wget often outputs the header as lowercase location:. This will cause the pattern to not match, making the script fall back to the hardcoded version. To fix this, the awk pattern should be made case-insensitive.
| "$latest_url" 2>&1 | awk '/^ Location: / {url=$2} END {print url}' | tr -d '\r' || true | |
| "$latest_url" 2>&1 | awk '/^ [Ll]ocation: / {url=$2} END {print url}' | tr -d '\r' || true |
| curl -sSL --max-time 10 --retry 3 --retry-delay 1 \ | ||
| -o /dev/null -w '%{url_effective}' "$latest_url" 2>/dev/null || true |
There was a problem hiding this comment.
The curl command uses -sSL, which on many systems is interpreted as just -s -L, ignoring the -S for showing errors. Furthermore, stderr is redirected to /dev/null, which suppresses any error messages, making debugging difficult. To make the command more explicit and robust, I suggest using -sS -L and removing the stderr redirection. This will ensure errors are shown on failure, while || true still prevents the script from exiting.
| curl -sSL --max-time 10 --retry 3 --retry-delay 1 \ | |
| -o /dev/null -w '%{url_effective}' "$latest_url" 2>/dev/null || true | |
| curl -sS -L --max-time 10 --retry 3 --retry-delay 1 \ | |
| -o /dev/null -w '%{url_effective}' "$latest_url" || true |
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: 3AceShowHand, tenfyzhong The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
/override pull-cdc-kafka-integration-heavy |
|
@wlwilliamx: Overrode contexts on behalf of wlwilliamx: pull-cdc-kafka-integration-heavy DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/override pull-cdc-mysql-integration-heavy |
|
@wlwilliamx: Overrode contexts on behalf of wlwilliamx: pull-cdc-mysql-integration-heavy DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/override pull-cdc-storage-integration-heavy |
|
@wlwilliamx: Overrode contexts on behalf of wlwilliamx: pull-cdc-storage-integration-heavy DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
What problem does this PR solve?
Issue Number: close #3960
What is changed and how it works?
The macOS integration test binaries download script currently uses the GitHub REST API to resolve the latest TiDB tag, which is often rate-limited (403) for anonymous requests. This PR switches to resolving the tag via the
releases/latestredirect URL instead.Check List
Tests
Questions
Will it cause performance regression or break compatibility?
None
Do you need to update user documentation, design documentation or monitoring documentation?
None
Release note