From 74411467e2bfaedfc4f6bb4d6da1791cb562f2f2 Mon Sep 17 00:00:00 2001 From: Pablo Baeyens Date: Mon, 17 May 2021 18:38:00 +0200 Subject: [PATCH] Replace `golint` with `revive` (#3391) * Replace `golint` with `revive` * Fix new linting issues --- .golangci.yml | 4 ++-- exporter/awsprometheusremotewriteexporter/auth_test.go | 2 +- exporter/datadogexporter/metadata/system/host_unix.go | 2 +- exporter/datadogexporter/metrics_translator_test.go | 8 ++++---- exporter/datadogexporter/utils/http.go | 4 ++-- exporter/dynatraceexporter/metrics_exporter.go | 2 +- .../elasticexporter/internal/translator/elastic/traces.go | 5 +---- exporter/loadbalancingexporter/loadbalancer.go | 6 +----- exporter/loadbalancingexporter/log_exporter.go | 6 +----- exporter/loadbalancingexporter/trace_exporter.go | 6 +----- exporter/lokiexporter/config.go | 6 +----- exporter/splunkhecexporter/client.go | 2 +- exporter/splunkhecexporter/client_test.go | 6 +++--- processor/spanmetricsprocessor/processor.go | 6 +----- processor/tailsamplingprocessor/processor.go | 2 +- receiver/carbonreceiver/config.go | 6 +----- receiver/carbonreceiver/protocol/config.go | 6 +----- receiver/kafkametricsreceiver/consumer_scraper.go | 4 ++-- 18 files changed, 26 insertions(+), 57 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2e9b08ce35db9..62d351f0b7df5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -70,7 +70,7 @@ linters-settings: disable: - fieldalignment - golint: + revive: # minimal confidence for issues, default is 0.8 min-confidence: 0.8 gofmt: @@ -100,10 +100,10 @@ linters: - exportloopref - gofmt - goimports - - golint - gosec - govet - misspell + - revive - staticcheck - unconvert - unparam diff --git a/exporter/awsprometheusremotewriteexporter/auth_test.go b/exporter/awsprometheusremotewriteexporter/auth_test.go index 3ad0e2a62015b..221ae725d0fa4 100644 --- a/exporter/awsprometheusremotewriteexporter/auth_test.go +++ b/exporter/awsprometheusremotewriteexporter/auth_test.go @@ -35,7 +35,7 @@ import ( "go.opentelemetry.io/collector/config/configtls" ) -var sdkInformation string = fmt.Sprintf("%s/%s (%s; %s; %s)", aws.SDKName, aws.SDKVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH) +var sdkInformation = fmt.Sprintf("%s/%s (%s; %s; %s)", aws.SDKName, aws.SDKVersion, runtime.Version(), runtime.GOOS, runtime.GOARCH) func TestRequestSignature(t *testing.T) { // Some form of AWS credentials must be set up for tests to succeed diff --git a/exporter/datadogexporter/metadata/system/host_unix.go b/exporter/datadogexporter/metadata/system/host_unix.go index 68f0e4f86e54c..172f669d6b8ba 100644 --- a/exporter/datadogexporter/metadata/system/host_unix.go +++ b/exporter/datadogexporter/metadata/system/host_unix.go @@ -24,7 +24,7 @@ import ( ) // keep as var for testing -var hostnamePath string = "/bin/hostname" +var hostnamePath = "/bin/hostname" func getSystemFQDN() (string, error) { // Go does not provide a way to get the full hostname diff --git a/exporter/datadogexporter/metrics_translator_test.go b/exporter/datadogexporter/metrics_translator_test.go index 0d0a7c4f99896..add1526ae914b 100644 --- a/exporter/datadogexporter/metrics_translator_test.go +++ b/exporter/datadogexporter/metrics_translator_test.go @@ -31,10 +31,10 @@ import ( func TestMetricValue(t *testing.T) { var ( - name string = "name" - value float64 = math.Pi - ts uint64 = uint64(time.Now().UnixNano()) - tags []string = []string{"tool:opentelemetry", "version:0.1.0"} + name = "name" + value = math.Pi + ts = uint64(time.Now().UnixNano()) + tags = []string{"tool:opentelemetry", "version:0.1.0"} ) metric := metrics.NewGauge(name, ts, value, tags) diff --git a/exporter/datadogexporter/utils/http.go b/exporter/datadogexporter/utils/http.go index c7f125fde2f25..dcafe97a98571 100644 --- a/exporter/datadogexporter/utils/http.go +++ b/exporter/datadogexporter/utils/http.go @@ -25,11 +25,11 @@ import ( ) var ( - JSONHeaders map[string]string = map[string]string{ + JSONHeaders = map[string]string{ "Content-Type": "application/json", "Content-Encoding": "gzip", } - ProtobufHeaders map[string]string = map[string]string{ + ProtobufHeaders = map[string]string{ "Content-Type": "application/x-protobuf", "Content-Encoding": "identity", } diff --git a/exporter/dynatraceexporter/metrics_exporter.go b/exporter/dynatraceexporter/metrics_exporter.go index b2cf618ed680f..fccdaa97fdac2 100644 --- a/exporter/dynatraceexporter/metrics_exporter.go +++ b/exporter/dynatraceexporter/metrics_exporter.go @@ -132,7 +132,7 @@ func (e *exporter) serializeMetrics(md pdata.Metrics) ([]string, int) { return lines, dropped } -var lastLog int64 = 0 +var lastLog int64 // send sends a serialized metric batch to Dynatrace. // Returns the number of lines rejected by Dynatrace. diff --git a/exporter/elasticexporter/internal/translator/elastic/traces.go b/exporter/elasticexporter/internal/translator/elastic/traces.go index a07a26e8deb3c..52789f5b52ce6 100644 --- a/exporter/elasticexporter/internal/translator/elastic/traces.go +++ b/exporter/elasticexporter/internal/translator/elastic/traces.go @@ -91,10 +91,7 @@ func EncodeSpan( } w.RawString("}\n") } - if err := encodeSpanEvents(otlpSpan.Events(), otlpResource, traceID, spanID, w); err != nil { - return err - } - return nil + return encodeSpanEvents(otlpSpan.Events(), otlpResource, traceID, spanID, w) } func setTransactionProperties( diff --git a/exporter/loadbalancingexporter/loadbalancer.go b/exporter/loadbalancingexporter/loadbalancer.go index e49149abe93b0..215d7c5ce44bf 100644 --- a/exporter/loadbalancingexporter/loadbalancer.go +++ b/exporter/loadbalancingexporter/loadbalancer.go @@ -101,11 +101,7 @@ func newLoadBalancer(params component.ExporterCreateParams, cfg config.Exporter, func (lb *loadBalancerImp) Start(ctx context.Context, host component.Host) error { lb.res.onChange(lb.onBackendChanges) lb.host = host - if err := lb.res.start(ctx); err != nil { - return err - } - - return nil + return lb.res.start(ctx) } func (lb *loadBalancerImp) onBackendChanges(resolved []string) { diff --git a/exporter/loadbalancingexporter/log_exporter.go b/exporter/loadbalancingexporter/log_exporter.go index d59c4f7f943ca..852059d9f4cea 100644 --- a/exporter/loadbalancingexporter/log_exporter.go +++ b/exporter/loadbalancingexporter/log_exporter.go @@ -73,11 +73,7 @@ func (e *logExporterImp) Capabilities() consumer.Capabilities { } func (e *logExporterImp) Start(ctx context.Context, host component.Host) error { - if err := e.loadBalancer.Start(ctx, host); err != nil { - return err - } - - return nil + return e.loadBalancer.Start(ctx, host) } func (e *logExporterImp) Shutdown(context.Context) error { diff --git a/exporter/loadbalancingexporter/trace_exporter.go b/exporter/loadbalancingexporter/trace_exporter.go index efe8cb5bda69b..f528c0b72202a 100644 --- a/exporter/loadbalancingexporter/trace_exporter.go +++ b/exporter/loadbalancingexporter/trace_exporter.go @@ -84,11 +84,7 @@ func (e *traceExporterImp) Capabilities() consumer.Capabilities { } func (e *traceExporterImp) Start(ctx context.Context, host component.Host) error { - if err := e.loadBalancer.Start(ctx, host); err != nil { - return err - } - - return nil + return e.loadBalancer.Start(ctx, host) } func (e *traceExporterImp) Shutdown(context.Context) error { diff --git a/exporter/lokiexporter/config.go b/exporter/lokiexporter/config.go index c04dfec9251c9..42a2f96b77e78 100644 --- a/exporter/lokiexporter/config.go +++ b/exporter/lokiexporter/config.go @@ -43,11 +43,7 @@ func (c *Config) validate() error { return fmt.Errorf("\"endpoint\" must be a valid URL") } - if err := c.Labels.validate(); err != nil { - return err - } - - return nil + return c.Labels.validate() } // LabelsConfig defines the labels-related configuration diff --git a/exporter/splunkhecexporter/client.go b/exporter/splunkhecexporter/client.go index af3eaeb409739..e7136672a9dce 100644 --- a/exporter/splunkhecexporter/client.go +++ b/exporter/splunkhecexporter/client.go @@ -299,7 +299,7 @@ func subLogs(ld *pdata.Logs, from *logIndex) *pdata.Logs { k = from.record } - for kSub := 0; k < logs.Len(); k++ { + for kSub := 0; k < logs.Len(); k++ { //revive:disable-line:var-naming logsSub.AppendEmpty() logs.At(k).CopyTo(logsSub.At(kSub)) kSub++ diff --git a/exporter/splunkhecexporter/client_test.go b/exporter/splunkhecexporter/client_test.go index eee9b39cdaa52..734204647fe2b 100644 --- a/exporter/splunkhecexporter/client_test.go +++ b/exporter/splunkhecexporter/client_test.go @@ -790,7 +790,7 @@ func TestSubLogs(t *testing.T) { logs := createLogData(2, 2, 3) // Logs subset from leftmost index (resource 0, library 0, record 0). - _0_0_0 := &logIndex{resource: 0, library: 0, record: 0} + _0_0_0 := &logIndex{resource: 0, library: 0, record: 0} //revive:disable-line:var-naming got := subLogs(&logs, _0_0_0) // Number of logs in subset should equal original logs. @@ -802,7 +802,7 @@ func TestSubLogs(t *testing.T) { assert.Equal(t, "1_1_2", got.ResourceLogs().At(1).InstrumentationLibraryLogs().At(1).Logs().At(2).Name()) // Logs subset from some mid index (resource 0, library 1, log 2). - _0_1_2 := &logIndex{resource: 0, library: 1, record: 2} + _0_1_2 := &logIndex{resource: 0, library: 1, record: 2} //revive:disable-line:var-naming got = subLogs(&logs, _0_1_2) assert.Equal(t, 7, got.LogRecordCount()) @@ -813,7 +813,7 @@ func TestSubLogs(t *testing.T) { assert.Equal(t, "1_1_2", got.ResourceLogs().At(1).InstrumentationLibraryLogs().At(1).Logs().At(2).Name()) // Logs subset from rightmost index (resource 1, library 1, log 2). - _1_1_2 := &logIndex{resource: 1, library: 1, record: 2} + _1_1_2 := &logIndex{resource: 1, library: 1, record: 2} //revive:disable-line:var-naming got = subLogs(&logs, _1_1_2) // Number of logs in subset should be 1. diff --git a/processor/spanmetricsprocessor/processor.go b/processor/spanmetricsprocessor/processor.go index 10a6e60ca757f..0eb232b82db60 100644 --- a/processor/spanmetricsprocessor/processor.go +++ b/processor/spanmetricsprocessor/processor.go @@ -214,11 +214,7 @@ func (p *processorImp) ConsumeTraces(ctx context.Context, traces pdata.Traces) e } // Forward trace data unmodified. - if err := p.nextConsumer.ConsumeTraces(ctx, traces); err != nil { - return err - } - - return nil + return p.nextConsumer.ConsumeTraces(ctx, traces) } // buildMetrics collects the computed raw metrics data, builds the metrics object and diff --git a/processor/tailsamplingprocessor/processor.go b/processor/tailsamplingprocessor/processor.go index 586ec5238eab9..accce72bffc1a 100644 --- a/processor/tailsamplingprocessor/processor.go +++ b/processor/tailsamplingprocessor/processor.go @@ -190,7 +190,7 @@ func (tsp *tailSamplingSpanProcessor) samplingPolicyOnTick() { func (tsp *tailSamplingSpanProcessor) makeDecision(id pdata.TraceID, trace *sampling.TraceData, metrics *policyMetrics) (sampling.Decision, *Policy) { finalDecision := sampling.NotSampled - var matchingPolicy *Policy = nil + var matchingPolicy *Policy for i, policy := range tsp.policies { policyEvaluateStartTime := time.Now() diff --git a/receiver/carbonreceiver/config.go b/receiver/carbonreceiver/config.go index 2c538a32a8e41..9f09b0874f256 100644 --- a/receiver/carbonreceiver/config.go +++ b/receiver/carbonreceiver/config.go @@ -76,9 +76,5 @@ func (cfg *Config) Unmarshal(componentParser *config.Parser) error { } // Unmarshal exact to validate the config keys. - if err := componentParser.UnmarshalExact(cfg); err != nil { - return err - } - - return nil + return componentParser.UnmarshalExact(cfg) } diff --git a/receiver/carbonreceiver/protocol/config.go b/receiver/carbonreceiver/protocol/config.go index 46c33c3b0208b..33e0f00864a68 100644 --- a/receiver/carbonreceiver/protocol/config.go +++ b/receiver/carbonreceiver/protocol/config.go @@ -87,9 +87,5 @@ func LoadParserConfig(cp *config.Parser, cfg *Config) error { return errSub } - if err := vParserCfg.UnmarshalExact(cfg.Config); err != nil { - return err - } - - return nil + return vParserCfg.UnmarshalExact(cfg.Config) } diff --git a/receiver/kafkametricsreceiver/consumer_scraper.go b/receiver/kafkametricsreceiver/consumer_scraper.go index 9291e6f378b49..b0f356058e692 100644 --- a/receiver/kafkametricsreceiver/consumer_scraper.go +++ b/receiver/kafkametricsreceiver/consumer_scraper.go @@ -147,8 +147,8 @@ func (s *consumerScraper) scrape(context.Context) (pdata.ResourceMetricsSlice, e } grpTopicMetrics := grpMetrics.WithLabels(map[string]string{metadata.L.Topic: topic}) if isConsumed { - var lagSum int64 = 0 - var offsetSum int64 = 0 + var lagSum int64 + var offsetSum int64 for partition, block := range partitions { grpPartitionMetrics := grpTopicMetrics.WithLabels(map[string]string{metadata.L.Partition: string(partition)}) consumerOffset := block.Offset