diff --git a/lading/src/bin/lading.rs b/lading/src/bin/lading.rs index 563d575ea..4a1d3f25f 100644 --- a/lading/src/bin/lading.rs +++ b/lading/src/bin/lading.rs @@ -210,6 +210,10 @@ struct Opts { /// whether to ignore inspector configuration, if present, and not run the inspector #[clap(long)] disable_inspector: bool, + /// the time, in seconds, to consider a metric expired and not to be included in the capture + /// If set to 0, metrics will never expire + #[clap(long, default_value_t = 0)] + capture_metric_expiration_seconds: u64, /// Extra sub commands #[clap(subcommand)] extracmds: Option, @@ -304,8 +308,13 @@ fn get_config(ops: &Opts, config: Option) -> Result { global_labels: options_global_labels.inner, }; } else if let Some(ref capture_path) = ops.capture_path { + let metric_expiration_duration = match ops.capture_metric_expiration_seconds { + 0 => None, + _ => Some(std::time::Duration::from_secs(ops.capture_metric_expiration_seconds)), + }; config.telemetry = Telemetry::Log { path: capture_path.parse().map_err(|_| Error::CapturePath)?, + metric_expiration_duration, global_labels: options_global_labels.inner, }; } else { @@ -386,9 +395,11 @@ async fn inner_main( Telemetry::Log { path, global_labels, + metric_expiration_duration, } => { let mut capture_manager = CaptureManager::new( path, + metric_expiration_duration, shutdown_watcher.register()?, experiment_started_watcher.clone(), target_running_watcher.clone(), diff --git a/lading/src/captures.rs b/lading/src/captures.rs index cdb69a5ff..5d6200007 100644 --- a/lading/src/captures.rs +++ b/lading/src/captures.rs @@ -75,6 +75,7 @@ impl CaptureManager { /// Function will error if the underlying capture file cannot be opened. pub async fn new( capture_path: PathBuf, + metric_expiration_duration: Option, shutdown: lading_signal::Watcher, experiment_started: lading_signal::Watcher, target_running: lading_signal::Watcher, @@ -94,7 +95,7 @@ impl CaptureManager { recency: Recency::new( quanta::Clock::new(), MetricKindMask::COUNTER | MetricKindMask::GAUGE, - Some(Duration::from_secs(2)), + metric_expiration_duration, ), }), global_labels: FxHashMap::default(), diff --git a/lading/src/config.rs b/lading/src/config.rs index 5f680bf3a..2b48cc6f6 100644 --- a/lading/src/config.rs +++ b/lading/src/config.rs @@ -80,6 +80,8 @@ pub enum Telemetry { path: PathBuf, /// Additional labels to include in every metric global_labels: FxHashMap, + /// Time to consider metrics 'expired' and not to be included in the log + metric_expiration_duration: Option, }, }