Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions fact/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const CONFIG_FILES: [&str; 4] = [
"fact.yaml",
];

/// Default maximum number of file events allowed per second when
/// `rate_limit` is not configured. A value of 0 means unlimited.
pub(crate) const DEFAULT_RATE_LIMIT: u64 = 400;

fn yaml_to_duration_secs(v: &Yaml) -> Option<Duration> {
v.as_f64()
.or_else(|| v.as_i64().map(|i| i as f64))
Expand Down Expand Up @@ -140,7 +144,7 @@ impl FactConfig {
}

pub fn rate_limit(&self) -> u64 {
self.rate_limit.unwrap_or(0)
self.rate_limit.unwrap_or(DEFAULT_RATE_LIMIT)
}

pub fn replay(&self) -> Option<&Path> {
Expand Down Expand Up @@ -996,7 +1000,7 @@ pub struct FactCli {
/// Events exceeding this rate will be dropped. A value of 0
/// means unlimited (no throttling).
///
/// Default value is 0 (unlimited)
/// Default value is 400
#[arg(long, short = 'l', env = "FACT_RATE_LIMIT")]
rate_limit: Option<u64>,

Expand Down
6 changes: 3 additions & 3 deletions fact/src/config/reloader/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,21 @@ generate_rate_limit_test! {
..Default::default()
},
FactConfig::default(),
Some(0)
Some(crate::config::DEFAULT_RATE_LIMIT)
}
generate_rate_limit_test! {
test_reloader_rate_limit_from_default_to_explicit_default,
FactConfig::default(),
FactConfig {
rate_limit: Some(0),
rate_limit: Some(crate::config::DEFAULT_RATE_LIMIT),
..Default::default()
},
None
}
generate_rate_limit_test! {
test_reloader_rate_limit_to_default_from_explicit_default,
FactConfig {
rate_limit: Some(0),
rate_limit: Some(crate::config::DEFAULT_RATE_LIMIT),
..Default::default()
},
FactConfig::default(),
Expand Down
2 changes: 1 addition & 1 deletion fact/src/config/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2094,7 +2094,7 @@ fn defaults() {
assert_eq!(config.grpc.backoff.retries(), 10);
assert_eq!(config.otel.endpoint(), None);
assert_eq!(config.scan_interval(), Duration::from_secs(30));
assert_eq!(config.rate_limit(), 0);
assert_eq!(config.rate_limit(), DEFAULT_RATE_LIMIT);
assert!(config.replay().is_none());
}

Expand Down
Loading