Skip to content
Closed
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions objectstore-metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ edition = "2024"
publish = false

[dependencies]
humantime-serde = { workspace = true }
metrics = { workspace = true }
metrics-exporter-dogstatsd = { workspace = true }
objectstore-log = { workspace = true }
Expand Down
22 changes: 22 additions & 0 deletions objectstore-metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ pub enum Error {
/// - `OS__METRICS__ADDR` — StatsD address (e.g. `127.0.0.1:8125` or `unixgram:///tmp/statsd.sock`)
/// - `OS__METRICS__PREFIX` — global metric name prefix
/// - `OS__METRICS__BUFFER_SIZE` — maximum payload length in bytes
/// - `OS__METRICS__FLUSH_INTERVAL` — exporter flush interval (e.g. `1s`)
/// - `OS__METRICS__TAGS__KEY=value` — per-key global tags
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct MetricsConfig {
Expand Down Expand Up @@ -250,6 +251,13 @@ pub struct MetricsConfig {
/// `OS__METRICS__BUFFER_SIZE`
pub buffer_size: Option<usize>,

/// Interval between exporter flushes. Defaults to ten seconds.
///
/// Shorter intervals retain more frequent gauge snapshots but increase export overhead.
/// Must be greater than zero. Set with `OS__METRICS__FLUSH_INTERVAL`.
#[serde(default = "default_flush_interval", with = "humantime_serde")]
pub flush_interval: std::time::Duration,

/// Global tags applied to all metrics.
///
/// Key-value pairs attached to every emitted metric. Useful for identifying
Expand Down Expand Up @@ -281,12 +289,17 @@ fn default_prefix() -> String {
"objectstore".to_owned()
}

fn default_flush_interval() -> std::time::Duration {
std::time::Duration::from_secs(10)
}

impl Default for MetricsConfig {
fn default() -> Self {
Self {
addr: None,
prefix: "objectstore".to_owned(),
buffer_size: None,
flush_interval: default_flush_interval(),
tags: BTreeMap::new(),
}
}
Expand All @@ -300,6 +313,14 @@ pub fn init(config: &MetricsConfig) -> Result<(), Error> {
let Some(ref addr) = config.addr else {
return Ok(());
};
if config.flush_interval.is_zero() {
return Err(
metrics_exporter_dogstatsd::BuildError::InvalidConfiguration {
reason: "metrics flush interval must be greater than zero".to_owned(),
}
.into(),
);
}

objectstore_log::info!("reporting metrics to statsd at {addr}");

Expand All @@ -313,6 +334,7 @@ pub fn init(config: &MetricsConfig) -> Result<(), Error> {
.with_remote_address(addr)?
.with_telemetry(true)
.with_aggregation_mode(AggregationMode::Aggressive)
.with_flush_interval(config.flush_interval)
.send_histograms_as_distributions(true)
.with_histogram_sampling(true)
.set_global_prefix(&config.prefix)
Expand Down
Loading