From 781575d45e6f65aa74257363e3912705fce57008 Mon Sep 17 00:00:00 2001 From: David Ashpole Date: Mon, 28 Aug 2023 19:24:56 -0400 Subject: [PATCH] [chore] [receiver/prometheus] fix flaky TestScopeInfoScopeAttributes unit test (#26240) **Description:** Fixes https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/26123 It sorts scopes before checking them. --- .../metrics_receiver_labels_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/receiver/prometheusreceiver/metrics_receiver_labels_test.go b/receiver/prometheusreceiver/metrics_receiver_labels_test.go index f4251962c0e9..c1e0631f0ff5 100644 --- a/receiver/prometheusreceiver/metrics_receiver_labels_test.go +++ b/receiver/prometheusreceiver/metrics_receiver_labels_test.go @@ -767,16 +767,19 @@ func verifyMultipleScopes(t *testing.T, td *testData, rms []pmetric.ResourceMetr require.Greater(t, len(rms), 0, "At least one resource metric should be present") sms := rms[0].ScopeMetrics() - require.Equal(t, sms.Len(), 3, "At two scope metrics should be present") + require.Equal(t, sms.Len(), 3, "Three scope metrics should be present") + sms.Sort(func(a, b pmetric.ScopeMetrics) bool { + return a.Scope().Name() < b.Scope().Name() + }) require.Equal(t, sms.At(0).Scope().Name(), "fake.scope.name") require.Equal(t, sms.At(0).Scope().Version(), "v0.1.0") require.Equal(t, sms.At(0).Scope().Attributes().Len(), 0) - require.Equal(t, sms.At(1).Scope().Name(), "scope.with.attributes") - require.Equal(t, sms.At(1).Scope().Version(), "v1.5.0") - require.Equal(t, sms.At(1).Scope().Attributes().Len(), 1) - scopeAttrVal, found := sms.At(1).Scope().Attributes().Get("animal") + require.Equal(t, sms.At(1).Scope().Name(), "otelcol/prometheusreceiver") + require.Equal(t, sms.At(1).Scope().Attributes().Len(), 0) + require.Equal(t, sms.At(2).Scope().Name(), "scope.with.attributes") + require.Equal(t, sms.At(2).Scope().Version(), "v1.5.0") + require.Equal(t, sms.At(2).Scope().Attributes().Len(), 1) + scopeAttrVal, found := sms.At(2).Scope().Attributes().Get("animal") require.True(t, found) require.Equal(t, scopeAttrVal.Str(), "bear") - require.Equal(t, sms.At(2).Scope().Name(), "otelcol/prometheusreceiver") - require.Equal(t, sms.At(2).Scope().Attributes().Len(), 0) }