Commit 408f2ad
Fix GitHub rate limit in project_setup by using recursive tree fetch (#5107)
## Description
This PR addresses the GitHub API rate limiting issues encountered during
the `project_setup` cron job execution for OSS-Fuzz projects.
### Problem
The previous implementation of `get_oss_fuzz_projects` made multiple API
calls per project (fetching directory trees individually), resulting in
O(N) requests where N is the number of projects. This frequently
triggered GitHub's rate limits (403 Forbidden).
### Solution
Optimized the project fetching logic to use the `recursive=1` parameter
when fetching the OSS-Fuzz repository tree.
- Fetches the entire directory tree in a single API call (O(1)).
- Uses SHA from the tree to cache `project.yaml` contents, skipping
unchanged files.
- Disables retries specifically for 403 errors to prevent retry storms.
- Parses the flattened tree structure to identify projects with
`project.yaml` and `Dockerfile`.
- Significantly reduces the API request count, mitigating rate limit
issues.
### Verification
- **Regression Testing**: Ran existing tests in
`src/clusterfuzz/_internal/tests/appengine/handlers/cron/project_setup_test.py`.
All passed.
- **New Tests**: Added `test_get_oss_fuzz_projects_api_error` to verify
error handling when the API call fails.
- **Mock Data**: Updated `url_results.txt` to include a mock response
for the recursive tree fetch, covering edge cases like:
- Invalid/Malformed YAML.
- Nested files (ignored).
- Files at root (ignored).
- Projects without YAML (ignored).
### Impact
- **Performance**: Drastic reduction in GitHub API calls.
- **Reliability**: Reduced likelihood of cron job failures due to rate
limiting.
- **Scope**: Changes are isolated to `project_setup.py` and only affect
the OSS-Fuzz project source flow.
---------
Co-authored-by: André Nogueira Ribeiro <94117783+decoNR@users.noreply.github.com>1 parent e84526d commit 408f2ad
File tree
4 files changed
+173
-43
lines changed- src/clusterfuzz/_internal
- cron
- datastore
- tests/appengine/handlers/cron
- project_setup_data
4 files changed
+173
-43
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
83 | 92 | | |
84 | 93 | | |
85 | 94 | | |
| |||
218 | 227 | | |
219 | 228 | | |
220 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
221 | 235 | | |
222 | 236 | | |
223 | 237 | | |
| |||
227 | 241 | | |
228 | 242 | | |
229 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
230 | 248 | | |
231 | 249 | | |
232 | 250 | | |
233 | | - | |
| 251 | + | |
234 | 252 | | |
235 | 253 | | |
236 | 254 | | |
237 | 255 | | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | 256 | | |
248 | 257 | | |
249 | 258 | | |
250 | | - | |
| 259 | + | |
251 | 260 | | |
252 | | - | |
253 | 261 | | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
| 262 | + | |
| 263 | + | |
258 | 264 | | |
259 | | - | |
260 | 265 | | |
261 | | - | |
| 266 | + | |
| 267 | + | |
262 | 268 | | |
263 | 269 | | |
264 | | - | |
265 | | - | |
266 | | - | |
| 270 | + | |
| 271 | + | |
267 | 272 | | |
268 | 273 | | |
269 | | - | |
270 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
271 | 283 | | |
272 | | - | |
273 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
274 | 313 | | |
275 | 314 | | |
276 | 315 | | |
277 | | - | |
| 316 | + | |
278 | 317 | | |
279 | 318 | | |
280 | 319 | | |
| |||
286 | 325 | | |
287 | 326 | | |
288 | 327 | | |
289 | | - | |
| 328 | + | |
290 | 329 | | |
291 | 330 | | |
292 | 331 | | |
| |||
533 | 572 | | |
534 | 573 | | |
535 | 574 | | |
536 | | - | |
| 575 | + | |
537 | 576 | | |
538 | 577 | | |
539 | 578 | | |
| |||
561 | 600 | | |
562 | 601 | | |
563 | 602 | | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
564 | 607 | | |
565 | 608 | | |
566 | 609 | | |
| |||
574 | 617 | | |
575 | 618 | | |
576 | 619 | | |
577 | | - | |
| 620 | + | |
| 621 | + | |
578 | 622 | | |
579 | 623 | | |
580 | 624 | | |
| |||
1010 | 1054 | | |
1011 | 1055 | | |
1012 | 1056 | | |
1013 | | - | |
| 1057 | + | |
1014 | 1058 | | |
1015 | 1059 | | |
1016 | 1060 | | |
| |||
1038 | 1082 | | |
1039 | 1083 | | |
1040 | 1084 | | |
1041 | | - | |
| 1085 | + | |
| 1086 | + | |
1042 | 1087 | | |
1043 | 1088 | | |
1044 | 1089 | | |
1045 | | - | |
| 1090 | + | |
1046 | 1091 | | |
1047 | 1092 | | |
1048 | 1093 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1476 | 1476 | | |
1477 | 1477 | | |
1478 | 1478 | | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
1479 | 1482 | | |
1480 | 1483 | | |
1481 | 1484 | | |
| |||
Lines changed: 71 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
243 | 314 | | |
244 | 315 | | |
0 commit comments