Skip to content

Commit

Permalink
Fix some errcheck errors (#2881)
Browse files Browse the repository at this point in the history
* Check testbed errors

* Check some more errors

* Empty commit to retrigger CI

* Address comments on hostmetricsreceiver

* Rewrite some errchecking code

* Inline ifs

* Inline ifs and change log.Fatalf + Error() calls by log.Fatal
  • Loading branch information
mx-psi authored May 14, 2021
1 parent 4976c05 commit 29b576e
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion component/componenttest/shutdown_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func verifyTracesProcessorDoesntProduceAfterShutdown(t *testing.T, factory compo
// Send some traces to the processor.
const generatedCount = 10
for i := 0; i < generatedCount; i++ {
processor.ConsumeTraces(context.Background(), testdata.GenerateTraceDataOneSpan())
require.NoError(t, processor.ConsumeTraces(context.Background(), testdata.GenerateTraceDataOneSpan()))
}

// Now shutdown the processor.
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlphttpexporter/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (e *exporter) export(ctx context.Context, url string, request []byte) error

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

Expand Down
2 changes: 1 addition & 1 deletion processor/processorhelper/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func sha1Hasher(attr pdata.AttributeValue) {
if len(val) > 0 {
// #nosec
h := sha1.New()
h.Write(val)
h.Write(val) // nolint: errcheck
val = h.Sum(nil)
hashedBytes := make([]byte, hex.EncodedLen(len(val)))
hex.Encode(hashedBytes, val)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ func appendSystemSpecificProcessesMetrics(metrics pdata.MetricSlice, startIndex

metrics.Resize(startIndex + unixMetricsLen)
initializeProcessesCountMetric(metrics.At(startIndex+0), now, misc)
appendUnixSystemSpecificProcessesMetrics(metrics, startIndex+1, now, misc)
if err = appendUnixSystemSpecificProcessesMetrics(metrics, startIndex+1, now, misc); err != nil {
return err
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/kafkareceiver/kafka_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (c *kafkaTracesConsumer) Start(context.Context, component.Host) error {
nextConsumer: c.nextConsumer,
ready: make(chan bool),
}
go c.consumeLoop(ctx, consumerGroup)
go c.consumeLoop(ctx, consumerGroup) // nolint:errcheck
<-consumerGroup.ready
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/otlphttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ func errorHandler(w http.ResponseWriter, r *http.Request, errMsg string, statusC

w.Header().Set("Content-Type", contentType)
w.WriteHeader(statusCode)
w.Write(msg)
w.Write(msg) // nolint:errcheck
}
2 changes: 1 addition & 1 deletion receiver/zipkinreceiver/trace_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func (zr *ZipkinReceiver) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if consumerErr != nil {
// Transient error, due to some internal condition.
w.WriteHeader(http.StatusInternalServerError)
w.Write(errNextConsumerRespBody)
w.Write(errNextConsumerRespBody) // nolint:errcheck
return
}

Expand Down
6 changes: 3 additions & 3 deletions service/zpages.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (srv *service) RegisterZPages(mux *http.ServeMux, pathPrefix string) {
}

func (srv *service) handleServicezRequest(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
r.ParseForm() // nolint:errcheck
w.Header().Set("Content-Type", "text/html; charset=utf-8")
zpages.WriteHTMLHeader(w, zpages.HeaderData{Title: "service"})
zpages.WriteHTMLComponentHeader(w, zpages.ComponentHeaderData{
Expand All @@ -58,7 +58,7 @@ func (srv *service) handleServicezRequest(w http.ResponseWriter, r *http.Request
}

func (srv *service) handlePipelinezRequest(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
r.ParseForm() // nolint:errcheck
w.Header().Set("Content-Type", "text/html; charset=utf-8")
pipelineName := r.Form.Get(zPipelineName)
componentName := r.Form.Get(zComponentName)
Expand Down Expand Up @@ -116,7 +116,7 @@ func (srv *service) getPipelinesSummaryTableData() zpages.SummaryPipelinesTableD
}

func handleExtensionzRequest(host component.Host, w http.ResponseWriter, r *http.Request) {
r.ParseForm()
r.ParseForm() // nolint:errcheck
w.Header().Set("Content-Type", "text/html; charset=utf-8")
extensionName := r.Form.Get(zExtensionName)
zpages.WriteHTMLHeader(w, zpages.HeaderData{Title: "Extensions"})
Expand Down
4 changes: 3 additions & 1 deletion testbed/testbed/child_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ func (cp *ChildProcess) WatchResourceConsumption() error {
cp.fetchCPUUsage()

if err := cp.checkAllowedResourceUsage(); err != nil {
cp.Stop()
if _, errStop := cp.Stop(); errStop != nil {
log.Printf("Failed to stop child process: %v", err)
}
return err
}

Expand Down
5 changes: 3 additions & 2 deletions testbed/testbed/mock_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ func (mb *MockBackend) Stop() {
log.Printf("Stopping mock backend...")

mb.logFile.Close()
mb.receiver.Stop()

if err := mb.receiver.Stop(); err != nil {
log.Printf("Failed to stop receiver: %v", err)
}
// Print stats.
log.Printf("Stopped backend. %s", mb.GetStats())
})
Expand Down
12 changes: 8 additions & 4 deletions testbed/testbed/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ func (r *PerformanceResults) Init(resultsDir string) {
r.perTestResults = []*PerformanceTestResult{}

// Create resultsSummary file
os.MkdirAll(resultsDir, os.FileMode(0755))
if err := os.MkdirAll(resultsDir, os.FileMode(0755)); err != nil {
log.Fatal(err)
}
var err error
r.resultsFile, err = os.Create(path.Join(r.resultsDir, "TESTRESULTS.md"))
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err)
}

// Write the header
Expand Down Expand Up @@ -145,11 +147,13 @@ func (r *CorrectnessResults) Init(resultsDir string) {
r.perTestResults = []*CorrectnessTestResult{}

// Create resultsSummary file
os.MkdirAll(resultsDir, os.FileMode(0755))
if err := os.MkdirAll(resultsDir, os.FileMode(0755)); err != nil {
log.Fatal(err)
}
var err error
r.resultsFile, err = os.Create(path.Join(r.resultsDir, "CORRECTNESSRESULTS.md"))
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err)
}

// Write the header
Expand Down
4 changes: 3 additions & 1 deletion testbed/testbed/test_case.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ func (tc *TestCase) StartAgent(args ...string) {

// StopAgent stops agent process.
func (tc *TestCase) StopAgent() {
tc.agentProc.Stop()
if _, err := tc.agentProc.Stop(); err != nil {
tc.indicateError(err)
}
}

// StartLoad starts the load generator and redirects its standard output and standard error
Expand Down

0 comments on commit 29b576e

Please sign in to comment.