Skip to content

Commit

Permalink
Upgrade golangci-lint and fix linting errors (grafana#9601)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:

Upgrade  `golangci-lint` and fixes all the errors. The upgrade includes some stricter linting.
  • Loading branch information
trevorwhitney authored Jun 12, 2023
1 parent 065bee7 commit 4a56445
Show file tree
Hide file tree
Showing 227 changed files with 705 additions and 700 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"image": "grafana/loki-build-image:0.28.3",
"image": "grafana/loki-build-image:0.29.0",
"containerEnv": {
"BUILD_IN_CONTAINER": "false"
},
Expand Down
42 changes: 21 additions & 21 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ steps:
depends_on:
- clone
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: check-drone-drift
- commands:
- make BUILD_IN_CONTAINER=false check-generated-files
depends_on:
- clone
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: check-generated-files
- commands:
- cd ..
Expand All @@ -110,7 +110,7 @@ steps:
depends_on:
- clone
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: clone-target-branch
when:
event:
Expand All @@ -121,15 +121,15 @@ steps:
- clone-target-branch
- check-generated-files
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: test
- commands:
- cd ../loki-target-branch
- BUILD_IN_CONTAINER=false make test
depends_on:
- clone-target-branch
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: test-target-branch
when:
event:
Expand All @@ -142,7 +142,7 @@ steps:
- test
- test-target-branch
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: compare-coverage
when:
event:
Expand All @@ -160,7 +160,7 @@ steps:
TOKEN:
from_secret: github_token
USER: grafanabot
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: report-coverage
when:
event:
Expand All @@ -170,15 +170,15 @@ steps:
depends_on:
- check-generated-files
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: lint
- commands:
- make BUILD_IN_CONTAINER=false check-mod
depends_on:
- test
- lint
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: check-mod
- commands:
- apk add make bash && make lint-scripts
Expand All @@ -189,21 +189,21 @@ steps:
depends_on:
- check-generated-files
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: loki
- commands:
- make BUILD_IN_CONTAINER=false check-doc
depends_on:
- loki
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: check-doc
- commands:
- make BUILD_IN_CONTAINER=false check-format GIT_TARGET_BRANCH="$DRONE_TARGET_BRANCH"
depends_on:
- loki
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: check-format
when:
event:
Expand All @@ -213,14 +213,14 @@ steps:
depends_on:
- loki
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: validate-example-configs
- commands:
- make BUILD_IN_CONTAINER=false check-example-config-doc
depends_on:
- clone
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: check-example-config-doc
- commands:
- mkdir -p /hugo/content/docs/loki/latest
Expand Down Expand Up @@ -253,7 +253,7 @@ steps:
depends_on:
- clone
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: loki-mixin-check
when:
event:
Expand All @@ -278,7 +278,7 @@ steps:
depends_on:
- clone
environment: {}
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: documentation-helm-reference-check
trigger:
ref:
Expand Down Expand Up @@ -1439,15 +1439,15 @@ steps:
NFPM_SIGNING_KEY:
from_secret: gpg_private_key
NFPM_SIGNING_KEY_FILE: /drone/src/private-key.key
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: write-key
- commands:
- make BUILD_IN_CONTAINER=false packages
environment:
NFPM_PASSPHRASE:
from_secret: gpg_passphrase
NFPM_SIGNING_KEY_FILE: /drone/src/private-key.key
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: test packaging
- commands:
- ./tools/packaging/verify-deb-install.sh
Expand All @@ -1473,7 +1473,7 @@ steps:
NFPM_PASSPHRASE:
from_secret: gpg_passphrase
NFPM_SIGNING_KEY_FILE: /drone/src/private-key.key
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: publish
when:
event:
Expand Down Expand Up @@ -1507,7 +1507,7 @@ steps:
from_secret: docker_password
DOCKER_USERNAME:
from_secret: docker_username
image: grafana/loki-build-image:0.28.3
image: grafana/loki-build-image:0.29.0
name: build and push
privileged: true
volumes:
Expand Down Expand Up @@ -1772,6 +1772,6 @@ kind: secret
name: gpg_private_key
---
kind: signature
hmac: 81437a4d7383dd556801f441c1510191471ae0349da15361a0b661bdc44bb8cd
hmac: 9959e5fb97ebc4800659a7cb733b06279c2acd3f87c8aae3c7d745ca91cfd055

...
11 changes: 7 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ run:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- win_eventlog$
- operator
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
Expand All @@ -39,6 +40,7 @@ run:
- .*.pb.go
- .*.y.go
- .*.rl.go
- .*.deepcopy.go
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
Expand All @@ -55,10 +57,11 @@ linters-settings:
local-prefixes: github.com/grafana/loki/pkg,github.com/grafana/loki/tools

depguard:
list-type: blacklist
include-go-root: true
packages-with-error-message:
- github.com/go-kit/kit/log: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
rules:
Main:
deny:
- desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
pkg: github.com/go-kit/kit/log

linters:
enable:
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ DOCKER_IMAGE_DIRS := $(patsubst %/Dockerfile,%,$(DOCKERFILES))
BUILD_IN_CONTAINER ?= true

# ensure you run `make drone` after changing this
BUILD_IMAGE_VERSION := 0.28.3
BUILD_IMAGE_VERSION := 0.29.0

# Docker image info
IMAGE_PREFIX ?= grafana
Expand All @@ -50,7 +50,7 @@ GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)

