Skip to content

Commit

Permalink
[chore] Fix some nolint in tests or non critical code (#11943)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Dec 17, 2024
1 parent bb27be0 commit 4cf491b
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 63 deletions.
16 changes: 12 additions & 4 deletions client/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import (

func Example_receiver() {
// Your receiver get a next consumer when it's constructed
var next consumer.Traces
next, err := consumer.NewTraces(func(ctx context.Context, td ptrace.Traces) error {
return nil
})
if err != nil {
panic(err)
}

// You'll convert the incoming data into pipeline data
td := ptrace.NewTraces()
Expand All @@ -30,13 +35,16 @@ func Example_receiver() {

// Extract the client information based on your original context and set it
// to Addr
cl.Addr = &net.IPAddr{ // nolint
// nolint
cl.Addr = &net.IPAddr{
IP: net.IPv4(1, 2, 3, 4),
}

// When you are done, propagate the context down the pipeline to the next
// consumer
next.ConsumeTraces(ctx, td) // nolint
// consumer and handle error.
if err = next.ConsumeTraces(ctx, td); err != nil {
panic(err)
}
}

func Example_processor() {
Expand Down
19 changes: 8 additions & 11 deletions exporter/exporterhelper/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func TestLogs_WithSpan(t *testing.T) {
le, err := NewLogs(context.Background(), set, &fakeLogsConfig, newPushLogsData(nil))
require.NoError(t, err)
require.NotNil(t, le)
checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, nil, 1)
checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, nil)
}

func TestLogsRequest_WithSpan(t *testing.T) {
Expand All @@ -297,7 +297,7 @@ func TestLogsRequest_WithSpan(t *testing.T) {
le, err := NewLogsRequest(context.Background(), set, internal.RequestFromLogsFunc(nil))
require.NoError(t, err)
require.NotNil(t, le)
checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, nil, 1)
checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, nil)
}

func TestLogs_WithSpan_ReturnError(t *testing.T) {
Expand All @@ -311,7 +311,7 @@ func TestLogs_WithSpan_ReturnError(t *testing.T) {
le, err := NewLogs(context.Background(), set, &fakeLogsConfig, newPushLogsData(want))
require.NoError(t, err)
require.NotNil(t, le)
checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, want, 1)
checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, want)
}

func TestLogsRequest_WithSpan_ReturnError(t *testing.T) {
Expand All @@ -325,7 +325,7 @@ func TestLogsRequest_WithSpan_ReturnError(t *testing.T) {
le, err := NewLogsRequest(context.Background(), set, internal.RequestFromLogsFunc(want))
require.NoError(t, err)
require.NotNil(t, le)
checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, want, 1)
checkWrapSpanForLogs(t, sr, set.TracerProvider.Tracer("test"), le, want)
}

func TestLogs_WithShutdown(t *testing.T) {
Expand Down Expand Up @@ -413,10 +413,7 @@ func generateLogsTraffic(t *testing.T, tracer trace.Tracer, le exporter.Logs, nu
}
}

// nolint: unparam
func checkWrapSpanForLogs(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le exporter.Logs,
wantError error, numLogRecords int64,
) {
func checkWrapSpanForLogs(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le exporter.Logs, wantError error) {
const numRequests = 5
generateLogsTraffic(t, tracer, le, numRequests, wantError)

Expand All @@ -430,11 +427,11 @@ func checkWrapSpanForLogs(t *testing.T, sr *tracetest.SpanRecorder, tracer trace
require.Equalf(t, parentSpan.SpanContext(), sd.Parent(), "Exporter span not a child\nSpanData %v", sd)
internal.CheckStatus(t, sd, wantError)

sentLogRecords := numLogRecords
var failedToSendLogRecords int64
sentLogRecords := int64(1)
failedToSendLogRecords := int64(0)
if wantError != nil {
sentLogRecords = 0
failedToSendLogRecords = numLogRecords
failedToSendLogRecords = 1
}
require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.SentLogRecordsKey, Value: attribute.Int64Value(sentLogRecords)}, "SpanData %v", sd)
require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.FailedToSendLogRecordsKey, Value: attribute.Int64Value(failedToSendLogRecords)}, "SpanData %v", sd)
Expand Down
19 changes: 8 additions & 11 deletions exporter/exporterhelper/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func TestMetrics_WithSpan(t *testing.T) {
me, err := NewMetrics(context.Background(), set, &fakeMetricsConfig, newPushMetricsData(nil))
require.NoError(t, err)
require.NotNil(t, me)
checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, nil, 2)
checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, nil)
}

func TestMetricsRequest_WithSpan(t *testing.T) {
Expand All @@ -299,7 +299,7 @@ func TestMetricsRequest_WithSpan(t *testing.T) {
me, err := NewMetricsRequest(context.Background(), set, internal.RequestFromMetricsFunc(nil))
require.NoError(t, err)
require.NotNil(t, me)
checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, nil, 2)
checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, nil)
}

func TestMetrics_WithSpan_ReturnError(t *testing.T) {
Expand All @@ -313,7 +313,7 @@ func TestMetrics_WithSpan_ReturnError(t *testing.T) {
me, err := NewMetrics(context.Background(), set, &fakeMetricsConfig, newPushMetricsData(want))
require.NoError(t, err)
require.NotNil(t, me)
checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, want, 2)
checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, want)
}

func TestMetricsRequest_WithSpan_ExportError(t *testing.T) {
Expand All @@ -327,7 +327,7 @@ func TestMetricsRequest_WithSpan_ExportError(t *testing.T) {
me, err := NewMetricsRequest(context.Background(), set, internal.RequestFromMetricsFunc(want))
require.NoError(t, err)
require.NotNil(t, me)
checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, want, 2)
checkWrapSpanForMetrics(t, sr, set.TracerProvider.Tracer("test"), me, want)
}

func TestMetrics_WithShutdown(t *testing.T) {
Expand Down Expand Up @@ -420,10 +420,7 @@ func generateMetricsTraffic(t *testing.T, tracer trace.Tracer, me exporter.Metri
}
}

// nolint: unparam
func checkWrapSpanForMetrics(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer,
me exporter.Metrics, wantError error, numMetricPoints int64,
) {
func checkWrapSpanForMetrics(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, me exporter.Metrics, wantError error) {
const numRequests = 5
generateMetricsTraffic(t, tracer, me, numRequests, wantError)

Expand All @@ -437,11 +434,11 @@ func checkWrapSpanForMetrics(t *testing.T, sr *tracetest.SpanRecorder, tracer tr
require.Equalf(t, parentSpan.SpanContext(), sd.Parent(), "Exporter span not a child\nSpanData %v", sd)
internal.CheckStatus(t, sd, wantError)

sentMetricPoints := numMetricPoints
var failedToSendMetricPoints int64
sentMetricPoints := int64(2)
failedToSendMetricPoints := int64(0)
if wantError != nil {
sentMetricPoints = 0
failedToSendMetricPoints = numMetricPoints
failedToSendMetricPoints = 2
}
require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.SentMetricPointsKey, Value: attribute.Int64Value(sentMetricPoints)}, "SpanData %v", sd)
require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.FailedToSendMetricPointsKey, Value: attribute.Int64Value(failedToSendMetricPoints)}, "SpanData %v", sd)
Expand Down
19 changes: 8 additions & 11 deletions exporter/exporterhelper/traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func TestTraces_WithSpan(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, te)

checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, nil, 1)
checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, nil)
}

func TestTracesRequest_WithSpan(t *testing.T) {
Expand All @@ -298,7 +298,7 @@ func TestTracesRequest_WithSpan(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, te)

checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, nil, 1)
checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, nil)
}

func TestTraces_WithSpan_ReturnError(t *testing.T) {
Expand All @@ -313,7 +313,7 @@ func TestTraces_WithSpan_ReturnError(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, te)

checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, want, 1)
checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, want)
}

func TestTracesRequest_WithSpan_ExportError(t *testing.T) {
Expand All @@ -328,7 +328,7 @@ func TestTracesRequest_WithSpan_ExportError(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, te)

checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, want, 1)
checkWrapSpanForTraces(t, sr, set.TracerProvider.Tracer("test"), te, want)
}

func TestTraces_WithShutdown(t *testing.T) {
Expand Down Expand Up @@ -421,10 +421,7 @@ func generateTraceTraffic(t *testing.T, tracer trace.Tracer, te exporter.Traces,
}
}

// nolint: unparam
func checkWrapSpanForTraces(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer,
te exporter.Traces, wantError error, numSpans int64,
) {
func checkWrapSpanForTraces(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, te exporter.Traces, wantError error) {
const numRequests = 5
generateTraceTraffic(t, tracer, te, numRequests, wantError)

Expand All @@ -439,11 +436,11 @@ func checkWrapSpanForTraces(t *testing.T, sr *tracetest.SpanRecorder, tracer tra
require.Equalf(t, parentSpan.SpanContext(), sd.Parent(), "Exporter span not a child\nSpanData %v", sd)
internal.CheckStatus(t, sd, wantError)

sentSpans := numSpans
var failedToSendSpans int64
sentSpans := int64(1)
failedToSendSpans := int64(0)
if wantError != nil {
sentSpans = 0
failedToSendSpans = numSpans
failedToSendSpans = 1
}
require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.SentSpansKey, Value: attribute.Int64Value(sentSpans)}, "SpanData %v", sd)
require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.FailedToSendSpansKey, Value: attribute.Int64Value(failedToSendSpans)}, "SpanData %v", sd)
Expand Down
19 changes: 8 additions & 11 deletions exporter/exporterhelper/xexporterhelper/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func TestProfilesExporter_WithSpan(t *testing.T) {
le, err := NewProfilesExporter(context.Background(), set, &fakeProfilesExporterConfig, newPushProfilesData(nil))
require.NoError(t, err)
require.NotNil(t, le)
checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, nil, 1)
checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, nil)
}

func TestProfilesRequestExporter_WithSpan(t *testing.T) {
Expand All @@ -205,7 +205,7 @@ func TestProfilesRequestExporter_WithSpan(t *testing.T) {
le, err := NewProfilesRequestExporter(context.Background(), set, internal.RequestFromProfilesFunc(nil))
require.NoError(t, err)
require.NotNil(t, le)
checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, nil, 1)
checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, nil)
}

func TestProfilesExporter_WithSpan_ReturnError(t *testing.T) {
Expand All @@ -219,7 +219,7 @@ func TestProfilesExporter_WithSpan_ReturnError(t *testing.T) {
le, err := NewProfilesExporter(context.Background(), set, &fakeProfilesExporterConfig, newPushProfilesData(want))
require.NoError(t, err)
require.NotNil(t, le)
checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, want, 1)
checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, want)
}

func TestProfilesRequestExporter_WithSpan_ReturnError(t *testing.T) {
Expand All @@ -233,7 +233,7 @@ func TestProfilesRequestExporter_WithSpan_ReturnError(t *testing.T) {
le, err := NewProfilesRequestExporter(context.Background(), set, internal.RequestFromProfilesFunc(want))
require.NoError(t, err)
require.NotNil(t, le)
checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, want, 1)
checkWrapSpanForProfilesExporter(t, sr, set.TracerProvider.Tracer("test"), le, want)
}

func TestProfilesExporter_WithShutdown(t *testing.T) {
Expand Down Expand Up @@ -299,10 +299,7 @@ func generateProfilesTraffic(t *testing.T, tracer trace.Tracer, le xexporter.Pro
}
}

// nolint: unparam
func checkWrapSpanForProfilesExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le xexporter.Profiles,
wantError error, numSampleRecords int64,
) {
func checkWrapSpanForProfilesExporter(t *testing.T, sr *tracetest.SpanRecorder, tracer trace.Tracer, le xexporter.Profiles, wantError error) {
const numRequests = 5
generateProfilesTraffic(t, tracer, le, numRequests, wantError)

Expand All @@ -316,11 +313,11 @@ func checkWrapSpanForProfilesExporter(t *testing.T, sr *tracetest.SpanRecorder,
require.Equalf(t, parentSpan.SpanContext(), sd.Parent(), "Exporter span not a child\nSpanData %v", sd)
internal.CheckStatus(t, sd, wantError)

sentSampleRecords := numSampleRecords
var failedToSendSampleRecords int64
sentSampleRecords := int64(1)
failedToSendSampleRecords := int64(0)
if wantError != nil {
sentSampleRecords = 0
failedToSendSampleRecords = numSampleRecords
failedToSendSampleRecords = 1
}
require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.SentSamplesKey, Value: attribute.Int64Value(sentSampleRecords)}, "SpanData %v", sd)
require.Containsf(t, sd.Attributes(), attribute.KeyValue{Key: internal.FailedToSendSamplesKey, Value: attribute.Int64Value(failedToSendSampleRecords)}, "SpanData %v", sd)
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (e *baseExporter) export(ctx context.Context, url string, request []byte, p

defer func() {
// Discard any remaining response body when we are done reading.
io.CopyN(io.Discard, resp.Body, maxHTTPResponseReadBytes) // nolint:errcheck
_, _ = io.CopyN(io.Discard, resp.Body, maxHTTPResponseReadBytes)
resp.Body.Close()
}()

Expand Down
2 changes: 1 addition & 1 deletion otelcol/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (col *Collector) Shutdown() {
state := col.GetState()
if state == StateRunning || state == StateStarting {
defer func() {
recover() // nolint:errcheck
_ = recover()
}()
close(col.shutdownChan)
}
Expand Down
1 change: 0 additions & 1 deletion pdata/pmetric/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
func FuzzUnmarshalMetrics(f *testing.F) {
f.Fuzz(func(_ *testing.T, data []byte) {
u := &JSONUnmarshaler{}
//nolint: errcheck
_, _ = u.UnmarshalMetrics(data)
})
}
12 changes: 4 additions & 8 deletions pdata/pmetric/pmetricotlp/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,27 @@ import (
func FuzzRequestUnmarshalJSON(f *testing.F) {
f.Fuzz(func(_ *testing.T, data []byte) {
er := NewExportRequest()
//nolint: errcheck
er.UnmarshalJSON(data)
_ = er.UnmarshalJSON(data)
})
}

func FuzzResponseUnmarshalJSON(f *testing.F) {
f.Fuzz(func(_ *testing.T, data []byte) {
er := NewExportResponse()
//nolint: errcheck
er.UnmarshalJSON(data)
_ = er.UnmarshalJSON(data)
})
}

func FuzzRequestUnmarshalProto(f *testing.F) {
f.Fuzz(func(_ *testing.T, data []byte) {
er := NewExportRequest()
//nolint: errcheck
er.UnmarshalProto(data)
_ = er.UnmarshalJSON(data)
})
}

func FuzzResponseUnmarshalProto(f *testing.F) {
f.Fuzz(func(_ *testing.T, data []byte) {
er := NewExportResponse()
//nolint: errcheck
er.UnmarshalProto(data)
_ = er.UnmarshalJSON(data)
})
}
3 changes: 1 addition & 2 deletions receiver/otlpreceiver/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,7 @@ func TestOTLPReceiverHTTPTracesIngestTest(t *testing.T) {
errStatus := &spb.Status{}
require.NoError(t, proto.Unmarshal(respBytes, errStatus))
assert.Equal(t, ingestionState.expectedStatusCode, resp.StatusCode)
// nolint:gosec
assert.Equal(t, ingestionState.expectedCode, codes.Code(errStatus.Code))
assert.EqualValues(t, ingestionState.expectedCode, errStatus.Code)
}
}

Expand Down
2 changes: 0 additions & 2 deletions service/internal/graph/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
)

// TODO: remove as part of https://github.com/open-telemetry/opentelemetry-collector/issues/7370 for service 1.0
//
// nolint
type getExporters interface {
GetExporters() map[pipeline.Signal]map[component.ID]component.Component
}
Expand Down

0 comments on commit 4cf491b

Please sign in to comment.