Skip to content

Commit c615efb

Browse files
theakshaypantzakisk
authored andcommitted
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 <akpant@redhat.com>
1 parent 74b0d28 commit c615efb

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

pkg/provider/github/profiler.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import (
88

99
"github.com/google/go-github/v85/github"
1010
providerMetrics "github.com/openshift-pipelines/pipelines-as-code/pkg/provider/providermetrics"
11+
"go.uber.org/zap"
1112
)
1213

1314
const (
1415
// Rate limit warning thresholds.
16+
rateLimitExceeded = 0 // Error when remaining calls are 0
1517
rateLimitCritical = 50 // Warn when remaining calls < 50
1618
rateLimitWarning = 100 // Warn when remaining calls < 100
1719
rateLimitInfo = 500 // Info when remaining calls < 500
@@ -69,6 +71,13 @@ func (v *Provider) checkRateLimit(resp *github.Response) (remaining string) {
6971
"reset", reset,
7072
}
7173
switch {
74+
case remainingCount == rateLimitExceeded:
75+
v.Logger.Errorw("GitHub API rate limit exceeded", logFields...)
76+
if v.eventEmitter != nil {
77+
v.eventEmitter.EmitMessage(
78+
v.repo, zap.ErrorLevel, "GitHubRateLimitExceeded",
79+
fmt.Sprintf("GitHub API rate limit exceeded, limit: %s, resets at: %s", limit, reset))
80+
}
7281
case remainingCount < rateLimitCritical:
7382
v.Logger.Errorw("GitHub API rate limit critically low", logFields...)
7483
case remainingCount < rateLimitWarning:

0 commit comments

Comments
 (0)