metrics tests: compare labels sorted, the SDK keeps attributes in no fixed order
This commit is contained in:
parent
3adfcb3843
commit
4b71bcd8ff
2 changed files with 12 additions and 6 deletions
|
|
@ -133,10 +133,13 @@ mod tests {
|
||||||
for resource in exporter.get_finished_metrics().unwrap() {
|
for resource in exporter.get_finished_metrics().unwrap() {
|
||||||
for scope in resource.scope_metrics() {
|
for scope in resource.scope_metrics() {
|
||||||
for metric in scope.metrics().filter(|m| m.name() == name) {
|
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>| {
|
let labels = |attrs: &mut dyn Iterator<Item = &KeyValue>| {
|
||||||
attrs
|
let mut all = attrs
|
||||||
.map(|kv| (kv.key.to_string(), kv.value.to_string()))
|
.map(|kv| (kv.key.to_string(), kv.value.to_string()))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>();
|
||||||
|
all.sort();
|
||||||
|
all
|
||||||
};
|
};
|
||||||
match metric.data() {
|
match metric.data() {
|
||||||
AggregatedMetrics::U64(MetricData::Sum(sum)) => {
|
AggregatedMetrics::U64(MetricData::Sum(sum)) => {
|
||||||
|
|
@ -180,8 +183,8 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
got,
|
got,
|
||||||
vec![
|
vec![
|
||||||
(vec![pair("step", "code"), pair("outcome", "failed")], 1),
|
(vec![pair("outcome", "failed"), pair("step", "code")], 1),
|
||||||
(vec![pair("step", "code"), pair("outcome", "stored")], 2),
|
(vec![pair("outcome", "stored"), pair("step", "code")], 2),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -190,10 +190,13 @@ mod tests {
|
||||||
for resource in exporter.get_finished_metrics().unwrap() {
|
for resource in exporter.get_finished_metrics().unwrap() {
|
||||||
for scope in resource.scope_metrics() {
|
for scope in resource.scope_metrics() {
|
||||||
for metric in scope.metrics().filter(|m| m.name() == name) {
|
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>| {
|
let labels = |attrs: &mut dyn Iterator<Item = &KeyValue>| {
|
||||||
attrs
|
let mut all = attrs
|
||||||
.map(|kv| (kv.key.to_string(), kv.value.to_string()))
|
.map(|kv| (kv.key.to_string(), kv.value.to_string()))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>();
|
||||||
|
all.sort();
|
||||||
|
all
|
||||||
};
|
};
|
||||||
match metric.data() {
|
match metric.data() {
|
||||||
AggregatedMetrics::U64(MetricData::Sum(sum)) => {
|
AggregatedMetrics::U64(MetricData::Sum(sum)) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue