Watch
0
0
Fork
You've already forked hyperhive
0

metrics tests: compare labels sorted, the SDK keeps attributes in no fixed order

This commit is contained in:
damocles 2026-11-05 00:53:43 +01:00 • committed by mara
commit 4b71bcd8ff
2 changed files with 12 additions and 6 deletions

View file

@ -133,10 +133,13 @@ mod tests {
for resource in exporter.get_finished_metrics().unwrap() {
for scope in resource.scope_metrics() {
for metric in scope.metrics().filter(|m| m.name() == name) {
// The SDK keeps attributes in no fixed order, so sort them.
let labels = |attrs: &mut dyn Iterator<Item = &KeyValue>| {
attrs
let mut all = attrs
.map(|kv| (kv.key.to_string(), kv.value.to_string()))
.collect::<Vec<_>>()
.collect::<Vec<_>>();
all.sort();
all
};
match metric.data() {
AggregatedMetrics::U64(MetricData::Sum(sum)) => {
@ -180,8 +183,8 @@ mod tests {
assert_eq!(
got,
vec![
(vec![pair("step", "code"), pair("outcome", "failed")], 1),
(vec![pair("step", "code"), pair("outcome", "stored")], 2),
(vec![pair("outcome", "failed"), pair("step", "code")], 1),
(vec![pair("outcome", "stored"), pair("step", "code")], 2),
]
);
}

View file

@ -190,10 +190,13 @@ mod tests {
for resource in exporter.get_finished_metrics().unwrap() {
for scope in resource.scope_metrics() {
for metric in scope.metrics().filter(|m| m.name() == name) {
// The SDK keeps attributes in no fixed order, so sort them.
let labels = |attrs: &mut dyn Iterator<Item = &KeyValue>| {
attrs
let mut all = attrs
.map(|kv| (kv.key.to_string(), kv.value.to_string()))
.collect::<Vec<_>>()
.collect::<Vec<_>>();
all.sort();
all
};
match metric.data() {
AggregatedMetrics::U64(MetricData::Sum(sum)) => {