-
Notifications
You must be signed in to change notification settings - Fork 111
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
Make metrics collection optional/faster #1147
base: main
Are you sure you want to change the base?
Changes from 1 commit
d84f414
43c2f23
2c17a74
f437e2f
481a526
4392cb8
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 |
---|---|---|
|
@@ -180,6 +180,9 @@ pub struct Metrics { | |
retries_num: AtomicU64, | ||
histogram: Arc<LockFreeHistogram>, | ||
meter: Arc<Meter>, | ||
total_connections: AtomicU64, | ||
connection_timeouts: AtomicU64, | ||
request_timeouts: AtomicU64, | ||
} | ||
|
||
impl Metrics { | ||
|
@@ -192,6 +195,9 @@ impl Metrics { | |
retries_num: AtomicU64::new(0), | ||
histogram: Arc::new(LockFreeHistogram::default()), | ||
meter: Arc::new(Meter::new()), | ||
total_connections: AtomicU64::new(0), | ||
connection_timeouts: AtomicU64::new(0), | ||
request_timeouts: AtomicU64::new(0), | ||
} | ||
} | ||
|
||
|
@@ -223,6 +229,26 @@ impl Metrics { | |
self.retries_num.fetch_add(1, ORDER_TYPE); | ||
} | ||
|
||
/// Increments counter for total number of connections | ||
pub(crate) fn inc_total_connections(&self) { | ||
self.total_connections.fetch_add(1, ORDER_TYPE); | ||
} | ||
|
||
/// Decrements counter for total number of connections | ||
pub(crate) fn dec_total_connections(&self) { | ||
self.total_connections.fetch_sub(1, ORDER_TYPE); | ||
} | ||
|
||
/// Increments counter for connection timeouts | ||
pub(crate) fn inc_connection_timeouts(&self) { | ||
self.connection_timeouts.fetch_add(1, ORDER_TYPE); | ||
} | ||
|
||
/// Increments counter for request timeouts | ||
pub(crate) fn inc_request_timeouts(&self) { | ||
self.request_timeouts.fetch_add(1, ORDER_TYPE); | ||
} | ||
Comment on lines
+247
to
+250
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. ❓ Is this counter intented to measure client-side request timeouts, server-side request timeouts, or both? 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. AFAIK this metric was used in cpp-driver to count client timeouts on requests to the database. I think it should be specified in the docstring of our inc method as well, so I will adjust it. |
||
|
||
/// Saves to histogram latency of completing single query. | ||
/// For paged queries it should log latency for every page. | ||
/// | ||
|
@@ -324,6 +350,21 @@ impl Metrics { | |
self.meter.fifteen_minute_rate() | ||
} | ||
|
||
/// Returns total number of active connections | ||
pub fn get_total_connections(&self) -> u64 { | ||
self.total_connections.load(ORDER_TYPE) | ||
} | ||
|
||
/// Returns counter for connection timeouts | ||
pub fn get_connection_timeouts(&self) -> u64 { | ||
self.connection_timeouts.load(ORDER_TYPE) | ||
} | ||
|
||
/// Returns counter for request timeouts | ||
pub fn get_request_timeouts(&self) -> u64 { | ||
self.request_timeouts.load(ORDER_TYPE) | ||
} | ||
|
||
// Metric implementations | ||
|
||
fn mean(h: Histogram) -> Result<u64, MetricsError> { | ||
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 wonder why they decided to remove 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. The histogram has no way of providing a true mean. Do we use the lower or upper end of the bucket range while calculating? Somewhere in the middle? It seems more appropriate to let the caller decide how they want to deal with this detail. Same when determining a percentile, the best we can do is return the |
||
|
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.
❓ These docstrings pretty much repeat what's said in the functions' names, but they don't tell me when I should call those.
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.
Those functions are not meant to be called by the user.
Nevertheless I surely will adjust the docstrings to better describe the logic behind those functions for devs to understand and use properly if needed in other places in the future.
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.
That's what I had in mind - internal usage.