Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.*: replace linters with golangci-lint #1227

Merged
merged 27 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
49bc5cf
.*: replace linters with golangci-lint
GiedriusS Jun 5, 2019
94fe33a
Makefile: fix binary name
GiedriusS Jun 5, 2019
897faf7
Makefile: fix path
GiedriusS Jun 5, 2019
838bbf1
Add .golangci.yml
Jun 6, 2019
a8844cf
Makefile: convert format to gometalint
Jun 6, 2019
c5d9cdf
.*: fix ineffectual assignment errors
Jun 6, 2019
0e296b9
.*: nuke lots of linter errors
Jun 7, 2019
e33c4b6
.*: fix more linter problems
GiedriusS Jun 9, 2019
96e6e13
.*: fix more linter errors
Jun 11, 2019
e49d0b0
.golangci: ignore InstrumentHandler{,Func} deprecation warnings
Jun 13, 2019
c228ea1
.golangci: fix indentation problems
Jun 13, 2019
dbe2a47
pkg/tracking: run goimports
Jun 13, 2019
9bc0900
.*: more goimports
Jun 13, 2019
6950cf2
.*: more goimports
Jun 13, 2019
06e3147
pkg/pool: fix test
Jun 14, 2019
4ee8313
store/prometheus: cleanup sync.Pool usage
Jun 14, 2019
ab2f1bd
store/bucket: use ptrs consistently
Jun 14, 2019
6c65e7b
store/bucket: return ownership to caller
Jun 14, 2019
c4f709b
Merge remote-tracking branch 'origin/master' into mci
Jul 1, 2019
77451d7
.*: fix rest of errors
Jul 1, 2019
699deee
component: bring back implementsStoreAPI()
GiedriusS Jul 1, 2019
704b97e
thanos/rule: refactor if
GiedriusS Jul 1, 2019
2026ee7
compact: use defer
GiedriusS Jul 1, 2019
c3d27f7
pool: null the slice
GiedriusS Jul 1, 2019
4d435b9
Merge remote-tracking branch 'origin' into gometaci
GiedriusS Jul 1, 2019
8682d6f
store: goimports
GiedriusS Jul 1, 2019
756d8b2
component: bring back the private methods
GiedriusS Jul 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
echo "Awesome! GCS integration tests are enabled."
fi
- run: make check-go-mod
- run: make errcheck
- run: make lint
- run: make check-docs
- run: make format
- run:
Expand Down Expand Up @@ -131,4 +131,4 @@ workflows:
tags:
only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
branches:
ignore: /.*/
ignore: /.*/
21 changes: 21 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
linters-settings:
errcheck:
exclude: ./.errcheck_excludes.txt

issues:
exclude-rules:
# TODO: move away from deprecated prometheus.InstrumentHandler{,Func}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't already, let's open an issue for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1304 👍 good catch

- linters:
- staticcheck
text: "SA1019:"
# These are not being checked since these methods exist
# so that no one else could implement them.
- linters:
- unused
text: "SourceStoreAPI.implementsStoreAPI"
- linters:
- unused
text: "SourceStoreAPI.producesBlocks"
- linters:
- unused
text: "Source.producesBlocks"
42 changes: 17 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PREFIX ?= $(shell pwd)
FILES_TO_FMT ?= $(shell find . -path ./vendor -prune -o -name '*.go' -print)

DOCKER_IMAGE_NAME ?= thanos
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))-$(shell date +%Y-%m-%d)-$(shell git rev-parse --short HEAD)
Expand All @@ -15,13 +14,8 @@ export GOPROXY
EMBEDMD ?= $(GOBIN)/embedmd-$(EMBEDMD_VERSION)
# v2.0.0
EMBEDMD_VERSION ?= 97c13d6e41602fc6e397eb51c45f38069371a969
ERRCHECK ?= $(GOBIN)/errcheck-$(ERRCHECK_VERSION)
# v1.2.0
ERRCHECK_VERSION ?= e14f8d59a22d460d56c5ee92507cd94c78fbf274
LICHE ?= $(GOBIN)/liche-$(LICHE_VERSION)
LICHE_VERSION ?= 2a2e6e56f6c615c17b2e116669c4cdb31b5453f3
GOIMPORTS ?= $(GOBIN)/goimports-$(GOIMPORTS_VERSION)
GOIMPORTS_VERSION ?= 9d4d845e86f14303813298ede731a971dd65b593
PROMU ?= $(GOBIN)/promu-$(PROMU_VERSION)
PROMU_VERSION ?= 9583e5a6448f97c6294dca72dd1d173e28f8d4a4
PROTOC ?= $(GOBIN)/protoc-$(PROTOC_VERSION)
Expand All @@ -33,6 +27,10 @@ HUGO ?= $(GOBIN)/hugo-$(HUGO_VERSION)
GOBINDATA_VERSION ?= a9c83481b38ebb1c4eb8f0168fd4b10ca1d3c523
GOBINDATA ?= $(GOBIN)/go-bindata-$(GOBINDATA_VERSION)
GIT ?= $(shell which git)
# golangci-lint which includes errcheck, goimports
# and more. v1.16.0
GOLANGCILINT_VERSION ?= 97ea1cbb21bbf5e4d0e8bcc0f9243385e9262dcc
GOLANGCILINT ?= $(GOBIN)/golangci-lint-$(GOLANGCILINT_VERSION)

