Skip to content

Commit 8ed987a

Browse files
[chore] fix panic issued in test when the gauge data is not present (#42357)
See the failing CI run https://github.com/open-telemetry/opentelemetry-collector-contrib/actions/runs/17329322611/job/49201552364?pr=42354 --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent f7b705d commit 8ed987a

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

processor/groupbytraceprocessor/event_test.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,15 +468,17 @@ func TestPeriodicMetrics(t *testing.T) {
468468
go em.periodicMetrics()
469469

470470
// ensure our gauge is showing 1 item in the queue
471-
assert.Eventually(t, func() bool {
472-
return getGaugeValue(t, "otelcol_processor_groupbytrace_num_events_in_queue", s) == 1
471+
assert.EventuallyWithT(t, func(tt *assert.CollectT) {
472+
val := getGaugeValue(t.Context(), tt, "otelcol_processor_groupbytrace_num_events_in_queue", s)
473+
assert.Equal(tt, int64(1), val)
473474
}, 1*time.Second, 10*time.Millisecond)
474475

475476
wg.Done() // release all events
476477

477478
// ensure our gauge is now showing no items in the queue
478-
assert.Eventually(t, func() bool {
479-
return getGaugeValue(t, "otelcol_processor_groupbytrace_num_events_in_queue", s) == 0
479+
assert.EventuallyWithT(t, func(tt *assert.CollectT) {
480+
val := getGaugeValue(t.Context(), tt, "otelcol_processor_groupbytrace_num_events_in_queue", s)
481+
assert.Equal(tt, int64(0), val)
480482
}, 1*time.Second, 10*time.Millisecond)
481483

482484
// signal and wait for the recursive call to finish
@@ -534,12 +536,17 @@ func TestDoWithTimeout_TimeoutTrigger(t *testing.T) {
534536
assert.WithinDuration(t, start, time.Now(), 100*time.Millisecond)
535537
}
536538

537-
func getGaugeValue(t *testing.T, name string, tt testTelemetry) int64 {
539+
func getGaugeValue(ctx context.Context, t *assert.CollectT, name string, tt testTelemetry) int64 {
538540
var md metricdata.ResourceMetrics
539-
require.NoError(t, tt.reader.Collect(t.Context(), &md))
541+
require.NoError(t, tt.reader.Collect(ctx, &md))
540542
m := tt.getMetric(name, md).Data
541-
g := m.(metricdata.Gauge[int64])
542-
assert.Len(t, g.DataPoints, 1, "expected exactly one data point")
543+
var g metricdata.Gauge[int64]
544+
var ok bool
545+
if g, ok = m.(metricdata.Gauge[int64]); !ok {
546+
assert.Fail(t, "missing gauge data")
547+
} else {
548+
assert.Len(t, g.DataPoints, 1, "expected exactly one data point")
549+
}
543550
return g.DataPoints[0].Value
544551
}
545552

0 commit comments

Comments
 (0)