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
29 changes: 29 additions & 0 deletions orb-dogd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ pub(crate) enum Metric {
val: f64,
tags: Vec<String>,
},
/// Milliseconds latency value; emits Datadog's `|ms` type.
/// Used by [`MetricEmitter::timing`].
Timing {
stat: String,
val: i64,
tags: Vec<String>,
},
}

impl Default for DogstatsdClient {
Expand Down Expand Up @@ -111,6 +118,11 @@ impl DogstatsdClient {
warn!("emitting metric failed with: {e}");
}
}
Metric::Timing { stat, val, tags } => {
if let Err(e) = client.timing(stat, val, tags) {
warn!("emitting metric failed with: {e}");
}
}
}
}
});
Expand Down Expand Up @@ -192,4 +204,21 @@ impl MetricEmitter for DogstatsdClient {
};
self.emit(metric)
}

fn timing<S, I>(&self, stat: S, val: i64, tags: I) -> Result<(), MetricError>
where
S: Into<String>,
I: IntoIterator<Item: Into<String>>,
{
let metric = Metric::Timing {
stat: stat.into(),
val,
tags: tags.into_iter().map(Into::into).collect(),
};
self.tx
.send(metric)
.map_err(|_| eyre::eyre!("metrics worker has died"))?;

Ok(())
}
}
7 changes: 7 additions & 0 deletions orb-dogd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ pub trait MetricEmitter: Send + Sync + 'static {
where
S: Into<String>,
I: IntoIterator<Item: Into<String>>;

/// Latency in milliseconds; emits Datadog's `|ms` type, which the
/// backend treats as a timing-flavored histogram.
fn timing<S, I>(&self, stat: S, val: i64, tags: I) -> Result<(), MetricError>
where
S: Into<String>,
I: IntoIterator<Item: Into<String>>;
}
22 changes: 22 additions & 0 deletions orb-dogd/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ impl MetricEmitter for MetricRecorder {
self.records.lock().expect("mutex poisoned").push(metric);
Ok(())
}

fn timing<S, I>(&self, stat: S, val: i64, tags: I) -> Result<(), MetricError>
where
S: Into<String>,
I: IntoIterator<Item: Into<String>>,
{
let metric = Metric::Timing {
stat: stat.into(),
val,
tags: tags.into_iter().map(Into::into).collect(),
};
self.records.lock().expect("mutex poisoned").push(metric);
Ok(())
}
}

/// [`MetricEmitter`] that drops every metric on the floor. Useful when test
Expand Down Expand Up @@ -153,6 +167,14 @@ impl MetricEmitter for MetricSinkhole {
{
Ok(())
}

fn timing<S, I>(&self, _: S, _: i64, _: I) -> Result<(), MetricError>
where
S: Into<String>,
I: IntoIterator<Item: Into<String>>,
{
Ok(())
}
}

#[cfg(test)]
Expand Down
Loading