WEB_DIR ?= website
WEBSITE_BASE_URL ?= https://thanos.io
Expand Down Expand Up @@ -151,19 +149,14 @@ check-docs: $(EMBEDMD) $(LICHE) build
@$(LICHE) --recursive docs --exclude "cloud.tencent.com" --document-root .
@$(LICHE) --exclude "cloud.tencent.com" --document-root . *.md

# errcheck performs static analysis and returns error if any of the errors is not checked.
.PHONY: errcheck
errcheck: $(ERRCHECK)
@echo ">> errchecking the code"
$(ERRCHECK) -verbose -exclude .errcheck_excludes.txt ./cmd/... ./pkg/... ./test/...

# format formats the code (including imports format).
# NOTE: format requires deps to not remove imports that are used, just not resolved.
# This is not encoded, because it is often used in IDE onSave logic.
# # NOTE: format requires deps to not remove imports that are used, just not resolved.
# # This is not encoded, because it is often used in IDE onSave logic.
.PHONY: format
format: $(GOIMPORTS)
format: check-git $(GOLANGCILINT)
@echo ">> formatting code"
@$(GOIMPORTS) -w $(FILES_TO_FMT)
@$(GOLANGCILINT) run --disable-all -E goimports ./...


# proto generates golang files from Thanos proto files.
.PHONY: proto
Expand Down Expand Up @@ -195,12 +188,6 @@ test-deps:
$(call fetch_go_bin_version,github.com/prometheus/alertmanager/cmd/alertmanager,$(ALERTMANAGER_VERSION))
$(call fetch_go_bin_version,github.com/minio/minio,$(MINIO_SERVER_VERSION))

# vet vets the code.
.PHONY: vet
vet: check-git
@echo ">> vetting code"
@go vet ./...

# go mod related
.PHONY: go-mod-tidy
go-mod-tidy: check-git
Expand Down Expand Up @@ -231,6 +218,11 @@ web: web-pre-process $(HUGO)
# TODO(bwplotka): Make it --gc
@cd $(WEB_DIR) && HUGO_ENV=production $(HUGO) --config hugo.yaml --minify -v -b $(WEBSITE_BASE_URL)

.PHONY: lint
lint: check-git $(GOLANGCILINT)
@echo ">> linting all of the Go files"
@$(GOLANGCILINT) run ./...

.PHONY: web-serve
web-serve: web-pre-process $(HUGO)
@echo ">> serving documentation website"
Expand All @@ -240,9 +232,6 @@ web-serve: web-pre-process $(HUGO)
$(EMBEDMD):
$(call fetch_go_bin_version,github.com/campoy/embedmd,$(EMBEDMD_VERSION))

$(ERRCHECK):
$(call fetch_go_bin_version,github.com/kisielk/errcheck,$(ERRCHECK_VERSION))

$(GOIMPORTS):
$(call fetch_go_bin_version,golang.org/x/tools/cmd/goimports,$(GOIMPORTS_VERSION))

Expand All @@ -260,6 +249,9 @@ $(HUGO):
$(GOBINDATA):
$(call fetch_go_bin_version,github.com/go-bindata/go-bindata/go-bindata,$(GOBINDATA_VERSION))

$(GOLANGCILINT):
$(call fetch_go_bin_version,github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCILINT_VERSION))

$(PROTOC):
@mkdir -p $(TMP_GOPATH)
@echo ">> fetching protoc@${PROTOC_VERSION}"
Expand Down
1 change: 0 additions & 1 deletion cmd/thanos/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func registerBucket(m map[string]setupFunc, app *kingpin.Application, name strin
registerBucketLs(m, cmd, name, objStoreConfig)
registerBucketInspect(m, cmd, name, objStoreConfig)
registerBucketWeb(m, cmd, name, objStoreConfig)
return
}

