()
| 448 | } |
| 449 | |
| 450 | func (cnf *Configuration) setupRateLimiting() { |
| 451 | |
| 452 | if cnf.RateLimit.RequestsPerSecond == nil && cnf.RateLimit.Burst == nil { |
| 453 | defaultRPS := 5000000.0 |
| 454 | defaultBurst := 10000000 |
| 455 | |
| 456 | cnf.RateLimit.RequestsPerSecond = &defaultRPS |
| 457 | cnf.RateLimit.Burst = &defaultBurst |
| 458 | |
| 459 | logrus.WithFields(logrus.Fields{ |
| 460 | "rps": defaultRPS, |
| 461 | "burst": defaultBurst, |
| 462 | }).Info("rate limiting not configured, using defaults") |
| 463 | } |
| 464 | |
| 465 | if cnf.RateLimit.RequestsPerSecond != nil && cnf.RateLimit.Burst == nil { |
| 466 | defaultBurst := 2 * int(*cnf.RateLimit.RequestsPerSecond) |
| 467 | cnf.RateLimit.Burst = &defaultBurst |
| 468 | logrus.WithField("burst", defaultBurst).Warn("rate limit burst not specified, setting default") |
| 469 | } |
| 470 | if cnf.RateLimit.RequestsPerSecond == nil && cnf.RateLimit.Burst != nil { |
| 471 | defaultRPS := float64(*cnf.RateLimit.Burst) / 2 |
| 472 | cnf.RateLimit.RequestsPerSecond = &defaultRPS |
| 473 | logrus.WithField("rps", defaultRPS).Warn("rate limit RPS not specified, setting default") |
| 474 | } |
| 475 | if cnf.RateLimit.CleanupIntervalSec == nil { |
| 476 | defaultCleanup := DEFAULT_CLEANUP_SEC |
| 477 | cnf.RateLimit.CleanupIntervalSec = &defaultCleanup |
| 478 | logrus.WithField("cleanup_interval_sec", defaultCleanup).Warn("rate limit cleanup interval not specified, setting default") |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | // MockConfig sets a mock configuration for testing purposes. |
| 483 | func MockConfig(mockConfig *Configuration) { |
no test coverage detected