Skip to content

Commit

Permalink
Removed redundant code. Return no error.
Browse files Browse the repository at this point in the history
  • Loading branch information
prasad-shirodkar committed Apr 10, 2024
1 parent 648b40e commit 509c602
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
11 changes: 2 additions & 9 deletions exporters/stdout/stdoutmetric/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ func (e *exporter) Aggregation(k metric.InstrumentKind) metric.Aggregation {
}

func (e *exporter) Export(ctx context.Context, data *metricdata.ResourceMetrics) error {
select {
case <-ctx.Done():
// Don't do anything if the context has already timed out.
return ctx.Err()
default:
// Context is still valid, continue.
}
if e.redactTimestamps {
redactTimestamps(data)
}
Expand All @@ -69,7 +62,7 @@ func (e *exporter) Export(ctx context.Context, data *metricdata.ResourceMetrics)

func (e *exporter) ForceFlush(ctx context.Context) error {
// exporter holds no state, nothing to flush.
return ctx.Err()
return nil
}

func (e *exporter) Shutdown(ctx context.Context) error {
Expand All @@ -78,7 +71,7 @@ func (e *exporter) Shutdown(ctx context.Context) error {
encoder: shutdownEncoder{},
})
})
return ctx.Err()
return nil
}

func (e *exporter) MarshalLog() interface{} {
Expand Down
4 changes: 2 additions & 2 deletions exporters/stdout/stdoutmetric/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func testCtxErrHonored(factory func(*testing.T) func(context.Context) error) fun
<-innerCtx.Done()

f := factory(t)
assert.ErrorIs(t, f(innerCtx), context.DeadlineExceeded)
assert.NoError(t, f(innerCtx))
})

t.Run("Canceled", func(t *testing.T) {
innerCtx, innerCancel := context.WithCancel(ctx)
innerCancel()

f := factory(t)
assert.ErrorIs(t, f(innerCtx), context.Canceled)
assert.NoError(t, f(innerCtx))
})

t.Run("NoError", func(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions exporters/stdout/stdouttrace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
e.stopped = true
e.stoppedMu.Unlock()

select {
case <-ctx.Done():
return ctx.Err()
default:
}
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions exporters/stdout/stdouttrace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestExporterShutdownHonorsTimeout(t *testing.T) {
defer innerCancel()
<-innerCtx.Done()
err = e.Shutdown(innerCtx)
assert.ErrorIs(t, err, context.DeadlineExceeded)
assert.NoError(t, err)
}

func TestExporterShutdownHonorsCancel(t *testing.T) {
Expand All @@ -209,7 +209,7 @@ func TestExporterShutdownHonorsCancel(t *testing.T) {
innerCtx, innerCancel := context.WithCancel(ctx)
innerCancel()
err = e.Shutdown(innerCtx)
assert.ErrorIs(t, err, context.Canceled)
assert.NoError(t, err)
}

func TestExporterShutdownNoError(t *testing.T) {
Expand Down

0 comments on commit 509c602

Please sign in to comment.