From f2fb9c8d5524abba85c87ef341d707c7a8173932 Mon Sep 17 00:00:00 2001 From: Anderson Queiroz Date: Tue, 8 Jun 2021 18:30:14 +0200 Subject: [PATCH] replaces golint by revive and fix newly reported linter issues (#800) * replaces golint by revive and fix newly reported linter issues * fix lint issue Co-authored-by: Tyler Yahn --- .golangci.yml | 6 +++--- detectors/aws/ecs/ecs.go | 1 + exporters/metric/cortex/cortex_test.go | 2 +- exporters/metric/dogstatsd/internal/statsd/conn.go | 1 + .../github.com/Shopify/sarama/otelsarama/example/init.go | 1 + instrumentation/github.com/astaxie/beego/otelbeego/beego.go | 2 +- .../github.com/aws/aws-sdk-go-v2/otelaws/attributes.go | 1 + .../go.mongodb.org/mongo-driver/mongo/otelmongo/db.go | 1 + .../go.mongodb.org/mongo-driver/mongo/otelmongo/peer.go | 4 ++-- .../go.mongodb.org/mongo-driver/mongo/otelmongo/tags.go | 1 + instrumentation/host/host.go | 1 + instrumentation/net/http/httptrace/otelhttptrace/api.go | 2 +- .../net/http/httptrace/otelhttptrace/clienttrace.go | 1 + .../net/http/httptrace/otelhttptrace/httptrace.go | 2 +- instrumentation/net/http/otelhttp/labeler.go | 2 +- instrumentation/runtime/runtime.go | 6 +----- 16 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index cef170f7c7f..eb43a1bddd5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,7 +7,7 @@ linters: enable: - misspell - goimports - - golint + - revive - gofmt issues: @@ -16,12 +16,12 @@ issues: - path: _test\.go text: "context.Context should be the first parameter of a function" linters: - - golint + - revive # Yes, they are, but it's okay in a test - path: _test\.go text: "exported func.*returns unexported type.*which can be annoying to use" linters: - - golint + - revive linters-settings: misspell: diff --git a/detectors/aws/ecs/ecs.go b/detectors/aws/ecs/ecs.go index 93c0537addb..d382161083f 100644 --- a/detectors/aws/ecs/ecs.go +++ b/detectors/aws/ecs/ecs.go @@ -27,6 +27,7 @@ import ( ) const ( + // TypeStr is AWS ECS type. TypeStr = "ecs" metadataV3EnvVar = "ECS_CONTAINER_METADATA_URI" metadataV4EnvVar = "ECS_CONTAINER_METADATA_URI_V4" diff --git a/exporters/metric/cortex/cortex_test.go b/exporters/metric/cortex/cortex_test.go index fd5bc660013..d32c00c6620 100644 --- a/exporters/metric/cortex/cortex_test.go +++ b/exporters/metric/cortex/cortex_test.go @@ -67,7 +67,7 @@ var validConfig = Config{ } var testResource = resource.NewWithAttributes(attribute.String("R", "V")) -var mockTime int64 = int64(time.Nanosecond) * time.Time{}.UnixNano() / int64(time.Millisecond) +var mockTime = int64(time.Nanosecond) * time.Time{}.UnixNano() / int64(time.Millisecond) func TestExportKindFor(t *testing.T) { exporter := Exporter{} diff --git a/exporters/metric/dogstatsd/internal/statsd/conn.go b/exporters/metric/dogstatsd/internal/statsd/conn.go index dd16de4dd16..d21b0f6ca89 100644 --- a/exporters/metric/dogstatsd/internal/statsd/conn.go +++ b/exporters/metric/dogstatsd/internal/statsd/conn.go @@ -91,6 +91,7 @@ const ( var ( _ export.Exporter = &Exporter{} + //nolint:revive // ignoring missing comments for unexported sentinel errors in an internal package. ErrInvalidScheme = fmt.Errorf("invalid statsd transport") ) diff --git a/instrumentation/github.com/Shopify/sarama/otelsarama/example/init.go b/instrumentation/github.com/Shopify/sarama/otelsarama/example/init.go index 4cb7619e182..0b8fe3617e9 100644 --- a/instrumentation/github.com/Shopify/sarama/otelsarama/example/init.go +++ b/instrumentation/github.com/Shopify/sarama/otelsarama/example/init.go @@ -24,6 +24,7 @@ import ( ) const ( + // KafkaTopic name. KafkaTopic = "sarama-instrumentation-example" ) diff --git a/instrumentation/github.com/astaxie/beego/otelbeego/beego.go b/instrumentation/github.com/astaxie/beego/otelbeego/beego.go index 7c4b4544f70..abfc5c5f638 100644 --- a/instrumentation/github.com/astaxie/beego/otelbeego/beego.go +++ b/instrumentation/github.com/astaxie/beego/otelbeego/beego.go @@ -26,7 +26,7 @@ import ( "github.com/astaxie/beego" ) -// OTelBeegoHandler implements the http.Handler interface and provides +// Handler implements the http.Handler interface and provides // trace and metrics to beego web apps. type Handler struct { http.Handler diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go index 50c1775b8af..34290232fcf 100644 --- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/attributes.go @@ -16,6 +16,7 @@ package otelaws import "go.opentelemetry.io/otel/attribute" +// AWS attributes. const ( OperationKey attribute.Key = "aws.operation" RegionKey attribute.Key = "aws.region" diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/db.go b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/db.go index 56d180082b4..d2edc54f44b 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/db.go +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/db.go @@ -16,6 +16,7 @@ package otelmongo import "go.opentelemetry.io/otel/attribute" +// Mongo DB attributes. const ( DBApplicationKey = attribute.Key("db.application") DBNameKey = attribute.Key("db.name") diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/peer.go b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/peer.go index 962e081216a..95414a64bf6 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/peer.go +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/peer.go @@ -17,9 +17,9 @@ package otelmongo import "go.opentelemetry.io/otel/attribute" const ( - // PeerHostname records the host name of the peer. + // PeerHostnameKey records the host name of the peer. PeerHostnameKey = attribute.Key("peer.hostname") - // PeerPort records the port number of the peer. + // PeerPortKey records the port number of the peer. PeerPortKey = attribute.Key("peer.port") ) diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/tags.go b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/tags.go index feddfe68dae..a7e33698619 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/tags.go +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/tags.go @@ -16,6 +16,7 @@ package otelmongo import "go.opentelemetry.io/otel/attribute" +// Mongo tag attributes. const ( TargetHostKey = attribute.Key("out.host") TargetPortKey = attribute.Key("out.port") diff --git a/instrumentation/host/host.go b/instrumentation/host/host.go index 81b61aa4da6..4317e26f564 100644 --- a/instrumentation/host/host.go +++ b/instrumentation/host/host.go @@ -66,6 +66,7 @@ func (o metricProviderOption) ApplyHost(c *config) { c.MeterProvider = o.MeterProvider } +// Attribute sets. var ( // Attribute sets for CPU time measurements. diff --git a/instrumentation/net/http/httptrace/otelhttptrace/api.go b/instrumentation/net/http/httptrace/otelhttptrace/api.go index 16b4763cc7f..491061583ee 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/api.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/api.go @@ -20,7 +20,7 @@ import ( "net/http/httptrace" ) -// Client +// W3C client. func W3C(ctx context.Context, req *http.Request) (context.Context, *http.Request) { ctx = httptrace.WithClientTrace(ctx, NewClientTrace(ctx)) req = req.WithContext(ctx) diff --git a/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go b/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go index 88c453a5b9f..a4d54b156f8 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/clienttrace.go @@ -30,6 +30,7 @@ import ( "go.opentelemetry.io/otel/trace" ) +// HTTP attributes. var ( HTTPStatus = attribute.Key("http.status") HTTPHeaderMIME = attribute.Key("http.mime") diff --git a/instrumentation/net/http/httptrace/otelhttptrace/httptrace.go b/instrumentation/net/http/httptrace/otelhttptrace/httptrace.go index e1d9363c1f0..728a8d6bd4d 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/httptrace.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/httptrace.go @@ -49,7 +49,7 @@ func WithPropagators(props propagation.TextMapPropagator) Option { } } -// Returns the Attributes, Context Entries, and SpanContext that were encoded by Inject. +// Extract returns the Attributes, Context Entries, and SpanContext that were encoded by Inject. func Extract(ctx context.Context, req *http.Request, opts ...Option) ([]attribute.KeyValue, []attribute.KeyValue, trace.SpanContext) { c := newConfig(opts) ctx = c.propagators.Extract(ctx, propagation.HeaderCarrier(req.Header)) diff --git a/instrumentation/net/http/otelhttp/labeler.go b/instrumentation/net/http/otelhttp/labeler.go index a1d102e769e..7b7d1c0aced 100644 --- a/instrumentation/net/http/otelhttp/labeler.go +++ b/instrumentation/net/http/otelhttp/labeler.go @@ -35,7 +35,7 @@ func (l *Labeler) Add(ls ...attribute.KeyValue) { l.attributes = append(l.attributes, ls...) } -// Labels returns a copy of the attributes added to the Labeler. +// Get returns a copy of the attributes added to the Labeler. func (l *Labeler) Get() []attribute.KeyValue { l.mu.Lock() defer l.mu.Unlock() diff --git a/instrumentation/runtime/runtime.go b/instrumentation/runtime/runtime.go index f9d31a36e1e..06f1015c934 100644 --- a/instrumentation/runtime/runtime.go +++ b/instrumentation/runtime/runtime.go @@ -150,11 +150,7 @@ func (r *runtime) register() error { return err } - if err := r.registerMemStats(); err != nil { - return err - } - - return nil + return r.registerMemStats() } func (r *runtime) registerMemStats() error {