Skip to content

Commit 83320cc

Browse files
committed
src/encoding/text: Do not separate labels with spaces
1 parent 67a94c3 commit 83320cc

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.11.2] - 2021-06-09
8+
### Fixed
9+
- Do not separate labels with spaces.
10+
711
## [0.11.1] - 2021-06-08
812
### Fixed
913
- Encode Info metric labels.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "open-metrics-client"
3-
version = "0.11.1"
3+
version = "0.11.2"
44
authors = ["Max Inden <mail@max-inden.de>"]
55
edition = "2018"
66
description = "Open Metrics client library allowing users to natively instrument applications."

src/encoding/text.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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> {
282282
impl<'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

Comments
 (0)