# We don't want find to scan inside a bunch of directories, to accelerate the
# 'make: Entering directory '/src/loki' phase.
DONT_FIND := -name tools -prune -o -name vendor -prune -o -name .git -prune -o -name .cache -prune -o -name .pkg -prune -o
DONT_FIND := -name tools -prune -o -name vendor -prune -o -name operator -prune -o -name .git -prune -o -name .cache -prune -o -name .pkg -prune -o

# Build flags
VPREFIX := github.com/grafana/loki/pkg/util/build
Expand Down Expand Up @@ -748,9 +748,9 @@ test-fuzz:

format:
find . $(DONT_FIND) -name '*.pb.go' -prune -o -name '*.y.go' -prune -o -name '*.rl.go' -prune -o \
-type f -name '*.go' -exec gofmt -w -s {} \;
-name '*_vfsdata.go' -prune -o -type f -name '*.go' -exec gofmt -w -s {} \;
find . $(DONT_FIND) -name '*.pb.go' -prune -o -name '*.y.go' -prune -o -name '*.rl.go' -prune -o \
-type f -name '*.go' -exec goimports -w -local github.com/grafana/loki {} \;
-name '*_vfsdata.go' -prune -o -type f -name '*.go' -exec goimports -w -local github.com/grafana/loki {} \;


GIT_TARGET_BRANCH ?= main
Expand Down
2 changes: 1 addition & 1 deletion clients/cmd/docker-driver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG BUILD_IMAGE=grafana/loki-build-image:0.28.3
ARG BUILD_IMAGE=grafana/loki-build-image:0.29.0
# Directories in this file are referenced from the root of the project not this folder
# This file is intended to be called from the root like so:
# docker build -t grafana/loki -f cmd/loki/Dockerfile .
Expand Down
2 changes: 1 addition & 1 deletion clients/cmd/promtail/Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG BUILD_IMAGE=grafana/loki-build-image:0.28.3
ARG BUILD_IMAGE=grafana/loki-build-image:0.29.0
# Directories in this file are referenced from the root of the project not this folder
# This file is intended to be called from the root like so:
# docker build -t grafana/promtail -f clients/cmd/promtail/Dockerfile .
Expand Down
2 changes: 1 addition & 1 deletion clients/cmd/promtail/Dockerfile.debug
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is intended to be called from the root like so:
# docker build -t grafana/promtail -f clients/cmd/promtail/Dockerfile.debug .

FROM grafana/loki-build-image:0.28.3 as build
FROM grafana/loki-build-image:0.29.0 as build
ARG GOARCH="amd64"
COPY . /src/loki
WORKDIR /src/loki
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/metric/histograms.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type HistogramConfig struct {
Buckets []float64 `mapstructure:"buckets"`
}

