Skip to content

Commit

Permalink
Make metric expiration time configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
scottopell committed Sep 24, 2024
1 parent 1843634 commit 00f9f33
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lading/src/bin/lading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtraCommands>,
Expand Down Expand Up @@ -304,8 +308,13 @@ fn get_config(ops: &Opts, config: Option<String>) -> Result<Config, Error> {
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 {
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion lading/src/captures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration>,
shutdown: lading_signal::Watcher,
experiment_started: lading_signal::Watcher,
target_running: lading_signal::Watcher,
Expand All @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions lading/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub enum Telemetry {
path: PathBuf,
/// Additional labels to include in every metric
global_labels: FxHashMap<String, String>,
/// Time to consider metrics 'expired' and not to be included in the log
metric_expiration_duration: Option<std::time::Duration>,
},
}

Expand Down

0 comments on commit 00f9f33

Please sign in to comment.