Skip to content

Commit

Permalink
[chore] Fix checkValueForProducer test helper for queue metrics (#8288)
Browse files Browse the repository at this point in the history
`checkValueForProducer` test helper assumes that every OC metric has
only one timeseries. But, since the queue metrics are defined globally,
they accumulate more timeseries with different labels from different
tests. This change removes that assumption. It allows having more tests
for the exporter queue without breaking
TestQueuedRetry_QueueMetricsReported.

Ideally, we should avoid defining instruments globally or clear them up
after each test. The first option would require passing the OpenCensus
registry in as a public field of TelemetrySettings from the service
start. The second option would require a bigger refactoring.

I think we can allow several tests emitting datapoints for the global
instruments for now until we migrate to OTel metrics.

Fixes tests failing in
#8250
  • Loading branch information
dmitryax authored Aug 28, 2023
1 parent 92f5fe6 commit 0a63747
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions exporter/exporterhelper/queued_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,11 @@ func checkValueForGlobalManager(t *testing.T, wantTags []tag.Tag, value int64, v
func checkValueForProducer(t *testing.T, producer metricproducer.Producer, wantTags []tag.Tag, value int64, vName string) bool {
for _, metric := range producer.Read() {
if metric.Descriptor.Name == vName && len(metric.TimeSeries) > 0 {
lastValue := metric.TimeSeries[len(metric.TimeSeries)-1]
if tagsMatchLabelKeys(wantTags, metric.Descriptor.LabelKeys, lastValue.LabelValues) {
require.Equal(t, value, lastValue.Points[len(lastValue.Points)-1].Value.(int64))
return true
for _, ts := range metric.TimeSeries {
if tagsMatchLabelKeys(wantTags, metric.Descriptor.LabelKeys, ts.LabelValues) {
require.Equal(t, value, ts.Points[len(ts.Points)-1].Value.(int64))
return true
}
}
}
}
Expand Down

0 comments on commit 0a63747

Please sign in to comment.