-
Notifications
You must be signed in to change notification settings - Fork 17
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
Used labels and service while calling metrics-rs macros #234
Conversation
…om the metric crate
…getting incremented by one
src/metrics/perf_event.rs
Outdated
@@ -80,12 +80,8 @@ impl HardwareMetricGroup { | |||
) -> std::io::Result<()> { | |||
let iterator = perf_events.counters.iter(); | |||
for value in iterator { | |||
register_histogram!(self.get_field_gauge_name(&node_name, &value.to_string())); | |||
register_histogram!(value.to_string(),"node" => String::from (node_name.clone())); | |||
} | |||
self.group.enable() |
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 didn't catch this one before. Why is the group enabled here?
But could we remove the whole function? And move the registration out of the struct and handle it in the Node.
// in Node::new()
for counter in hardware_metric_group.counters() {
register_histogram!(counter, "node" => self.descriptor.clone());
}
src/stream/node/source.rs
Outdated
return self.handle_source_error(error); | ||
increment_counter!("error_counter", "source" => self.descriptor.clone()); | ||
|
||
return self.handle_source_error(error, error_counter); |
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.
As discussed. no need to have counter variable within the handle_source_error
function.
Add something like this where we simply bump the counter if the error is acceptable, but otherwise return Err if it is seen as critical.
match self.handle_source_error(error) {
Ok(_) => {
counter += 1; // Acceptable Error, just increase counter
}
Err(err) {
return Err(err); // Critical error
}
}
Fixes #231 |
src/stream/node/mod.rs
Outdated
for value in iterator { | ||
register_histogram!(value.to_string(),"node" => descriptor.clone()); | ||
} | ||
hardware_metric_group.group.enable().ok(); |
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.
should we be enabling the group here in the constructor?
Well to check that there are no errors yes, but it will start counting. Its probably fine to have it there, but then we should probably move the group.reset()?; before rather than after executing handle_events(...).
#[cfg(feature = "hardware_counters", ... )]
self.hardware_metric_group.reset()?;
#[cfg(feature = "metrics")]
let start_time = Instant::now();
@@ -249,13 +218,52 @@ where | |||
return Ok(()); | |||
} | |||
|
|||
#[cfg(all(feature = "hardware_counters", target_os = "linux", not(test)))] |
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.
registration should happen in Node::new().
I think we can remove the HardwareMetricGroup now that we operate locally. Also, a lot of code can be removed.
We don't need to reset the group.
for iterators, no need to store the iterator in a variable.
for counter in self.perf_events.counters.iter() {
}
// instead of
let iterator = self.perf_events.counters.iter();
for counter in iterator {
}
The code below has not been verified to compile but should be possible to write it like that.
// Node constructor
#[cfg(all(feature = "hardware_counters", target_os = "linux", not(test)))]
for counter in self.perf_events.counters.iter() {
register_histogram!(counter.to_string(),"node" => self.descriptor.clone());
}
// handle message
#[cfg(all(feature = "hardware_counters", target_os = "linux", not(test)))]
let mut (group, counters) = {
let group = Group::new()?;
let counters = Vec::with_capacity(self.perf_events.counters.len());
for hardware_counter in self.perf_events.counters.iter() {
let counter = Builder::new()
.group(&mut group)
.kind(hardware_counter.get_hardware_kind())
.build()?;
counters.push((hardware_counter.to_string(), counter));
}
(group, counters)
};
#[cfg(all(feature = "hardware_counters", target_os = "linux", not(test)))]
group.enable()?;
// do work
#[cfg(all(feature = "hardware_counters", target_os = "linux", not(test)))]
group.disable()?;
#[cfg(all(feature = "hardware_counters", target_os = "linux", not(test)))]
let counts = group.read()?;
#[cfg(all(feature = "hardware_counters", target_os = "linux", not(test)))]
for (metric_name, counter) in counters.iter() {
histogram!(String::from(metric_name), counts[counter] as f64, "node" => self.descriptor.clone());
}
No description provided.