mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-05 22:32:20 +01:00
Makefile: enable golangci-lint in make check_all
This commit is contained in:
parent
9cac11db64
commit
786beb8fc8
7
Makefile
7
Makefile
@ -56,10 +56,15 @@ errcheck: install-errcheck
|
|||||||
install-errcheck:
|
install-errcheck:
|
||||||
which errcheck || GO111MODULE=off go get -u github.com/kisielk/errcheck
|
which errcheck || GO111MODULE=off go get -u github.com/kisielk/errcheck
|
||||||
|
|
||||||
|
check_all: fmt vet lint errcheck golangci-lint
|
||||||
|
|
||||||
test:
|
test:
|
||||||
GO111MODULE=on go test -mod=vendor ./lib/...
|
GO111MODULE=on go test -mod=vendor ./lib/...
|
||||||
GO111MODULE=on go test -mod=vendor ./app/...
|
GO111MODULE=on go test -mod=vendor ./app/...
|
||||||
|
|
||||||
|
test_full:
|
||||||
|
GO111MODULE=on go test -mod=vendor -coverprofile=coverage.txt -covermode=atomic ./lib/... ./app/...
|
||||||
|
|
||||||
benchmark:
|
benchmark:
|
||||||
GO111MODULE=on go test -mod=vendor -bench=. ./lib/...
|
GO111MODULE=on go test -mod=vendor -bench=. ./lib/...
|
||||||
GO111MODULE=on go test -mod=vendor -bench=. ./app/...
|
GO111MODULE=on go test -mod=vendor -bench=. ./app/...
|
||||||
@ -81,7 +86,7 @@ install-qtc:
|
|||||||
|
|
||||||
|
|
||||||
golangci-lint: install-golangci-lint
|
golangci-lint: install-golangci-lint
|
||||||
golangci-lint run
|
golangci-lint run --exclude '(SA4003|SA1019):' -D errcheck
|
||||||
|
|
||||||
install-golangci-lint:
|
install-golangci-lint:
|
||||||
which golangci-lint || GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
|
which golangci-lint || GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
|
||||||
|
41
lib/memory/limiter.go
Normal file
41
lib/memory/limiter.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package memory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Limiter is the memory limiter.
|
||||||
|
//
|
||||||
|
// It limits memory to MaxSize.
|
||||||
|
type Limiter struct {
|
||||||
|
// The maximum allowed memory
|
||||||
|
MaxSize uint64
|
||||||
|
|
||||||
|
mu sync.Mutex
|
||||||
|
usage uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get obtains n bytes of memory from ml.
|
||||||
|
//
|
||||||
|
// It returns true on success, false on error.
|
||||||
|
func (ml *Limiter) Get(n uint64) bool {
|
||||||
|
ml.mu.Lock()
|
||||||
|
ok := n <= ml.MaxSize && ml.MaxSize-n >= ml.usage
|
||||||
|
if ok {
|
||||||
|
ml.usage += n
|
||||||
|
}
|
||||||
|
ml.mu.Unlock()
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put returns back n bytes of memory to ml.
|
||||||
|
func (ml *Limiter) Put(n uint64) {
|
||||||
|
ml.mu.Lock()
|
||||||
|
if n > ml.usage {
|
||||||
|
logger.Panicf("BUG: n=%d cannot exceed %d", n, ml.usage)
|
||||||
|
}
|
||||||
|
ml.usage -= n
|
||||||
|
ml.mu.Unlock()
|
||||||
|
}
|
56
lib/memory/limiter_test.go
Normal file
56
lib/memory/limiter_test.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package memory
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLimiter(t *testing.T) {
|
||||||
|
var ml Limiter
|
||||||
|
ml.MaxSize = 100
|
||||||
|
|
||||||
|
// Allocate memory
|
||||||
|
if !ml.Get(10) {
|
||||||
|
t.Fatalf("cannot get 10 out of %d bytes", ml.MaxSize)
|
||||||
|
}
|
||||||
|
if ml.usage != 10 {
|
||||||
|
t.Fatalf("unexpected usage; got %d; want %d", ml.usage, 10)
|
||||||
|
}
|
||||||
|
if !ml.Get(20) {
|
||||||
|
t.Fatalf("cannot get 20 out of 90 bytes")
|
||||||
|
}
|
||||||
|
if ml.usage != 30 {
|
||||||
|
t.Fatalf("unexpected usage; got %d; want %d", ml.usage, 30)
|
||||||
|
}
|
||||||
|
if ml.Get(1000) {
|
||||||
|
t.Fatalf("unexpected get for 1000 bytes")
|
||||||
|
}
|
||||||
|
if ml.usage != 30 {
|
||||||
|
t.Fatalf("unexpected usage; got %d; want %d", ml.usage, 30)
|
||||||
|
}
|
||||||
|
if ml.Get(71) {
|
||||||
|
t.Fatalf("unexpected get for 71 bytes")
|
||||||
|
}
|
||||||
|
if ml.usage != 30 {
|
||||||
|
t.Fatalf("unexpected usage; got %d; want %d", ml.usage, 30)
|
||||||
|
}
|
||||||
|
if !ml.Get(70) {
|
||||||
|
t.Fatalf("cannot get 70 bytes")
|
||||||
|
}
|
||||||
|
if ml.usage != 100 {
|
||||||
|
t.Fatalf("unexpected usage; got %d; want %d", ml.usage, 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return memory back
|
||||||
|
ml.Put(10)
|
||||||
|
ml.Put(70)
|
||||||
|
if ml.usage != 20 {
|
||||||
|
t.Fatalf("unexpected usage; got %d; want %d", ml.usage, 20)
|
||||||
|
}
|
||||||
|
if !ml.Get(30) {
|
||||||
|
t.Fatalf("cannot get 30 bytes")
|
||||||
|
}
|
||||||
|
ml.Put(50)
|
||||||
|
if ml.usage != 0 {
|
||||||
|
t.Fatalf("unexpected usage; got %d; want %d", ml.usage, 0)
|
||||||
|
}
|
||||||
|
}
|
@ -38,7 +38,7 @@ func TestSearchQueryMarshalUnmarshal(t *testing.T) {
|
|||||||
if len(tail) > 0 {
|
if len(tail) > 0 {
|
||||||
t.Fatalf("unexpected tail left after SearchQuery unmarshaling; tail (len=%d): %q", len(tail), tail)
|
t.Fatalf("unexpected tail left after SearchQuery unmarshaling; tail (len=%d): %q", len(tail), tail)
|
||||||
}
|
}
|
||||||
if sq1.AccountID != sq1.AccountID {
|
if sq2.AccountID != sq1.AccountID {
|
||||||
t.Fatalf("unexpected AccountID; got %d; want %d", sq2.AccountID, sq1.AccountID)
|
t.Fatalf("unexpected AccountID; got %d; want %d", sq2.AccountID, sq1.AccountID)
|
||||||
}
|
}
|
||||||
if sq2.ProjectID != sq1.ProjectID {
|
if sq2.ProjectID != sq1.ProjectID {
|
||||||
|
Loading…
Reference in New Issue
Block a user