chore(ci): add trigger context to rate-limit monitor#61007
Merged
Conversation
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
.github/scripts/monitor-github-rate-limit.js:44
`pr_number` is the only numeric PR field that bypasses the `num()` guard used for `changed_files`, `additions`, and `deletions`. While GitHub always returns a numeric PR number, the inconsistency means a non-numeric value (e.g. a stringified number from a mock or a future payload change) would be forwarded as-is rather than normalised to `null`.
```suggestion
pr_number: pr ? num(pr.number) : null,
```
### Issue 2 of 2
.github/scripts/monitor-github-rate-limit.test.js:128-137
The project prefers parameterised tests. The non-PR fallback case only exercises `push`; wrapping this in a `test.each` across the other trigger types the workflow can see (`schedule`, `workflow_dispatch`, `push` with no `ref`, etc.) would confirm the nulling logic holds for all of them with no additional boilerplate.
Reviews (1): Last reviewed commit: "chore(ci): add trigger context to rate-l..." | Re-trigger Greptile |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The
Monitor GitHub Rate Limitworkflow records the repo's/rate_limitsnapshot to PostHog on every PR open/synchronize and master push, but each sample only carries the aggregate per-resource numbers (used,remaining,limit). Nothing records what triggered the sample, so the time series can't be broken down by event type or PR characteristics — which makes it hard to see which kinds of CI activity drivecore(GITHUB_TOKEN) consumption.Changes
Adds a
buildTrigger(context)helper that tags every emitted sample with the triggering event context:trigger_event/trigger_action— e.g.pull_request/synchronize, orpushhead_ref,pr_number,pr_authorpr_changed_files,pr_additions,pr_deletionsThese merge into each
github_rate_limit_observedevent's properties. Non-PR events (push, schedule) fall back torefand leave the PR fields null. No change to triggers, cadence, permissions, or the measured bucket — purely additive instrumentation.Downstream in PostHog this enables breakdowns the aggregate series alone can't answer — burn rate by event type, and whether larger PRs correlate with higher per-event consumption.
How did you test this code?
I'm an agent (Claude Code) — automated tests only, no manual/live testing:
monitor-github-rate-limit.test.jswith two cases: one asserting the PR trigger fields are captured on each sample, one assertingbuildTriggerfalls back torefand nulls PR fields for non-PR events.npx jest .github/scripts/monitor-github-rate-limit.test.js→ 5/5 passing.Automatic notifications
Docs update
Not needed — internal CI/observability tooling.
🤖 Agent context
Authored with Claude Code while investigating
coreGITHUB_TOKEN rate-limit pressure. The monitor measures the aggregate per-repo bucket but can't attribute consumption to a workflow or event type; this is the first, lowest-effort ("event-level") attribution layer, reusing the existing high-frequency sample stream. A complementary per-workflow approach (snapshotuseddelta regressed against job elapsed time to cancel the shared-bucket background) was considered for finer attribution and deferred as a heavier follow-up. The PR-size fields are included deliberately to test whether large diffs correlate with higher per-event burn. Field set kept minimal and additive.