MCPcopy Create free account
hub / github.com/rilldata/rill / checkRateLimit

Method checkRateLimit

runtime/server/server.go:394–413  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

392}
393
394func (s *Server) checkRateLimit(ctx context.Context) (context.Context, error) {
395 // Any request type might be limited separately as it is part of Metadata
396 // Any request type might be excluded from this limit check and limited later,
397 // e.g. in the corresponding request handler by calling s.limiter.Limit(ctx, "limitKey", redis_rate.PerMinute(100))
398 if auth.GetClaims(ctx, "").UserID == "" {
399 method, ok := grpc.Method(ctx)
400 if !ok {
401 return ctx, fmt.Errorf("server context does not have a method")
402 }
403 limitKey := ratelimit.AnonLimitKey(method, observability.GrpcPeer(ctx))
404 if err := s.limiter.Limit(ctx, limitKey, ratelimit.Public); err != nil {
405 if errors.As(err, &ratelimit.QuotaExceededError{}) {
406 return ctx, status.Error(codes.ResourceExhausted, err.Error())
407 }
408 return ctx, err
409 }
410 }
411
412 return ctx, nil
413}
414
415func (s *Server) addInstanceRequestAttributes(ctx context.Context, instanceID string) {
416 attrs := s.runtime.GetInstanceAttributes(ctx, instanceID)

Callers

nothing calls this directly

Calls 6

GetClaimsFunction · 0.92
AnonLimitKeyFunction · 0.92
GrpcPeerFunction · 0.92
ErrorfMethod · 0.65
LimitMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected