@@ -28,6 +28,14 @@ var rateLimitDenials = statz.NewCounter1[string]("signaling/rate_limits_denials"
2828 },
2929})
3030
31+ var rateLimitErrors = statz .NewCounter1 [string ]("signaling/rate_limit_errors" , statz.MetricConfig {
32+ Description : "Total number of errors while applying the rate limit." ,
33+ Unit : units .Dimensionless ,
34+ Labels : []statz.Label {
35+ {Name : "reason" , Description : "Reason that applying the rate limit failed." },
36+ },
37+ })
38+
3139// Database configuration and collection names for MongoDB rate limiter.
3240var (
3341 mongodbWebRTCRateLimiterCollName = "rate_limiter"
@@ -102,8 +110,10 @@ func (rl *MongoDBRateLimiter) Allow(ctx context.Context, key string) error {
102110 }},
103111 options .Update ().SetUpsert (true ))
104112 if err != nil {
105- rl .logger .Errorw ("rate limit doc existence check failed" , "error" , err , "key" , key )
106- return err
113+ // to not erroneously rate limit requests, we log the error but do not return the error.
114+ rl .logger .Infow ("rate limit doc existence check failed" , "error" , err , "key" , key )
115+ rateLimitErrors .Inc ("existence_check_failed" )
116+ return nil
107117 }
108118
109119 // Filter: only match if request count within the most recent window for this key is < MaxRequests
@@ -176,8 +186,10 @@ func (rl *MongoDBRateLimiter) Allow(ctx context.Context, key string) error {
176186
177187 result , err := rl .rateLimitColl .UpdateOne (ctx , filter , update )
178188 if err != nil {
179- rl .logger .Errorw ("rate limit operation failed" , "error" , err , "key" , key )
180- return err
189+ // to not erroneously rate limit requests, we log the error but do not return the error.
190+ rl .logger .Infow ("rate limit operation failed" , "error" , err , "key" , key )
191+ rateLimitErrors .Inc ("update_operation_failed" )
192+ return nil
181193 }
182194
183195 // No match means rate limit exceeded
0 commit comments