diff --git a/.golangci.yml b/.golangci.yml index d9efa75..c0809b3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,27 @@ -# Run only staticcheck for now. Additional linters will be enabled one-by-one. +run: + issues-exit-code: 1 + tests: true linters: + disable: + - errcheck enable: - - staticcheck - disable-all: true + - deadcode + - goimports + - gosimple + - govet + - ineffassign + - nakedret + - staticcheck + - structcheck + - unused + - varcheck + - whitespace +linters-settings: + govet: + check-shadowing: true +issues: + exclude-use-default: false + exclude: + - 'shadow: declaration of "err" shadows declaration at line (\d+)' + max-issues-per-linter: 0 + max-same-issues: 0 diff --git a/main.go b/main.go index d070e5d..fdee20e 100644 --- a/main.go +++ b/main.go @@ -45,11 +45,6 @@ import ( "github.com/prometheus/statsd_exporter/pkg/relay" ) -const ( - defaultHelp = "Metric autogenerated by statsd_exporter." - regErrF = "Failed to update metric" -) - var ( eventStats = promauto.NewCounterVec( prometheus.CounterOpts{ @@ -171,17 +166,6 @@ var ( ) ) -// uncheckedCollector wraps a Collector but its Describe method yields no Desc. -// This allows incoming metrics to have inconsistent label sets -type uncheckedCollector struct { - c prometheus.Collector -} - -func (u uncheckedCollector) Describe(_ chan<- *prometheus.Desc) {} -func (u uncheckedCollector) Collect(c chan<- prometheus.Metric) { - u.c.Collect(c) -} - func serveHTTP(mux http.Handler, listenAddress string, logger log.Logger) { level.Error(logger).Log("msg", http.ListenAndServe(listenAddress, mux)) os.Exit(1) diff --git a/pkg/exporter/exporter_test.go b/pkg/exporter/exporter_test.go index 7a3a7c5..ef7836f 100644 --- a/pkg/exporter/exporter_test.go +++ b/pkg/exporter/exporter_test.go @@ -74,12 +74,6 @@ var ( Help: "The number of lines discarded due to being too long.", }, ) - unixgramPackets = prometheus.NewCounter( - prometheus.CounterOpts{ - Name: "statsd_exporter_unixgram_packets_total", - Help: "The total number of StatsD packets received over Unixgram.", - }, - ) linesReceived = prometheus.NewCounter( prometheus.CounterOpts{ Name: "statsd_exporter_lines_total", @@ -111,17 +105,6 @@ var ( Help: "The number of errors parsing DogStatsD tags.", }, ) - configLoads = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: "statsd_exporter_config_reloads_total", - Help: "The number of configuration reloads.", - }, - []string{"outcome"}, - ) - mappingsCount = prometheus.NewGauge(prometheus.GaugeOpts{ - Name: "statsd_exporter_loaded_mappings", - Help: "The current number of configured metric mappings.", - }) conflictingEventStats = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "statsd_exporter_events_conflict_total", diff --git a/pkg/line/line.go b/pkg/line/line.go index cd3aac2..98c70e3 100644 --- a/pkg/line/line.go +++ b/pkg/line/line.go @@ -239,7 +239,6 @@ samples: for _, sample := range samples { samplesReceived.Inc() components := strings.Split(sample, "|") - samplingFactor := 1.0 if len(components) < 2 || len(components) > 4 { sampleErrors.WithLabelValues("malformed_component").Inc() level.Debug(logger).Log("msg", "Bad component", "line", line) @@ -273,7 +272,7 @@ samples: switch component[0] { case '@': - samplingFactor, err = strconv.ParseFloat(component[1:], 64) + samplingFactor, err := strconv.ParseFloat(component[1:], 64) if err != nil { level.Debug(logger).Log("msg", "Invalid sampling factor", "component", component[1:], "line", line) sampleErrors.WithLabelValues("invalid_sample_factor").Inc() diff --git a/pkg/mapper/fsm/dump.go b/pkg/mapper/fsm/dump.go index d91e2cf..35772f9 100644 --- a/pkg/mapper/fsm/dump.go +++ b/pkg/mapper/fsm/dump.go @@ -43,6 +43,6 @@ func (f *FSM) DumpFSM(w io.Writer) { idx++ } // color for start state - w.Write([]byte(fmt.Sprintf("0 [color=\"#a94442\",fillcolor=\"#f2dede\"];\n"))) + w.Write([]byte(fmt.Sprintln("0 [color=\"#a94442\",fillcolor=\"#f2dede\"];"))) w.Write([]byte("}")) } diff --git a/pkg/mapper/mapper.go b/pkg/mapper/mapper.go index e213890..1471444 100644 --- a/pkg/mapper/mapper.go +++ b/pkg/mapper/mapper.go @@ -22,7 +22,7 @@ import ( "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" "github.com/prometheus/statsd_exporter/pkg/level" "github.com/prometheus/statsd_exporter/pkg/mapper/fsm" @@ -381,7 +381,6 @@ func (m *MetricMapper) GetMapping(statsdMetric string, statsdMetricType MetricTy // make a shallow copy so that we do not overwrite name // as multiple names can be matched by same mapping func copyMetricMapping(in *MetricMapping) *MetricMapping { - var out MetricMapping - out = *in + out := *in return &out }