-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added prometheus metrics to track lines written and bytes written per database. The write buffer does the tracking after validation of incoming line protocol. Tests added to verify.
- Loading branch information
Showing
7 changed files
with
301 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use std::borrow::Cow; | ||
|
||
use metric::{Metric, Registry, U64Counter}; | ||
|
||
#[derive(Debug)] | ||
pub(super) struct WriteMetrics { | ||
write_lines_total: Metric<U64Counter>, | ||
write_bytes_total: Metric<U64Counter>, | ||
} | ||
|
||
pub(super) const WRITE_LINES_TOTAL_NAME: &str = "influxdb3_write_lines_total"; | ||
pub(super) const WRITE_BYTES_TOTAL_NAME: &str = "influxdb3_write_bytes_total"; | ||
|
||
impl WriteMetrics { | ||
pub(super) fn new(metric_registry: &Registry) -> Self { | ||
let write_lines_total = metric_registry.register_metric::<U64Counter>( | ||
WRITE_LINES_TOTAL_NAME, | ||
"track total number of lines written to the database", | ||
); | ||
let write_bytes_total = metric_registry.register_metric::<U64Counter>( | ||
WRITE_BYTES_TOTAL_NAME, | ||
"track total number of bytes written to the database", | ||
); | ||
Self { | ||
write_lines_total, | ||
write_bytes_total, | ||
} | ||
} | ||
|
||
pub(super) fn record_lines<D: Into<String>>(&self, db: D, lines: u64) { | ||
let db: Cow<'static, str> = Cow::from(db.into()); | ||
self.write_lines_total.recorder([("db", db)]).inc(lines); | ||
} | ||
|
||
pub(super) fn record_bytes<D: Into<String>>(&self, db: D, bytes: u64) { | ||
let db: Cow<'static, str> = Cow::from(db.into()); | ||
self.write_bytes_total.recorder([("db", db)]).inc(bytes); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use metric::{Attributes, Registry}; | ||
|
||
use super::WriteMetrics; | ||
|
||
#[test] | ||
fn record_lines() { | ||
let metric_registry = Registry::new(); | ||
let metrics = WriteMetrics::new(&metric_registry); | ||
metrics.record_lines("foo", 64); | ||
metrics.record_lines(String::from("bar"), 256); | ||
assert_eq!( | ||
64, | ||
metrics | ||
.write_lines_total | ||
.get_observer(&Attributes::from(&[("db", "foo")])) | ||
.unwrap() | ||
.fetch() | ||
); | ||
assert_eq!( | ||
256, | ||
metrics | ||
.write_lines_total | ||
.get_observer(&Attributes::from(&[("db", "bar")])) | ||
.unwrap() | ||
.fetch() | ||
); | ||
} | ||
|
||
#[test] | ||
fn record_bytes() { | ||
let metric_registry = Registry::new(); | ||
let metrics = WriteMetrics::new(&metric_registry); | ||
metrics.record_bytes("foo", 64); | ||
metrics.record_bytes(String::from("bar"), 256); | ||
assert_eq!( | ||
64, | ||
metrics | ||
.write_bytes_total | ||
.get_observer(&Attributes::from(&[("db", "foo")])) | ||
.unwrap() | ||
.fetch() | ||
); | ||
assert_eq!( | ||
256, | ||
metrics | ||
.write_bytes_total | ||
.get_observer(&Attributes::from(&[("db", "bar")])) | ||
.unwrap() | ||
.fetch() | ||
); | ||
} | ||
} |
Oops, something went wrong.