client_rust
client_rust copied to clipboard
Custom Collector with `sub_registry_with_prefix` outputs name multiple times
If you create a custom Collector and attach it to a sub registry it appends the name improperly.
#[derive(Debug)]
struct MyCollector {}
impl prometheus_client::collector::Collector for MyCollector {
fn collect<'a>(&'a self) -> Box<dyn Iterator<Item = (std::borrow::Cow<'a, prometheus_client::registry::Descriptor>, prometheus_client::MaybeOwned<'a, Box<dyn prometheus_client::registry::LocalMetric>>)> + 'a> {
let c: Box<dyn prometheus_client::registry::LocalMetric> = Box::new(prometheus_client::metrics::counter::ConstCounter::new(42));
let descriptor = prometheus_client::registry::Descriptor::new(
"my_counter",
"This is my counter",
None,
None,
vec![],
);
Box::new(std::iter::once((std::borrow::Cow::Owned(descriptor), prometheus_client::MaybeOwned::Owned(c))))
}
}
let my_collector = Box::new(MyCollector{});
{
let mut root_registry = <Registry>::with_prefix("root");
let r = root_registry.sub_registry_with_prefix("000");
let r = r.sub_registry_with_prefix("111");
let r = r.sub_registry_with_prefix("222");
r.register_collector(my_collector);
}
Results:
# HELP root_root_000_root_000_111_root_000_111_222_my_counter This is my counter.....
# TYPE root_root_000_root_000_111_root_000_111_222_my_counter counter
root_root_000_root_000_111_root_000_111_222_my_counter_total 42
# EOF
Expected:
# HELP root_000_111_222_my_counter This is my counter.....
# TYPE root_000_111_222_my_counter counter
root_000_111_222_my_counter_total 42
# EOF
Same issue
I noticed the same. It seems state is only kept when the previous screen is part of the location stack.
E.g. going from LocationA -> LocationB
class LocationB extends BeamLocation<BeamState> {
@override
List<BeamPage> buildPages(BuildContext context, BeamState state) {
return [
// create whatever (back)stack you desire here.
// this will also keep the current state of this location in memory
...LocationA().buildPages(context, state),
const WidgetB(),
];
}
@override
List<Pattern> get pathPatterns => ["/b"];
}
Disclaimer: I just started using beamer 2 days ago. There could be another way I don't know yet ^^;
There was also this comment that could be useful