@@ -244,7 +244,7 @@ impl<'a, 'b> Encoder<'a, 'b> {
244244
245245 // TODO: Consider caching the encoded labels for Histograms as they stay the
246246 // same but are currently encoded multiple times.
247- pub ( self ) fn encode_labels ( & mut self ) -> Result < BucketEncoder , std:: io:: Error > {
247+ fn encode_labels ( & mut self ) -> Result < BucketEncoder , std:: io:: Error > {
248248 if let Some ( labels) = & self . labels {
249249 self . writer . write_all ( b"{" ) ?;
250250 labels. encode ( self . writer ) ?;
@@ -282,7 +282,7 @@ pub struct BucketEncoder<'a> {
282282impl < ' a > BucketEncoder < ' a > {
283283 fn encode_bucket ( & mut self , upper_bound : f64 ) -> Result < ValueEncoder , std:: io:: Error > {
284284 if self . opened_curly_brackets {
285- self . writer . write_all ( b", " ) ?;
285+ self . writer . write_all ( b"," ) ?;
286286 } else {
287287 self . writer . write_all ( b"{" ) ?;
288288 }
@@ -654,7 +654,10 @@ mod tests {
654654 registry. register ( "my_counter_family" , "My counter family" , family. clone ( ) ) ;
655655
656656 family
657- . get_or_create ( & vec ! [ ( "method" . to_string( ) , "GET" . to_string( ) ) ] )
657+ . get_or_create ( & vec ! [
658+ ( "method" . to_string( ) , "GET" . to_string( ) ) ,
659+ ( "status" . to_string( ) , "200" . to_string( ) ) ,
660+ ] )
658661 . inc ( ) ;
659662
660663 let mut encoded = Vec :: new ( ) ;
@@ -696,6 +699,26 @@ mod tests {
696699 parse_with_python_client ( String :: from_utf8 ( encoded) . unwrap ( ) ) ;
697700 }
698701
702+ #[ test]
703+ fn encode_histogram_family ( ) {
704+ let mut registry = Registry :: default ( ) ;
705+ let family =
706+ Family :: new_with_constructor ( || Histogram :: new ( exponential_buckets ( 1.0 , 2.0 , 10 ) ) ) ;
707+ registry. register ( "my_histogram" , "My histogram" , family. clone ( ) ) ;
708+ family
709+ . get_or_create ( & vec ! [
710+ ( "method" . to_string( ) , "GET" . to_string( ) ) ,
711+ ( "status" . to_string( ) , "200" . to_string( ) ) ,
712+ ] )
713+ . observe ( 1.0 ) ;
714+
715+ let mut encoded = Vec :: new ( ) ;
716+
717+ encode ( & mut encoded, & registry) . unwrap ( ) ;
718+
719+ parse_with_python_client ( String :: from_utf8 ( encoded) . unwrap ( ) ) ;
720+ }
721+
699722 #[ test]
700723 fn encode_histogram_with_exemplars ( ) {
701724 let mut registry = Registry :: default ( ) ;
0 commit comments