Skip to content

Commit

Permalink
Replace SendEncodeMetric with SendSyncEncodeMetric
Browse files Browse the repository at this point in the history
This will allow the default `Registry` to be used in multi-threaded
environments (e.g. web servers) where the registry needs to be shared
between threads.

Closes prometheus#57.
  • Loading branch information
sd2k committed Mar 29, 2022
1 parent a458c03 commit 8043642
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/encoding/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,11 @@ impl EncodeMetric for Box<dyn EncodeMetric> {
}
}

pub trait SendEncodeMetric: EncodeMetric + Send {}
pub trait SendSyncEncodeMetric: EncodeMetric + Send + Sync {}

impl<T: EncodeMetric + Send> SendEncodeMetric for T {}
impl<T: EncodeMetric + Send + Sync> SendSyncEncodeMetric for T {}

impl EncodeMetric for Box<dyn SendEncodeMetric> {
impl EncodeMetric for Box<dyn SendSyncEncodeMetric> {
fn encode(&self, encoder: Encoder) -> Result<(), std::io::Error> {
self.deref().encode(encoder)
}
Expand Down
2 changes: 1 addition & 1 deletion src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ use std::ops::Add;
/// # "# EOF\n";
/// # assert_eq!(expected, String::from_utf8(buffer).unwrap());
/// ```
pub struct Registry<M = Box<dyn crate::encoding::text::SendEncodeMetric>> {
pub struct Registry<M = Box<dyn crate::encoding::text::SendSyncEncodeMetric>> {
prefix: Option<Prefix>,
labels: Vec<(Cow<'static, str>, Cow<'static, str>)>,
metrics: Vec<(Descriptor, M)>,
Expand Down

0 comments on commit 8043642

Please sign in to comment.