Add semaphore to limit concurrent API calls during Kubernetes observer startup#11
Conversation
…r startup closes PrefectHQ#19937 When the observer starts, it receives events for all existing pods/jobs and checks for duplicates via API calls. This can overwhelm the server when there are many pods. This change adds a configurable semaphore (default: 5 concurrent calls) to rate-limit these startup checks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5297067fd8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| response = await orchestration_client.request( | ||
| "POST", | ||
| "/events/filter", | ||
| json=dict(filter=event_filter.model_dump(exclude_unset=True, mode="json")), | ||
| json=dict( |
There was a problem hiding this comment.
Keep the semaphore held during the API request
The startup semaphore is acquired only while building event_filter, but the actual orchestration_client.request happens after the async with block has exited (see the request at lines 153-156). This means concurrent startup events still send API calls without any throttling, so the intended protection against API overload when many existing pods/jobs are present does not actually take effect. Consider keeping the request inside the semaphore scope.
Useful? React with 👍 / 👎.
Benchmark PR from agentic-review-benchmarks#11