Skip to content

Commit

Permalink
[chore] [receiver/prometheus] fix flaky TestScopeInfoScopeAttributes …
Browse files Browse the repository at this point in the history
…unit test (#26240)

**Description:**

Fixes
#26123

It sorts scopes before checking them.
  • Loading branch information
dashpole authored Aug 28, 2023
1 parent 110cd54 commit 781575d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions receiver/prometheusreceiver/metrics_receiver_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 781575d

Please sign in to comment.