Skip to content

Commit 2109c5d

Browse files
committed
Add test & changelog
Signed-off-by: Jean-Baptiste Skutnik <jskutnik@ddn.com>
1 parent 40393b1 commit 2109c5d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ 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.24.1]
8+
9+
### Fixed
10+
11+
- Filter out empty metric families, to match the go client.
12+
See [PR 279].
13+
14+
[PR 279]: https://github.com/prometheus/client_rust/pull/279
15+
716
## [0.24.0]
817

918
### Added

src/encoding/text.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,4 +1278,41 @@ def parse(input):
12781278
.unwrap();
12791279
})
12801280
}
1281+
1282+
#[test]
1283+
fn encode_omit_empty() {
1284+
let mut registry = Registry::default();
1285+
let counter1: Family<Vec<(&'static str, &'static str)>, Counter> = Default::default();
1286+
let counter2: Family<Vec<(&'static str, &'static str)>, Counter> = Default::default();
1287+
let counter3: Family<Vec<(&'static str, &'static str)>, Counter> = Default::default();
1288+
1289+
registry.register("counter1", "First counter", counter1.clone());
1290+
registry.register("counter2", "Second counter", counter2.clone());
1291+
registry.register("counter3", "Third counter", counter3.clone());
1292+
1293+
counter1.get_or_create(&vec![("label", "value")]).inc();
1294+
1295+
let mut encoded = String::new();
1296+
encode(&mut encoded, &registry).unwrap();
1297+
1298+
let expected = "# HELP counter1 First counter.\n".to_owned()
1299+
+ "# TYPE counter1 counter\n"
1300+
+ "counter1_total{label=\"value\"} 1\n"
1301+
+ "# EOF\n";
1302+
assert_eq!(expected, encoded);
1303+
1304+
counter2.get_or_create(&vec![("label", "value")]).inc();
1305+
1306+
let mut encoded = String::new();
1307+
encode(&mut encoded, &registry).unwrap();
1308+
1309+
let expected = "# HELP counter1 First counter.\n".to_owned()
1310+
+ "# TYPE counter1 counter\n"
1311+
+ "counter1_total{label=\"value\"} 1\n"
1312+
+ "# HELP counter2 Second counter.\n"
1313+
+ "# TYPE counter2 counter\n"
1314+
+ "counter2_total{label=\"value\"} 1\n"
1315+
+ "# EOF\n";
1316+
assert_eq!(expected, encoded);
1317+
}
12811318
}

0 commit comments

Comments
 (0)