mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
.golangci.yml: properly enable revive
linter and fix all the warnings it detects
This commit is contained in:
parent
ffa327d6d1
commit
f7ef80aaad
10 changed files with 30 additions and 22 deletions
|
@ -1,14 +1,18 @@
|
||||||
run:
|
run:
|
||||||
timeout: 2m
|
timeout: 2m
|
||||||
|
|
||||||
enable:
|
linters:
|
||||||
|
enable:
|
||||||
- revive
|
- revive
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
- linters:
|
- linters:
|
||||||
- staticcheck
|
- staticcheck
|
||||||
text: "SA(4003|1019|5011):"
|
text: "SA(4003|1019|5011):"
|
||||||
|
include:
|
||||||
|
- EXC0012
|
||||||
|
- EXC0014
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
errcheck:
|
errcheck:
|
||||||
|
|
|
@ -51,27 +51,27 @@ func main() {
|
||||||
|
|
||||||
if len(*snapshotCreateURL) > 0 {
|
if len(*snapshotCreateURL) > 0 {
|
||||||
// create net/url object
|
// create net/url object
|
||||||
createUrl, err := url.Parse(*snapshotCreateURL)
|
createURL, err := url.Parse(*snapshotCreateURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalf("cannot parse snapshotCreateURL: %s", err)
|
logger.Fatalf("cannot parse snapshotCreateURL: %s", err)
|
||||||
}
|
}
|
||||||
if len(*snapshotName) > 0 {
|
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.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 {
|
if len(*snapshotDeleteURL) <= 0 {
|
||||||
err := flag.Set("snapshot.deleteURL", strings.Replace(*snapshotCreateURL, "/create", "/delete", 1))
|
err := flag.Set("snapshot.deleteURL", strings.Replace(*snapshotCreateURL, "/create", "/delete", 1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalf("Failed to set snapshot.deleteURL flag: %v", err)
|
logger.Fatalf("Failed to set snapshot.deleteURL flag: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deleteUrl, err := url.Parse(*snapshotDeleteURL)
|
deleteURL, err := url.Parse(*snapshotDeleteURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalf("cannot parse snapshotDeleteURL: %s", err)
|
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 {
|
if err != nil {
|
||||||
logger.Fatalf("cannot create snapshot: %s", err)
|
logger.Fatalf("cannot create snapshot: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
err := snapshot.Delete(deleteUrl.String(), name)
|
err := snapshot.Delete(deleteURL.String(), name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatalf("cannot delete snapshot: %s", err)
|
logger.Fatalf("cannot delete snapshot: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ const (
|
||||||
// retryableFunc describes call back which will repeat on errors
|
// retryableFunc describes call back which will repeat on errors
|
||||||
type retryableFunc func() error
|
type retryableFunc func() error
|
||||||
|
|
||||||
|
// ErrBadRequest is an error returned on bad request
|
||||||
var ErrBadRequest = errors.New("bad request")
|
var ErrBadRequest = errors.New("bad request")
|
||||||
|
|
||||||
// Backoff describes object with backoff policy params
|
// Backoff describes object with backoff policy params
|
||||||
|
|
|
@ -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) {
|
if math.IsNaN(k) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -791,8 +791,8 @@ func getIntK(k float64, kMax int) int {
|
||||||
if kn < 0 {
|
if kn < 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if kn > kMax {
|
if kn > max {
|
||||||
return kMax
|
return max
|
||||||
}
|
}
|
||||||
return kn
|
return kn
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,10 +84,10 @@ func signRequestWithTime(req *http.Request, service, region, payloadHash string,
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSignatureKey(key, datestamp, region, service string) string {
|
func getSignatureKey(key, datestamp, region, service string) string {
|
||||||
kDate := hmacBin("AWS4"+key, datestamp)
|
dateKey := hmacBin("AWS4"+key, datestamp)
|
||||||
kRegion := hmacBin(kDate, region)
|
regionKey := hmacBin(dateKey, region)
|
||||||
kService := hmacBin(kRegion, service)
|
serviceKey := hmacBin(regionKey, service)
|
||||||
return hmacBin(kService, "aws4_request")
|
return hmacBin(serviceKey, "aws4_request")
|
||||||
}
|
}
|
||||||
|
|
||||||
func hashHex(s string) string {
|
func hashHex(s string) string {
|
||||||
|
|
|
@ -468,6 +468,7 @@ func isHTTPURL(targetURL string) bool {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsScheduledForRemoval(name string) bool {
|
// IsScheduledForRemoval returns true if the filename contains .must-remove. substring
|
||||||
return strings.Contains(name, ".must-remove.")
|
func IsScheduledForRemoval(filename string) bool {
|
||||||
|
return strings.Contains(filename, ".must-remove.")
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ func concatTwoStrings(x, y string) string {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func newClient(sw *ScrapeWork, ctx context.Context) *client {
|
func newClient(ctx context.Context, sw *ScrapeWork) *client {
|
||||||
var u fasthttp.URI
|
var u fasthttp.URI
|
||||||
u.Update(sw.ScrapeURL)
|
u.Update(sw.ScrapeURL)
|
||||||
hostPort := string(u.Host())
|
hostPort := string(u.Host())
|
||||||
|
|
|
@ -22,6 +22,8 @@ func getServiceLabels(cfg *apiConfig) []*promutils.Labels {
|
||||||
return ms
|
return ms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ServiceList is a list of Nomad services.
|
||||||
|
// See https://developer.hashicorp.com/nomad/api-docs/services#list-services
|
||||||
type ServiceList struct {
|
type ServiceList struct {
|
||||||
Namespace string `json:"Namespace"`
|
Namespace string `json:"Namespace"`
|
||||||
Services []struct {
|
Services []struct {
|
||||||
|
|
|
@ -442,7 +442,7 @@ func newScraper(sw *ScrapeWork, group string, pushData func(at *auth.Token, wr *
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
stoppedCh: make(chan struct{}),
|
stoppedCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
c := newClient(sw, ctx)
|
c := newClient(ctx, sw)
|
||||||
sc.sw.Config = sw
|
sc.sw.Config = sw
|
||||||
sc.sw.ScrapeGroup = group
|
sc.sw.ScrapeGroup = group
|
||||||
sc.sw.ReadData = c.ReadData
|
sc.sw.ReadData = c.ReadData
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"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 {
|
func HandleVMProtoClientHandshake(remoteWriteURL string, doRequest func(handshakeURL string) (*http.Response, error)) bool {
|
||||||
u := remoteWriteURL
|
u := remoteWriteURL
|
||||||
if strings.Contains(u, "?") {
|
if strings.Contains(u, "?") {
|
||||||
|
|
Loading…
Reference in a new issue