-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: track lines rejected in prometheus metrics #25722
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,37 +4,51 @@ use metric::{Metric, Registry, U64Counter}; | |
|
||
#[derive(Debug)] | ||
pub(super) struct WriteMetrics { | ||
write_lines_total: Metric<U64Counter>, | ||
write_bytes_total: Metric<U64Counter>, | ||
write_lines_count: Metric<U64Counter>, | ||
write_lines_rejected_count: Metric<U64Counter>, | ||
write_bytes_count: 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"; | ||
pub(super) const WRITE_LINES_METRIC_NAME: &str = "influxdb3_write_lines"; | ||
pub(super) const WRITE_LINES_REJECTED_METRIC_NAME: &str = "influxdb3_write_lines_rejected"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should end in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mentioned this in the PR description, but our Prometheus exporter adds a "_total" to the end of metric names that use a counter on export, which is why I removed it from the names here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry, I should have read that closer! |
||
pub(super) const WRITE_BYTES_METRIC_NAME: &str = "influxdb3_write_bytes"; | ||
|
||
impl WriteMetrics { | ||
pub(super) fn new(metric_registry: &Registry) -> Self { | ||
let write_lines_total = metric_registry.register_metric::<U64Counter>( | ||
WRITE_LINES_TOTAL_NAME, | ||
let write_lines_count = metric_registry.register_metric::<U64Counter>( | ||
WRITE_LINES_METRIC_NAME, | ||
"track total number of lines written to the database", | ||
); | ||
let write_bytes_total = metric_registry.register_metric::<U64Counter>( | ||
WRITE_BYTES_TOTAL_NAME, | ||
let write_lines_rejected_count = metric_registry.register_metric::<U64Counter>( | ||
WRITE_LINES_REJECTED_METRIC_NAME, | ||
"track total number of lines written to the database that were rejected", | ||
); | ||
let write_bytes_count = metric_registry.register_metric::<U64Counter>( | ||
WRITE_BYTES_METRIC_NAME, | ||
"track total number of bytes written to the database", | ||
); | ||
Self { | ||
write_lines_total, | ||
write_bytes_total, | ||
write_lines_count, | ||
write_lines_rejected_count, | ||
write_bytes_count, | ||
} | ||
} | ||
|
||
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); | ||
self.write_lines_count.recorder([("db", db)]).inc(lines); | ||
} | ||
|
||
pub(super) fn record_lines_rejected<D: Into<String>>(&self, db: D, lines: u64) { | ||
let db: Cow<'static, str> = Cow::from(db.into()); | ||
self.write_lines_rejected_count | ||
.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); | ||
self.write_bytes_count.recorder([("db", db)]).inc(bytes); | ||
} | ||
} | ||
|
||
|
@@ -53,15 +67,39 @@ mod tests { | |
assert_eq!( | ||
64, | ||
metrics | ||
.write_lines_total | ||
.write_lines_count | ||
.get_observer(&Attributes::from(&[("db", "foo")])) | ||
.unwrap() | ||
.fetch() | ||
); | ||
assert_eq!( | ||
256, | ||
metrics | ||
.write_lines_count | ||
.get_observer(&Attributes::from(&[("db", "bar")])) | ||
.unwrap() | ||
.fetch() | ||
); | ||
} | ||
|
||
#[test] | ||
fn record_lines_rejected() { | ||
let metric_registry = Registry::new(); | ||
let metrics = WriteMetrics::new(&metric_registry); | ||
metrics.record_lines_rejected("foo", 64); | ||
metrics.record_lines_rejected(String::from("bar"), 256); | ||
assert_eq!( | ||
64, | ||
metrics | ||
.write_lines_rejected_count | ||
.get_observer(&Attributes::from(&[("db", "foo")])) | ||
.unwrap() | ||
.fetch() | ||
); | ||
assert_eq!( | ||
256, | ||
metrics | ||
.write_lines_total | ||
.write_lines_rejected_count | ||
.get_observer(&Attributes::from(&[("db", "bar")])) | ||
.unwrap() | ||
.fetch() | ||
|
@@ -77,15 +115,15 @@ mod tests { | |
assert_eq!( | ||
64, | ||
metrics | ||
.write_bytes_total | ||
.write_bytes_count | ||
.get_observer(&Attributes::from(&[("db", "foo")])) | ||
.unwrap() | ||
.fetch() | ||
); | ||
assert_eq!( | ||
256, | ||
metrics | ||
.write_bytes_total | ||
.write_bytes_count | ||
.get_observer(&Attributes::from(&[("db", "bar")])) | ||
.unwrap() | ||
.fetch() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write_lines_total
is the more standard naming convention. Metric names should end in units, e.g. _seconds, _bytes, or _total for unit-less metrics. See https://prometheus.io/docs/practices/naming/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed this in cd51bc2