Skip to content

feat(metrics): add GitHub API rate limit metrics#138

Draft
aparajon wants to merge 2 commits into
mainfrom
aparajon/github-rate-limit-metrics
Draft

feat(metrics): add GitHub API rate limit metrics#138
aparajon wants to merge 2 commits into
mainfrom
aparajon/github-rate-limit-metrics

Conversation

@aparajon
Copy link
Copy Markdown
Collaborator

🤖 Generated by Codex on behalf of @aparajon.

Summary

  • Add GitHub API request and primary rate-limit metrics for SchemaBot
  • Categorize GitHub calls as read, write, or auth for dashboarding write pressure
  • Normalize unknown GitHub metric labels while logging the raw values for discovery
  • Bump go-github and ghinstallation to current versions for rate-limit response fields

Copilot AI review requested due to automatic review settings May 21, 2026 17:48
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds observability for GitHub API usage in SchemaBot by recording per-operation request counts and primary rate-limit headers (limit/remaining/used), and updates GitHub client dependencies to versions that expose the necessary response fields.

Changes:

  • Introduce schemabot.github.requests_total and schemabot.github.rate_limit.* metrics, including label normalization/allowlisting.
  • Instrument REST and GraphQL GitHub calls (including auth/token exchange via transport) to emit request and rate-limit metrics.
  • Bump go-github and ghinstallation versions and update affected test imports.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/webhook/webhook_e2e_test.go Update go-github import to v86 in webhook E2E tests.
pkg/webhook/testhelpers_test.go Update go-github import to v86 in webhook test helpers.
pkg/webhook/review_gate_test.go Update go-github import to v86 in review gate tests.
pkg/webhook/review_gate_e2e_test.go Update go-github import to v86 in review gate E2E tests.
pkg/webhook/apply_e2e_test.go Update go-github import to v86 in apply E2E tests.
pkg/webhook/apply_comment_e2e_test.go Update go-github import to v86 in apply-comment E2E tests.
pkg/metrics/README.md Document new GitHub request + primary rate-limit metrics and recommended dashboards.
pkg/metrics/metrics.go Add GitHub metric constants, normalization/allowlisting, and recorders for new metrics.
pkg/metrics/github_metrics_test.go Add unit tests for GitHub label normalization.
pkg/github/reviews.go Emit GitHub response metrics for reviews/team-members/reviewer-request operations.
pkg/github/rate_limit_metrics.go Add HTTP transport + helpers to record GitHub request + rate-limit headers (incl. GraphQL/auth).
pkg/github/rate_limit_metrics_test.go Add tests validating header-based rate-limit metric recording behavior.
pkg/github/pr_info_cache_test.go Update go-github import to v86 in PR info cache tests.
pkg/github/config_test.go Update go-github import to v86 in GitHub config tests.
pkg/github/client.go Wrap transports/clients to record GitHub metrics; record responses for key REST operations.
go.mod Bump go-github to v86 and ghinstallation to v2.18.0.
go.sum Update sums for bumped dependencies and transitive changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/metrics/metrics.go
Comment on lines +477 to +483
func normalizeGitHubOperation(operation string) string {
if isKnownGitHubOperation(operation) {
return operation
}
slog.Warn("GitHub metric operation label normalized to unknown", "operation", operation)
return gitHubMetricValueUnknown
}
Comment thread pkg/github/rate_limit_metrics.go Outdated
Comment on lines +118 to +123
if !hasLimit && !hasRemaining {
return
}

used, hasUsed := parseGitHubRateLimitHeader(resp.Header, headerRateLimitUsed)
if !hasUsed && hasLimit && hasRemaining {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants