Skip to content
Merged
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
2 changes: 1 addition & 1 deletion rs/moq-relay/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Have the auth server mark cluster peers as `peer` (`moq auth serve --mtls-peer`)

`stats.interval`, `--stats-interval`, and `MOQ_STATS_INTERVAL` take a duration such as `"1s"` or `"500ms"` instead of a bare number of seconds, and a zero interval refuses to start.
Write `interval = 5` as `interval = "5s"`.
In Rust, `stats::Config::interval` is a `Duration`, and `stats::Config::build` returns a `Result`.
In Rust, `stats::Config::interval` is an `Option<Duration>` (`None` publishes every second), and `stats::Config::build` returns a `Result`.

### `receive_window` has a floor (#5878)

Expand Down
22 changes: 20 additions & 2 deletions rs/moq-relay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,24 @@ root = ["ca.pem"]
}
}

/// Stats enabled from the CLI alone build at the producer's default interval:
/// the parser fills a field it skips with its type's zero, not `Default`.
#[tokio::test]
async fn cli_stats_build_without_an_interval() {
if !test_env::Env::without(&["MOQ_STATS_ENABLED", "MOQ_STATS_INTERVAL"]).isolate() {
return;
}

let args = [
std::ffi::OsString::from("moq-relay"),
std::ffi::OsString::from("--stats-enabled"),
];
let config = Config::parse_and_merge(args).expect("config load");
assert!(config.stats.enabled);
let cluster = cluster::Cluster::new(cluster::Options::default()).expect("cluster");
config.stats.build(cluster.origin.clone()).expect("stats build");
}

/// Bare defaults loaded from TOML survive when the CLI does not mention them.
#[test]
fn cli_does_not_clobber_toml_stats_enabled() {
Expand Down Expand Up @@ -960,7 +978,7 @@ linger = "2m"
config.stats.enabled,
"TOML's stats.enabled=true must not be clobbered by CLI defaults"
);
assert_eq!(config.stats.interval(), std::time::Duration::from_secs(5));
assert_eq!(config.stats.interval(), Some(std::time::Duration::from_secs(5)));
assert_eq!(config.stats.node.as_deref(), Some("localhost"));
assert_eq!(config.stats.depth, 2);
assert_eq!(config.stats.linger(), Some(std::time::Duration::from_secs(120)));
Expand All @@ -973,7 +991,7 @@ linger = "2m"
];
let config = Config::parse_and_merge(args).expect("config load");
assert_eq!(config.stats.linger(), Some(std::time::Duration::from_secs(30)));
assert_eq!(config.stats.interval(), std::time::Duration::from_millis(250));
assert_eq!(config.stats.interval(), Some(std::time::Duration::from_millis(250)));
}

/// Bare runtime defaults loaded from TOML survive when the CLI omits them.
Expand Down
16 changes: 9 additions & 7 deletions rs/moq-relay/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct Config {
/// second.
#[usage(skip)]
#[serde(with = "humantime_serde")]
pub interval: Duration,
pub interval: Option<Duration>,

/// How often stats snapshots are published. Defaults to 1s.
#[usage(long = "stats-interval", env = "MOQ_STATS_INTERVAL", setting = "stats.interval")]
Expand Down Expand Up @@ -102,7 +102,7 @@ impl Default for Config {
Self {
enabled: false,
prefix: ".stats".into(),
interval: Duration::from_secs(1),
interval: None,
interval_arg: None,
node: None,
depth: 0,
Expand All @@ -113,9 +113,9 @@ impl Default for Config {
}

impl Config {
/// The interval after command-line overrides.
pub(crate) fn interval(&self) -> Duration {
self.interval_arg.map(Into::into).unwrap_or(self.interval)
/// The interval after command-line overrides; `None` keeps the producer's default.
pub(crate) fn interval(&self) -> Option<Duration> {
self.interval_arg.map(Into::into).or(self.interval)
}

/// The linger after command-line overrides; `None` keeps the producer's default.
Expand All @@ -136,17 +136,19 @@ impl Config {
}
let prefix = self.prefix.clone();
let interval = self.interval();
anyhow::ensure!(!interval.is_zero(), "stats.interval must be non-zero");
anyhow::ensure!(interval != Some(Duration::ZERO), "stats.interval must be non-zero");
let node = self.node.clone().map(PathOwned::from);
let depth = self.depth;
let linger = self.linger();
tracing::info!(prefix, ?interval, node = ?node, depth, ?linger, "stats publishing enabled");
let mut config = moq_stats::produce::Config::new()
.with_origin(origin)
.with_prefix(prefix)
.with_interval(interval)
.with_node(node)
.with_depth(depth);
if let Some(interval) = interval {
config = config.with_interval(interval);
}
if let Some(linger) = linger {
config = config.with_linger(linger);
}
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-relay/tests/integration/wire_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async fn wire_sources(io_uring: bool) {
config.auth.public = vec![moq_auth::Pattern::all()];
config.stats.enabled = true;
config.internal.listen = Some("127.0.0.1:0".parse().unwrap());
config.stats.interval = Duration::from_secs(3600);
config.stats.interval = Some(Duration::from_secs(3600));
config.drain_timeout = Duration::ZERO;
if io_uring {
config.runtime.workers = Some(1);
Expand Down
Loading