From 476bf8337b8c114caac4e63ccc34113721009873 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Tue, 15 Oct 2024 00:00:00 +0000 Subject: [PATCH] feat(encoding)!: `Collector` does not consume `DescriptorEncoder` see #135. this adjusts the parameter of `encode()` so that it only mutably borrows the encoder. Signed-off-by: katelyn martin --- src/collector.rs | 2 +- src/encoding/text.rs | 2 +- src/registry.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/collector.rs b/src/collector.rs index 66270c4..f5c95a0 100644 --- a/src/collector.rs +++ b/src/collector.rs @@ -37,5 +37,5 @@ use crate::encoding::DescriptorEncoder; /// ``` pub trait Collector: std::fmt::Debug + Send + Sync + 'static { /// Once the [`Collector`] is registered, this method is called on each scrape. - fn encode(&self, encoder: DescriptorEncoder) -> Result<(), std::fmt::Error>; + fn encode(&self, encoder: &mut DescriptorEncoder) -> Result<(), std::fmt::Error>; } diff --git a/src/encoding/text.rs b/src/encoding/text.rs index ca44aa9..aaac9cc 100644 --- a/src/encoding/text.rs +++ b/src/encoding/text.rs @@ -1077,7 +1077,7 @@ mod tests { impl crate::collector::Collector for Collector { fn encode( &self, - mut encoder: crate::encoding::DescriptorEncoder, + encoder: &mut crate::encoding::DescriptorEncoder, ) -> Result<(), std::fmt::Error> { let counter = crate::metrics::counter::ConstCounter::new(42u64); let mut metric_encoder = encoder.encode_descriptor( diff --git a/src/registry.rs b/src/registry.rs index 77653e2..2b1a83b 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -300,9 +300,9 @@ impl Registry { } for collector in self.collectors.iter() { - let descriptor_encoder = + let mut descriptor_encoder = encoder.with_prefix_and_labels(self.prefix.as_ref(), &self.labels); - collector.encode(descriptor_encoder)?; + collector.encode(&mut descriptor_encoder)?; } for registry in self.sub_registries.iter() {