From 101db167c574765b76f0294d9a2772a4d17d0ffe Mon Sep 17 00:00:00 2001 From: Akshay Pant Date: Mon, 4 May 2026 12:55:21 +0530 Subject: [PATCH] chore(github): emit event when API rate limit exceeded Add Kubernetes event emission via EmitMessage when GitHub API rate limit remaining hits zero. This surfaces rate limit exhaustion as a Repository event, improving observability for operators. Signed-off-by: Akshay Pant --- pkg/provider/github/profiler.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/provider/github/profiler.go b/pkg/provider/github/profiler.go index 93bd4cfc10..bdfef1da70 100644 --- a/pkg/provider/github/profiler.go +++ b/pkg/provider/github/profiler.go @@ -8,10 +8,12 @@ import ( "github.com/google/go-github/v85/github" providerMetrics "github.com/openshift-pipelines/pipelines-as-code/pkg/provider/providermetrics" + "go.uber.org/zap" ) const ( // Rate limit warning thresholds. + rateLimitExceeded = 0 // Error when remaining calls are 0 rateLimitCritical = 50 // Warn when remaining calls < 50 rateLimitWarning = 100 // Warn when remaining calls < 100 rateLimitInfo = 500 // Info when remaining calls < 500 @@ -69,6 +71,13 @@ func (v *Provider) checkRateLimit(resp *github.Response) (remaining string) { "reset", reset, } switch { + case remainingCount == rateLimitExceeded: + v.Logger.Errorw("GitHub API rate limit exceeded", logFields...) + if v.eventEmitter != nil { + v.eventEmitter.EmitMessage( + v.repo, zap.ErrorLevel, "GitHubRateLimitExceeded", + fmt.Sprintf("GitHub API rate limit exceeded, limit: %s, resets at: %s", limit, reset)) + } case remainingCount < rateLimitCritical: v.Logger.Errorw("GitHub API rate limit critically low", logFields...) case remainingCount < rateLimitWarning: