From f3b82a452335b7379fb25df31b88a960bf79337f Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Wed, 20 Jul 2022 22:41:45 +0800 Subject: [PATCH] [receiver/signalfx]fix lint for signalfxreceiver (#12592) * [receiver/signalfx]fix lint for fix-link-for-signalfxreceiver Signed-off-by: Ziqi Zhao * Update receiver/signalfxreceiver/receiver_test.go Co-authored-by: Dmitrii Anoshin * fix for reviews Signed-off-by: Ziqi Zhao Co-authored-by: Dmitrii Anoshin --- receiver/signalfxreceiver/receiver.go | 10 ++++++---- receiver/signalfxreceiver/receiver_test.go | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/receiver/signalfxreceiver/receiver.go b/receiver/signalfxreceiver/receiver.go index b8245ffae2cb..ed0c58cf12d8 100644 --- a/receiver/signalfxreceiver/receiver.go +++ b/receiver/signalfxreceiver/receiver.go @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// nolint:errcheck package signalfxreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/signalfxreceiver" import ( @@ -215,7 +214,10 @@ func (r *sfxReceiver) writeResponse(ctx context.Context, resp http.ResponseWrite } resp.WriteHeader(http.StatusOK) - resp.Write(okRespBody) + _, err = resp.Write(okRespBody) + if err != nil { + r.failRequest(ctx, resp, http.StatusInternalServerError, errNextConsumerRespBody, err) + } } func (r *sfxReceiver) handleDatapointReq(resp http.ResponseWriter, req *http.Request) { @@ -239,7 +241,7 @@ func (r *sfxReceiver) handleDatapointReq(resp http.ResponseWriter, req *http.Req if len(msg.Datapoints) == 0 { r.obsrecv.EndMetricsOp(ctx, typeStr, 0, nil) - resp.Write(okRespBody) + _, _ = resp.Write(okRespBody) return } @@ -285,7 +287,7 @@ func (r *sfxReceiver) handleEventReq(resp http.ResponseWriter, req *http.Request if len(msg.Events) == 0 { r.obsrecv.EndMetricsOp(ctx, typeStr, 0, nil) - resp.Write(okRespBody) + _, _ = resp.Write(okRespBody) return } diff --git a/receiver/signalfxreceiver/receiver_test.go b/receiver/signalfxreceiver/receiver_test.go index c383cdcbcdcb..52b16fd52bbd 100644 --- a/receiver/signalfxreceiver/receiver_test.go +++ b/receiver/signalfxreceiver/receiver_test.go @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// nolint:errcheck package signalfxreceiver import ( @@ -109,7 +108,9 @@ func Test_signalfxeceiver_EndToEnd(t *testing.T) { require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost())) require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost())) runtime.Gosched() - defer r.Shutdown(context.Background()) + defer func() { + require.NoError(t, r.Shutdown(context.Background())) + }() unixSecs := int64(1574092046) unixNSecs := int64(11 * time.Millisecond) @@ -178,7 +179,9 @@ func Test_signalfxeceiver_EndToEnd(t *testing.T) { } return false }, 10*time.Second, 5*time.Millisecond, "failed to wait for the port to be open") - defer exp.Shutdown(context.Background()) + defer func() { + require.NoError(t, exp.Shutdown(context.Background())) + }() require.NoError(t, exp.ConsumeMetrics(context.Background(), want)) mds := sink.AllMetrics() @@ -551,7 +554,9 @@ func Test_sfxReceiver_TLS(t *testing.T) { sink := new(consumertest.MetricsSink) r := newReceiver(componenttest.NewNopReceiverCreateSettings(), *cfg) r.RegisterMetricsConsumer(sink) - defer r.Shutdown(context.Background()) + defer func() { + require.NoError(t, r.Shutdown(context.Background())) + }() mh := newAssertNoErrorHost(t) require.NoError(t, r.Start(context.Background(), mh), "should not have failed to start metric reception")