func registerBucketVerify(m map[string]setupFunc, root *kingpin.CmdClause, name string, objStoreConfig *pathOrContent) {
Expand Down
3 changes: 3 additions & 0 deletions cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func runCompact(
// are in milliseconds.
comp, err := tsdb.NewLeveledCompactor(ctx, reg, logger, levels, downsample.NewPool())
if err != nil {
cancel()
return errors.Wrap(err, "create compactor")
}

Expand All @@ -216,11 +217,13 @@ func runCompact(
)

if err := os.RemoveAll(downsamplingDir); err != nil {
cancel()
return errors.Wrap(err, "clean working downsample directory")
}

compactor, err := compact.NewBucketCompactor(logger, sy, comp, compactDir, bkt, concurrency)
if err != nil {
cancel()
return errors.Wrap(err, "create bucket compactor")
}

Expand Down
2 changes: 0 additions & 2 deletions cmd/thanos/downsample.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ func processDownsampling(ctx context.Context, logger log.Logger, bkt objstore.Bu

level.Info(logger).Log("msg", "uploaded block", "id", id, "duration", time.Since(begin))

begin = time.Now()

// It is not harmful if these fails.
if err := os.RemoveAll(bdir); err != nil {
level.Warn(logger).Log("msg", "failed to clean directory", "dir", bdir, "err", err)
Expand Down
4 changes: 4 additions & 0 deletions cmd/thanos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ func main() {
var closer io.Closer
var confContentYaml []byte
confContentYaml, err = tracingConfig.Content()
if err != nil {
GiedriusS marked this conversation as resolved.
Show resolved Hide resolved
level.Error(logger).Log("msg", "getting tracing config failed", "err", err)
os.Exit(1)
}

if len(confContentYaml) == 0 {
level.Info(logger).Log("msg", "Tracing will be disabled")
Expand Down
5 changes: 1 addition & 4 deletions cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,7 @@ func runReceive(
err error
)
g.Add(func() error {
select {
case <-dbOpen:
break
}
<-dbOpen

l, err = net.Listen("tcp", grpcBindAddr)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,14 +762,14 @@ func queryFunc(

if err != nil {
level.Error(logger).Log("err", err, "query", q)
} else {
if len(warns) > 0 {
ruleEvalWarnings.WithLabelValues(strings.ToLower(partialResponseStrategy.String())).Inc()
// TODO(bwplotka): Propagate those to UI, probably requires changing rule manager code ):
level.Warn(logger).Log("warnings", strings.Join(warns, ", "), "query", q)
}
return v, nil
}

if err == nil && len(warns) > 0 {
ruleEvalWarnings.WithLabelValues(strings.ToLower(partialResponseStrategy.String())).Inc()
// TODO(bwplotka): Propagate those to UI, probably requires changing rule manager code ):
level.Warn(logger).Log("warnings", strings.Join(warns, ", "), "query", q)
}
return v, err
}
return nil, errors.Errorf("no query peer reachable")
}
Expand Down
1 change: 0 additions & 1 deletion pkg/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ func (s *Sender) Send(ctx context.Context, alerts []*Alert) {

s.dropped.Add(float64(len(alerts)))
level.Warn(s.logger).Log("msg", "failed to send alerts to all alertmanagers", "alertmanagers", amrs, "alerts", string(b))
return
}

func (s *Sender) sendOne(ctx context.Context, url string, b []byte) error {
Expand Down
7 changes: 1 addition & 6 deletions pkg/block/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func GatherIndexIssueStats(logger log.Logger, fn string, minTime int64, maxTime
stats.OutOfOrderLabels++
level.Warn(logger).Log("msg",
"out-of-order label set: known bug in Prometheus 2.8.0 and below",
"labelset", fmt.Sprintf("%s", lset),
"labelset", lset.String(),
"series", fmt.Sprintf("%d", id),
)
}
Expand Down Expand Up @@ -727,11 +727,6 @@ func (ss stringset) set(s string) {
ss[s] = struct{}{}
}

func (ss stringset) has(s string) bool {
_, ok := ss[s]
return ok
}

func (ss stringset) String() string {
return strings.Join(ss.slice(), ",")
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/block/metadata/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ const (
// Meta describes the a block's meta. It wraps the known TSDB meta structure and
// extends it by Thanos-specific fields.
type Meta struct {
Version int `json:"version"`

tsdb.BlockMeta

Thanos Thanos `json:"thanos"`
Expand Down
4 changes: 1 addition & 3 deletions pkg/compact/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ type syncerMetrics struct {
garbageCollectionDuration prometheus.Histogram
compactions *prometheus.CounterVec
compactionFailures *prometheus.CounterVec
indexCacheBlocks prometheus.Counter
GiedriusS marked this conversation as resolved.
Show resolved Hide resolved
indexCacheTraverse prometheus.Counter
indexCacheFailures prometheus.Counter
}

func newSyncerMetrics(reg prometheus.Registerer) *syncerMetrics {
Expand Down Expand Up @@ -985,6 +982,7 @@ func (c *BucketCompactor) Compact(ctx context.Context) error {
finishedAllGroups = true
mtx sync.Mutex
)
defer workCtxCancel()

// Set up workers who will compact the groups when the groups are ready.
// They will compact available groups until they encounter an error, after which they will stop.
Expand Down
1 change: 0 additions & 1 deletion pkg/compact/downsample/downsample.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ func (a *aggregator) add(v float64) {
// aggrChunkBuilder builds chunks for multiple different aggregates.
type aggrChunkBuilder struct {
mint, maxt int64
isCounter bool
added int

chunks [5]chunkenc.Chunk
Expand Down
2 changes: 1 addition & 1 deletion pkg/compact/retention_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ func TestApplyRetentionPolicyByResolution(t *testing.T) {
func uploadMockBlock(t *testing.T, bkt objstore.Bucket, id string, minTime, maxTime time.Time, resolutionLevel int64) {
t.Helper()
meta1 := metadata.Meta{
Version: 1,
BlockMeta: tsdb.BlockMeta{
ULID: ulid.MustParse(id),
MinTime: minTime.Unix() * 1000,
MaxTime: maxTime.Unix() * 1000,
Version: 1,
},
Thanos: metadata.Thanos{
Downsample: metadata.ThanosDownsample{
Expand Down
1 change: 0 additions & 1 deletion pkg/discovery/dns/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func (p *Provider) Resolve(ctx context.Context, addrs []string) {
p.resolverLookupsCount.Inc()
if err != nil {
// The DNS resolution failed. Continue without modifying the old records.
p.resolved[addr] = p.resolved[addr] // Ensure metrics capture the result even if empty.
p.resolverFailuresCount.Inc()
level.Error(p.logger).Log("msg", "dns resolution failed", "addr", addr, "err", err)
continue
Expand Down
4 changes: 2 additions & 2 deletions pkg/objstore/azure/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func getContainerURL(ctx context.Context, conf Config) (blob.ContainerURL, error
MaxTries: int32(conf.MaxRetries),
}
if deadline, ok := ctx.Deadline(); ok {
retryOptions.TryTimeout = deadline.Sub(time.Now())
retryOptions.TryTimeout = time.Until(deadline)
}

p := blob.NewPipeline(c, blob.PipelineOptions{
Expand Down Expand Up @@ -73,7 +73,7 @@ func getBlobURL(ctx context.Context, conf Config, blobName string) (blob.BlockBl

func parseError(errorCode string) string {
match := errorCodeRegex.FindStringSubmatch(errorCode)
if match != nil && len(match) == 2 {
if len(match) == 2 {
return match[1]
}
return errorCode
Expand Down
4 changes: 1 addition & 3 deletions pkg/objstore/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (b *Bucket) Close() error {
// In a close function it empties and deletes the bucket.
func NewTestBucket(t testing.TB, project string) (objstore.Bucket, func(), error) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
src := rand.NewSource(time.Now().UnixNano())
gTestConfig := Config{
Bucket: fmt.Sprintf("test_%s_%x", strings.ToLower(t.Name()), src.Int63()),
Expand All @@ -180,12 +181,10 @@ func NewTestBucket(t testing.TB, project string) (objstore.Bucket, func(), error

b, err := NewBucket(ctx, log.NewNopLogger(), bc, "thanos-e2e-test")
if err != nil {
cancel()
return nil, nil, err
}

if err = b.bkt.Create(ctx, project, nil); err != nil {
cancel()
_ = b.Close()
return nil, nil, err
}
Expand All @@ -196,7 +195,6 @@ func NewTestBucket(t testing.TB, project string) (objstore.Bucket, func(), error
if err := b.bkt.Delete(ctx); err != nil {
t.Logf("deleting bucket failed: %s", err)
}
cancel()
if err := b.Close(); err != nil {
t.Logf("closing bucket failed: %s", err)
}
Expand Down
Loading