Skip to content

Commit

Permalink
add some logging so it is easier to see what grpc rate limits are set (
Browse files Browse the repository at this point in the history
…#1045)

Co-authored-by: Sean Reilly <[email protected]>
  • Loading branch information
reillyse and Sean Reilly authored Nov 15, 2024
1 parent 11ec54a commit d7d8039
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/services/grpc/middleware/rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (rl *HatchetRateLimiter) GetOrCreateTenantRateLimiter(rateLimitToken string
}

func NewHatchetRateLimiter(r rate.Limit, b int, l *zerolog.Logger) *HatchetRateLimiter {
l.Info().Msgf("grpc rate limit set to %v per second with a burst of %v (10X rate for Dispatcher)", r, b)
return &HatchetRateLimiter{
rateLimiters: make(map[string]*HatchetApiTokenRateLimiter),
rate: r,
Expand All @@ -69,19 +70,19 @@ func (r *HatchetRateLimiter) Limit(ctx context.Context) error {
case "dispatcher":

if !r.GetOrCreateTenantRateLimiter(rateLimitToken).dispatcherLimiter.Allow() {
r.l.Info().Msg("dispatcher rate limit exceeded")
r.l.Info().Msgf("dispatcher rate limit (%v per second) exceeded", r.GetOrCreateTenantRateLimiter(rateLimitToken).dispatcherLimiter.Limit())
return status.Errorf(codes.ResourceExhausted, "dispatcher rate limit exceeded")
}

case "events":
if !r.GetOrCreateTenantRateLimiter(rateLimitToken).eventsLimiter.Allow() {
r.l.Info().Msg("ingest rate limit exceeded")
r.l.Info().Msgf("ingest rate limit (%v per second) exceeded", r.GetOrCreateTenantRateLimiter(rateLimitToken).eventsLimiter.Limit())
return status.Errorf(codes.ResourceExhausted, "ingest rate limit exceeded")
}

case "workflow":
if !r.GetOrCreateTenantRateLimiter(rateLimitToken).workflowLimiter.Allow() {
r.l.Info().Msg("workflow rate limit exceeded")
r.l.Info().Msgf("workflow rate limit (%v per second) exceeded", r.GetOrCreateTenantRateLimiter(rateLimitToken).workflowLimiter.Limit())
return status.Errorf(codes.ResourceExhausted, "admin rate limit exceeded")
}

Expand Down

0 comments on commit d7d8039

Please sign in to comment.