feat: enable more linters and fix warnings (#364)

Signed-off-by: akartasov <agneum@gmail.com>
This commit is contained in:
akartasov 2021-10-24 21:22:01 +07:00
parent 95d34445ed
commit b60989291b
No known key found for this signature in database
GPG key ID: 9EDC00917A50AED6
6 changed files with 30 additions and 42 deletions

View file

@ -1,5 +1,28 @@
# Run only staticcheck for now. Additional linters will be enabled one-by-one. run:
issues-exit-code: 1
tests: true
skip-dirs:
- vendor
linters: linters:
enable:
- staticcheck
disable-all: true disable-all: true
enable:
- 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

16
main.go
View file

@ -45,11 +45,6 @@ import (
"github.com/prometheus/statsd_exporter/pkg/relay" "github.com/prometheus/statsd_exporter/pkg/relay"
) )
const (
defaultHelp = "Metric autogenerated by statsd_exporter."
regErrF = "Failed to update metric"
)
var ( var (
eventStats = promauto.NewCounterVec( eventStats = promauto.NewCounterVec(
prometheus.CounterOpts{ 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) { func serveHTTP(mux http.Handler, listenAddress string, logger log.Logger) {
level.Error(logger).Log("msg", http.ListenAndServe(listenAddress, mux)) level.Error(logger).Log("msg", http.ListenAndServe(listenAddress, mux))
os.Exit(1) os.Exit(1)

View file

@ -74,12 +74,6 @@ var (
Help: "The number of lines discarded due to being too long.", 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( linesReceived = prometheus.NewCounter(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "statsd_exporter_lines_total", Name: "statsd_exporter_lines_total",
@ -111,17 +105,6 @@ var (
Help: "The number of errors parsing DogStatsD tags.", 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( conflictingEventStats = prometheus.NewCounterVec(
prometheus.CounterOpts{ prometheus.CounterOpts{
Name: "statsd_exporter_events_conflict_total", Name: "statsd_exporter_events_conflict_total",

View file

@ -239,7 +239,6 @@ samples:
for _, sample := range samples { for _, sample := range samples {
samplesReceived.Inc() samplesReceived.Inc()
components := strings.Split(sample, "|") components := strings.Split(sample, "|")
samplingFactor := 1.0
if len(components) < 2 || len(components) > 4 { if len(components) < 2 || len(components) > 4 {
sampleErrors.WithLabelValues("malformed_component").Inc() sampleErrors.WithLabelValues("malformed_component").Inc()
level.Debug(logger).Log("msg", "Bad component", "line", line) level.Debug(logger).Log("msg", "Bad component", "line", line)
@ -273,7 +272,7 @@ samples:
switch component[0] { switch component[0] {
case '@': case '@':
samplingFactor, err = strconv.ParseFloat(component[1:], 64) samplingFactor, err := strconv.ParseFloat(component[1:], 64)
if err != nil { if err != nil {
level.Debug(logger).Log("msg", "Invalid sampling factor", "component", component[1:], "line", line) level.Debug(logger).Log("msg", "Invalid sampling factor", "component", component[1:], "line", line)
sampleErrors.WithLabelValues("invalid_sample_factor").Inc() sampleErrors.WithLabelValues("invalid_sample_factor").Inc()

View file

@ -43,6 +43,6 @@ func (f *FSM) DumpFSM(w io.Writer) {
idx++ idx++
} }
// color for start state // 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("}")) w.Write([]byte("}"))
} }

View file

@ -22,7 +22,7 @@ import (
"github.com/go-kit/log" "github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus" "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/level"
"github.com/prometheus/statsd_exporter/pkg/mapper/fsm" "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 // make a shallow copy so that we do not overwrite name
// as multiple names can be matched by same mapping // as multiple names can be matched by same mapping
func copyMetricMapping(in *MetricMapping) *MetricMapping { func copyMetricMapping(in *MetricMapping) *MetricMapping {
var out MetricMapping out := *in
out = *in
return &out return &out
} }