Repository navigation
fix(appset): request max page size from Bitbucket Cloud pull request API to reduce rate limiting - #30063
fix(appset): request max page size from Bitbucket Cloud pull request API to reduce rate limiting#30063roulettedares wants to merge 1 commit into
Conversation
❗ Preview Environment deployment failed on BunnyshellSee: Environment Details | Pipeline Logs Available commands (reply to this comment):
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe Bitbucket Cloud client constructors now set the page size to 50. Tests use that value for initial requests, paginated requests, and pagination links. ChangesBitbucket Cloud pagination
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to The change raises the requested page size while retaining pagination coverage; no concrete merge-blocking risk is evident. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bundle ReportBundle size has no change ✅ |
…API to reduce rate limiting The Bitbucket Cloud pull request generator never set a page size, so the go-bitbucket client used its default of 10. Listing a repo's open pull requests therefore costs ceil(N/10) API calls on every ApplicationSet reconcile. Bitbucket Cloud allows 1,000 requests per hour to the repositories API on a rolling window, so a workspace with several active repos (e.g. during a burst of Renovate PR updates) exhausts the budget and reconciles fail with 429 Too Many Requests for over an hour. Request pagelen=50, the maximum Bitbucket Cloud accepts for this endpoint (pagelen=100 is rejected with 400 'Invalid pagelen'). This matches the intent of the other providers, which already request 100 per page (GitHub, GitLab, Bitbucket Server). For a repo with 81 open PRs this drops the per-reconcile cost from 9 calls to 2. Both the basic-auth and bearer-token constructors are covered; the no-auth constructor routes through the bearer-token one. Signed-off-by: Joshua S <20404891+roulettedares@users.noreply.github.com>
7da020f to
0a982f7
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #30063 +/- ##
==========================================
+ Coverage 72.34% 72.35% +0.01%
==========================================
Files 434 434
Lines 56289 56291 +2
==========================================
+ Hits 40721 40729 +8
+ Misses 15568 15562 -6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Problem
The Bitbucket Cloud pull request generator never sets a page size, so the underlying
go-bitbucketclient uses its default of 10 (DEFAULT_PAGE_LENGTH). Listing a repository's open pull requests therefore costsceil(N/10)API calls on every ApplicationSet reconcile — e.g. 9 calls for a repo with 81 open PRs.Bitbucket Cloud enforces a limit of 1,000 requests per hour on
/2.0/repositories/*(rolling window). In a workspace with several active repositories plus a burst of PR activity (e.g. a Renovate run updating many PRs), the generator's polling exhausts that budget, and every subsequent reconcile fails with429 Too Many Requestsfor over an hour.The other pull request generators already request large pages: GitHub and GitLab use
PerPage: 100, Bitbucket Server useslimit: 100. Bitbucket Cloud is the outlier.Fix
Set
Pagelen = 50on the Bitbucket Cloud client in both the basic-auth and bearer-token constructors (the no-auth constructor routes through the bearer-token one). 50 is the maximum Bitbucket Cloud accepts for this endpoint —pagelen=100is rejected with400 Invalid pagelen(verified against the live API; see pagination docs, max page size varies by endpoint).For the 81-open-PRs example this drops the cost from 9 calls to 2 per repo per reconcile — a 4–5x reduction in API consumption against the hourly budget. Pagination is unchanged: the client still follows Bitbucket's
nextlinks (which carry the requested page size).Related context: #27644 adds webhook support for this generator, which reduces how often polling happens; this PR reduces what each poll costs. They are independent.
Testing
httptest-based unit tests to assert that requests to/repositories/{owner}/{repo}/pullrequestscarrypagelen=50for both the basic-auth and bearer-token constructors, and kept multi-page coverage (nextlinks are still followed).go test ./applicationset/services/pull_request/...,go vet, andgolangci-lint runon the package all pass locally.pagelen=50is accepted andpagelen=100is rejected by the live Bitbucket Cloud API for the pull requests endpoint.This is a low-risk fix that could be cherry-picked into supported release branches.
Checklist:
Summary by CodeRabbit