Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix errcheck failed issue for the files of e2e-test, demos and tools. #9769

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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