diff --git a/.golangci.yml b/.golangci.yml index 5c6ebc779..c0df40161 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,14 +1,18 @@ run: timeout: 2m -enable: +linters: + enable: - revive issues: exclude-rules: - - linters: - - staticcheck - text: "SA(4003|1019|5011):" + - linters: + - staticcheck + text: "SA(4003|1019|5011):" + include: + - EXC0012 + - EXC0014 linters-settings: errcheck: diff --git a/app/vmbackup/main.go b/app/vmbackup/main.go index bbf36d374..d7fbe3d1d 100644 --- a/app/vmbackup/main.go +++ b/app/vmbackup/main.go @@ -51,27 +51,27 @@ func main() { if len(*snapshotCreateURL) > 0 { // create net/url object - createUrl, err := url.Parse(*snapshotCreateURL) + createURL, err := url.Parse(*snapshotCreateURL) if err != nil { logger.Fatalf("cannot parse snapshotCreateURL: %s", err) } if len(*snapshotName) > 0 { logger.Fatalf("-snapshotName shouldn't be set if -snapshot.createURL is set, since snapshots are created automatically in this case") } - logger.Infof("Snapshot create url %s", createUrl.Redacted()) + logger.Infof("Snapshot create url %s", createURL.Redacted()) if len(*snapshotDeleteURL) <= 0 { err := flag.Set("snapshot.deleteURL", strings.Replace(*snapshotCreateURL, "/create", "/delete", 1)) if err != nil { logger.Fatalf("Failed to set snapshot.deleteURL flag: %v", err) } } - deleteUrl, err := url.Parse(*snapshotDeleteURL) + deleteURL, err := url.Parse(*snapshotDeleteURL) if err != nil { logger.Fatalf("cannot parse snapshotDeleteURL: %s", err) } - logger.Infof("Snapshot delete url %s", deleteUrl.Redacted()) + logger.Infof("Snapshot delete url %s", deleteURL.Redacted()) - name, err := snapshot.Create(createUrl.String()) + name, err := snapshot.Create(createURL.String()) if err != nil { logger.Fatalf("cannot create snapshot: %s", err) } @@ -81,7 +81,7 @@ func main() { } defer func() { - err := snapshot.Delete(deleteUrl.String(), name) + err := snapshot.Delete(deleteURL.String(), name) if err != nil { logger.Fatalf("cannot delete snapshot: %s", err) } diff --git a/app/vmctl/backoff/backoff.go b/app/vmctl/backoff/backoff.go index 31cbf0017..beb14304d 100644 --- a/app/vmctl/backoff/backoff.go +++ b/app/vmctl/backoff/backoff.go @@ -19,6 +19,7 @@ const ( // retryableFunc describes call back which will repeat on errors type retryableFunc func() error +// ErrBadRequest is an error returned on bad request var ErrBadRequest = errors.New("bad request") // Backoff describes object with backoff policy params diff --git a/app/vmselect/promql/aggr.go b/app/vmselect/promql/aggr.go index 98fb1a6a9..3ba78615a 100644 --- a/app/vmselect/promql/aggr.go +++ b/app/vmselect/promql/aggr.go @@ -783,7 +783,7 @@ func fillNaNsAtIdx(idx int, k float64, tss []*timeseries) { } } -func getIntK(k float64, kMax int) int { +func getIntK(k float64, max int) int { if math.IsNaN(k) { return 0 } @@ -791,8 +791,8 @@ func getIntK(k float64, kMax int) int { if kn < 0 { return 0 } - if kn > kMax { - return kMax + if kn > max { + return max } return kn } diff --git a/lib/awsapi/sign.go b/lib/awsapi/sign.go index dba942c5d..a8c41193a 100644 --- a/lib/awsapi/sign.go +++ b/lib/awsapi/sign.go @@ -84,10 +84,10 @@ func signRequestWithTime(req *http.Request, service, region, payloadHash string, } func getSignatureKey(key, datestamp, region, service string) string { - kDate := hmacBin("AWS4"+key, datestamp) - kRegion := hmacBin(kDate, region) - kService := hmacBin(kRegion, service) - return hmacBin(kService, "aws4_request") + dateKey := hmacBin("AWS4"+key, datestamp) + regionKey := hmacBin(dateKey, region) + serviceKey := hmacBin(regionKey, service) + return hmacBin(serviceKey, "aws4_request") } func hashHex(s string) string { diff --git a/lib/fs/fs.go b/lib/fs/fs.go index 6332b90eb..f346b7953 100644 --- a/lib/fs/fs.go +++ b/lib/fs/fs.go @@ -468,6 +468,7 @@ func isHTTPURL(targetURL string) bool { } -func IsScheduledForRemoval(name string) bool { - return strings.Contains(name, ".must-remove.") +// IsScheduledForRemoval returns true if the filename contains .must-remove. substring +func IsScheduledForRemoval(filename string) bool { + return strings.Contains(filename, ".must-remove.") } diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index 9d0be0fbc..fa2b60c9e 100644 --- a/lib/promscrape/client.go +++ b/lib/promscrape/client.go @@ -79,7 +79,7 @@ func concatTwoStrings(x, y string) string { return s } -func newClient(sw *ScrapeWork, ctx context.Context) *client { +func newClient(ctx context.Context, sw *ScrapeWork) *client { var u fasthttp.URI u.Update(sw.ScrapeURL) hostPort := string(u.Host()) diff --git a/lib/promscrape/discovery/nomad/service.go b/lib/promscrape/discovery/nomad/service.go index 41ce4932e..1147308ce 100644 --- a/lib/promscrape/discovery/nomad/service.go +++ b/lib/promscrape/discovery/nomad/service.go @@ -22,6 +22,8 @@ func getServiceLabels(cfg *apiConfig) []*promutils.Labels { return ms } +// ServiceList is a list of Nomad services. +// See https://developer.hashicorp.com/nomad/api-docs/services#list-services type ServiceList struct { Namespace string `json:"Namespace"` Services []struct { diff --git a/lib/promscrape/scraper.go b/lib/promscrape/scraper.go index 8118fe719..cf653776a 100644 --- a/lib/promscrape/scraper.go +++ b/lib/promscrape/scraper.go @@ -442,7 +442,7 @@ func newScraper(sw *ScrapeWork, group string, pushData func(at *auth.Token, wr * cancel: cancel, stoppedCh: make(chan struct{}), } - c := newClient(sw, ctx) + c := newClient(ctx, sw) sc.sw.Config = sw sc.sw.ScrapeGroup = group sc.sw.ReadData = c.ReadData diff --git a/lib/protoparser/common/vmproto_handshake.go b/lib/protoparser/common/vmproto_handshake.go index edc299dc1..a0cf9f00e 100644 --- a/lib/protoparser/common/vmproto_handshake.go +++ b/lib/protoparser/common/vmproto_handshake.go @@ -7,7 +7,7 @@ import ( "strings" ) -// HandleVMProtoClientHashake returns true if the server at remoteWriteURL supports VictoriaMetrics remote write protocol. +// HandleVMProtoClientHandshake returns true if the server at remoteWriteURL supports VictoriaMetrics remote write protocol. func HandleVMProtoClientHandshake(remoteWriteURL string, doRequest func(handshakeURL string) (*http.Response, error)) bool { u := remoteWriteURL if strings.Contains(u, "?") {