(requestConfig, callback)
| 18 | } |
| 19 | |
| 20 | function validateRateLimitConfig(requestConfig, callback) { |
| 21 | const limit = requestConfig.RequestsPerSecond; |
| 22 | if (Number.isNaN(limit) || !Number.isInteger(limit) || limit < 0) { |
| 23 | return callback(errorInstances.InvalidArgument |
| 24 | .customizeDescription('RequestsPerSecond must be a positive integer')); |
| 25 | } |
| 26 | |
| 27 | // Validate limit against node count AND worker count |
| 28 | const nodes = config.rateLimiting?.nodes || 1; |
| 29 | const workers = config.clusters || 1; |
| 30 | const minLimit = nodes * workers; |
| 31 | |
| 32 | if (limit > 0 && limit < minLimit) { |
| 33 | return callback(errorInstances.InvalidArgument |
| 34 | .customizeDescription( |
| 35 | `RequestsPerSecond (${limit}) must be >= ` + |
| 36 | `(nodes x workers = ${nodes} x ${workers} = ${minLimit}) or 0 (unlimited). ` + |
| 37 | 'Each worker enforces limit/nodes/workers locally. ' + |
| 38 | `With limit less than ${minLimit}, per-worker rate would be less than 1 req/s, ` + |
| 39 | 'effectively blocking traffic.' |
| 40 | )); |
| 41 | } |
| 42 | |
| 43 | return callback(null, new models.RateLimitConfiguration({ |
| 44 | RequestsPerSecond: { |
| 45 | Limit: limit, |
| 46 | }, |
| 47 | })); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * bucketPutRateLimit - create or update a bucket policy |
no outgoing calls
no test coverage detected