Skip to content

Commit

Permalink
fix errcheck failed issue for the files of e2e-test, demos and tools. (
Browse files Browse the repository at this point in the history
…#9769)

* fix issue for examples/demo/server
* fix errcheck issue for testbed and tracegen
* fix govet error declaration of 'err' shadows declaration
Signed-off-by: Ziqi Zhao <zhaoziqi9146@gmail.com>
  • Loading branch information
fatsheep9146 authored May 6, 2022
1 parent 4990177 commit 789297f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
13 changes: 10 additions & 3 deletions examples/demo/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

// Sample contains a simple http server that exports to the OpenTelemetry agent.
// nolint:errcheck

package main

import (
Expand Down Expand Up @@ -141,6 +141,7 @@ func main() {
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
// random sleep to simulate latency
var sleep int64

switch modulus := time.Now().Unix() % 5; modulus {
case 0:
sleep = rng.Int63n(2000)
Expand All @@ -166,12 +167,18 @@ func main() {
}
span.SetAttributes(baggageAttributes...)

w.Write([]byte("Hello World"))
if _, err := w.Write([]byte("Hello World")); err != nil {
http.Error(w, "write operation failed.", http.StatusInternalServerError)
return
}

})
wrappedHandler := otelhttp.NewHandler(handler, "/hello")

// serve up the wrapped handler
http.Handle("/hello", wrappedHandler)
http.ListenAndServe(":7080", nil)
if err := http.ListenAndServe(":7080", nil); err != nil {
handleErr(err, "server failed to serve")
}

}
4 changes: 1 addition & 3 deletions testbed/datareceivers/mockawsxraydatareceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package datareceivers // import "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/datareceivers"

import (
Expand Down Expand Up @@ -81,8 +80,7 @@ func (ar *MockAwsXrayDataReceiver) Start(tc consumer.Traces, _ consumer.Metrics,
}

func (ar *MockAwsXrayDataReceiver) Stop() error {
ar.receiver.Shutdown(context.Background())
return nil
return ar.receiver.Shutdown(context.Background())
}

func (ar *MockAwsXrayDataReceiver) GenConfigYAMLStr() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package mockawsxrayreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/mockdatareceivers/mockawsxrayreceiver"

import (
Expand Down Expand Up @@ -108,7 +107,9 @@ func (ar *MockAwsXrayReceiver) handleRequest(req *http.Request) error {

var result map[string]interface{}

json.Unmarshal(body, &result)
if err = json.Unmarshal(body, &result); err != nil {
log.Fatalln(err)
}

traces, _ := ToTraces(body)
sc := traces.SpanCount()
Expand Down
5 changes: 3 additions & 2 deletions tracegen/internal/tracegen/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package tracegen // import "github.com/open-telemetry/opentelemetry-collector-contrib/tracegen/internal/tracegen"

import (
Expand Down Expand Up @@ -74,7 +73,9 @@ func (w worker) simulateTraces() {
semconv.PeerServiceKey.String("tracegen-client"),
))

limiter.Wait(context.Background())
if err := limiter.Wait(context.Background()); err != nil {
w.logger.Fatal("limiter waited failed, retry", zap.Error(err))
}

opt := trace.WithTimestamp(time.Now().Add(fakeSpanDuration))
child.End(opt)
Expand Down
9 changes: 7 additions & 2 deletions tracegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// nolint:errcheck
package main

import (
Expand Down Expand Up @@ -93,7 +92,13 @@ func main() {
}()

ssp := sdktrace.NewBatchSpanProcessor(exp, sdktrace.WithBatchTimeout(time.Second))
defer ssp.Shutdown(context.Background())
defer func() {
logger.Info("stop the batch span processor")
if err := ssp.Shutdown(context.Background()); err != nil {
logger.Error("failed to stop the batch span processor", zap.Error(err))
return
}
}()

tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithResource(resource.NewWithAttributes(semconv.SchemaURL, semconv.ServiceNameKey.String(cfg.ServiceName))),
Expand Down

0 comments on commit 789297f

Please sign in to comment.