func validateHistogramConfig(config *HistogramConfig) error {
func validateHistogramConfig(_ *HistogramConfig) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/metric/metricvec.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func newMetricVec(factory func(labels map[string]string) prometheus.Metric, maxA

// Describe implements prometheus.Collector and doesn't declare any metrics on purpose to bypass prometheus validation.
// see https://godoc.org/github.com/prometheus/client_golang/prometheus#hdr-Custom_Collectors_and_constant_Metrics search for "unchecked"
func (c *metricVec) Describe(ch chan<- *prometheus.Desc) {}
func (c *metricVec) Describe(_ chan<- *prometheus.Desc) {}

// Collect implements prometheus.Collector
func (c *metricVec) Collect(ch chan<- prometheus.Metric) {
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (g *geoIPStage) Name() string {
return StageTypeGeoIP
}

func (g *geoIPStage) process(labels model.LabelSet, extracted map[string]interface{}, t *time.Time, entry *string) {
func (g *geoIPStage) process(labels model.LabelSet, extracted map[string]interface{}, _ *time.Time, _ *string) {
var ip net.IP
if g.cfgs.Source != nil {
if _, ok := extracted[*g.cfgs.Source]; !ok {
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/labelallow.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type labelAllowStage struct {
}

// Process implements Stage
func (l *labelAllowStage) Process(labels model.LabelSet, extracted map[string]interface{}, t *time.Time, entry *string) {
func (l *labelAllowStage) Process(labels model.LabelSet, _ map[string]interface{}, _ *time.Time, _ *string) {
for label := range labels {
if _, ok := l.labels[string(label)]; !ok {
delete(labels, label)
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/labeldrop.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type labelDropStage struct {
}

// Process implements Stage
func (l *labelDropStage) Process(labels model.LabelSet, extracted map[string]interface{}, t *time.Time, entry *string) {
func (l *labelDropStage) Process(labels model.LabelSet, _ map[string]interface{}, _ *time.Time, _ *string) {
for _, label := range l.cfgs {
delete(labels, model.LabelName(label))
}
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type labelStage struct {
}

// Process implements Stage
func (l *labelStage) Process(labels model.LabelSet, extracted map[string]interface{}, t *time.Time, entry *string) {
func (l *labelStage) Process(labels model.LabelSet, extracted map[string]interface{}, _ *time.Time, _ *string) {
for lName, lSrc := range l.cfgs {
if lValue, ok := extracted[*lSrc]; ok {
s, err := getString(lValue)
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/logfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func parseLogfmtConfig(config interface{}) (*LogfmtConfig, error) {
}

// Process implements Stage
func (j *logfmtStage) Process(labels model.LabelSet, extracted map[string]interface{}, t *time.Time, entry *string) {
func (j *logfmtStage) Process(_ model.LabelSet, extracted map[string]interface{}, _ *time.Time, entry *string) {
// If a source key is provided, the logfmt stage should process it
// from the extracted map, otherwise should fallback to the entry
input := entry
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ type metricStage struct {
}

// Process implements Stage
func (m *metricStage) Process(labels model.LabelSet, extracted map[string]interface{}, t *time.Time, entry *string) {
func (m *metricStage) Process(labels model.LabelSet, extracted map[string]interface{}, _ *time.Time, entry *string) {
for name, collector := range m.metrics {
// There is a special case for counters where we count even if there is no match in the extracted map.
if c, ok := collector.(*metric.Counters); ok {
Expand Down
6 changes: 3 additions & 3 deletions clients/pkg/logentry/stages/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func TestMetricStage_Process(t *testing.T) {
"expression": "(?P<get>\"GET).*HTTP/1.1\" (?P<status>\\d*) (?P<time>\\d*ms)",
}
timeSource := "time"
true := "true"
tru := "true"
metricsConfig := MetricsConfig{
"total_keys": MetricConfig{
MetricType: "Counter",
Expand Down Expand Up @@ -501,15 +501,15 @@ func TestMetricStage_Process(t *testing.T) {
MetricType: "Counter",
Description: "contains_warn",
Config: metric.CounterConfig{
Value: &true,
Value: &tru,
Action: metric.CounterInc,
},
},
"contains_false": MetricConfig{
MetricType: "Counter",
Description: "contains_false",
Config: metric.CounterConfig{
Value: &true,
Value: &tru,
Action: metric.CounterAdd,
},
},
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type outputStage struct {
}

// Process implements Stage
func (o *outputStage) Process(labels model.LabelSet, extracted map[string]interface{}, t *time.Time, entry *string) {
func (o *outputStage) Process(_ model.LabelSet, extracted map[string]interface{}, _ *time.Time, entry *string) {
if o.cfgs == nil {
return
}
Expand Down
1 change: 1 addition & 0 deletions clients/pkg/logentry/stages/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func BenchmarkPipeline(b *testing.B) {
b.ResetTimer()

go func() {
//nolint:revive
for range out {
}
}()
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func parseRegexConfig(config interface{}) (*RegexConfig, error) {
}

// Process implements Stage
func (r *regexStage) Process(labels model.LabelSet, extracted map[string]interface{}, t *time.Time, entry *string) {
func (r *regexStage) Process(_ model.LabelSet, extracted map[string]interface{}, _ *time.Time, entry *string) {
// If a source key is provided, the regex stage should process it
// from the extracted map, otherwise should fallback to the entry
input := entry
Expand Down
Loading

0 comments on commit 4a56445

Please sign in to comment.