-
Notifications
You must be signed in to change notification settings - Fork 31
Integrate derived metrics with metrics.rs #104
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
Conversation
The metrics-rs-integration feature allows users to automatically export metrics via the metrics.rs crate. Previously, only base metrics were included, derived metrics were excluded. This commit updates the integration to include derived metrics.
0447437 to
0dddf1b
Compare
arielb1
left a comment
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.
- Could you add a test to https://github.com/tokio-rs/tokio-metrics/blob/main/tests/auto_metrics.rs ?
- Is there a way of making
test_no_fields_missingwork for derived metrics? I suspect there is not since they are method and not fields, but if there is it would be excellent.
I'll get on that this week/weekend. I was holding off on writing tests until I got buy in that it was a good idea, but it sounds like we are interested in merging this (once tests are added)? |
Yea, we will be interested in merging this. Great PR! |
I have two thoughts here. The first is that we can maintain a const array in the impl RuntimeMetrics {
const DERIVED_METRICS: &[&str] = &["busy_ratio"];
const DERIVED_UNSTABLE_METRICS: &[&str] = &["mean_polls_per_park"];
...
}Then we could check against those arrays in a test to make sure we aren't missing a derived metric. I don't personally like this approach because we still have to remember to manually update the arrays whenever adding a new method. The only real benefit is that these arrays are physically closer to the methods so it will be harder to forget. The second idea builds off of the first. We could write an attribute proc macro that walks the AST of a struct and builds a list of all method names, and use those lists similarly as the first idea. It's a bit heavyweight but we'd only have to define it once and then it wouldn't require further maintenance. Unless we wanted to add methods to Any thoughts? |
Since we already have a macro that defines the direct metrics ( Line 1570 in a610c22
I would not use a proc macro, this is too small for one. |
I just pushed a commit with this approach.
I added tests for both derived runtime and task metrics. I couldn't really figure out a way for the value to be deterministic, so I just tested that the values existed and were not 0. |
Ignoring whitespace while reviewing makes the diff much more pleasant. |
| pub fn mean_slow_poll_duration(&self) -> Duration { | ||
| mean(self.total_slow_poll_duration, self.total_slow_poll_count) | ||
| } | ||
| /// The mean duration that tasks spent waiting to be executed after awakening. |
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.
Your indentation is inconsistent between this and the previous block
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.
Do you want me to fix that in a follow up?
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.
Ah, never mind, I see that you just did that.
The metrics-rs-integration feature allows users to automatically export metrics via the metrics.rs crate. Previously, only base metrics were included, derived metrics were excluded. This commit updates the integration to include derived metrics.
I'm not 100% convinced that this is a good idea, users could just reconstruct the derived metrics on their own wherever those metrics end up getting exported to. However, the implementation was easy enough I thought I'd use the PR as a platform to discuss the idea.