From 62611443ec007e9e3ff72e35fe6236d7b738b699 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 4 Dec 2023 13:35:26 +0000 Subject: [PATCH] Move heap ballast util function to dskit So it can be shared by other programs. --- cmd/mimir/main.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- pkg/util/ballast_test.go | 24 ------------------- .../grafana/dskit/ballast}/ballast.go | 7 +++--- vendor/modules.txt | 3 ++- 6 files changed, 10 insertions(+), 34 deletions(-) delete mode 100644 pkg/util/ballast_test.go rename {pkg/util => vendor/github.com/grafana/dskit/ballast}/ballast.go (73%) diff --git a/cmd/mimir/main.go b/cmd/mimir/main.go index da21d2864d7..909fbacb5d8 100644 --- a/cmd/mimir/main.go +++ b/cmd/mimir/main.go @@ -17,6 +17,7 @@ import ( "strings" "github.com/go-kit/log/level" + "github.com/grafana/dskit/ballast" "github.com/grafana/dskit/flagext" "github.com/grafana/dskit/tracing" "github.com/pkg/errors" @@ -24,7 +25,6 @@ import ( "gopkg.in/yaml.v3" "github.com/grafana/mimir/pkg/mimir" - "github.com/grafana/mimir/pkg/util" util_log "github.com/grafana/mimir/pkg/util/log" "github.com/grafana/mimir/pkg/util/usage" "github.com/grafana/mimir/pkg/util/version" @@ -179,7 +179,7 @@ func main() { Registry: reg, }) - var ballast = util.AllocateBallast(mainFlags.ballastBytes) + var ballast = ballast.Allocate(mainFlags.ballastBytes) // In testing mode skip JAEGER setup to avoid panic due to // "duplicate metrics collector registration attempted" diff --git a/go.mod b/go.mod index e770fdb0484..4bf46daca52 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/golang/snappy v0.0.4 github.com/google/gopacket v1.1.19 github.com/gorilla/mux v1.8.1 - github.com/grafana/dskit v0.0.0-20231126215014-4cfd2dc0d14c + github.com/grafana/dskit v0.0.0-20231204113943-3040f31404f8 github.com/grafana/e2e v0.1.1 github.com/hashicorp/golang-lru v1.0.2 // indirect github.com/json-iterator/go v1.1.12 diff --git a/go.sum b/go.sum index 252213691e5..bf6732f001b 100644 --- a/go.sum +++ b/go.sum @@ -541,8 +541,8 @@ github.com/gosimple/slug v1.1.1 h1:fRu/digW+NMwBIP+RmviTK97Ho/bEj/C9swrCspN3D4= github.com/gosimple/slug v1.1.1/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0= github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc h1:PXZQA2WCxe85Tnn+WEvr8fDpfwibmEPgfgFEaC87G24= github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc/go.mod h1:AHHlOEv1+GGQ3ktHMlhuTUwo3zljV3QJbC0+8o2kn+4= -github.com/grafana/dskit v0.0.0-20231126215014-4cfd2dc0d14c h1:VzcctxlNlf/NmB/ZsX+dvcIZiEVm1xDZO+eCBhOSnSg= -github.com/grafana/dskit v0.0.0-20231126215014-4cfd2dc0d14c/go.mod h1:8dsy5tQOkeNQyjXpm5mQsbCu3H5uzeBD35MzRQFznKU= +github.com/grafana/dskit v0.0.0-20231204113943-3040f31404f8 h1:bRYRUeFr1UiJJsS2XFezQCr6i5DlCRwWaMPb272ZTqQ= +github.com/grafana/dskit v0.0.0-20231204113943-3040f31404f8/go.mod h1:8dsy5tQOkeNQyjXpm5mQsbCu3H5uzeBD35MzRQFznKU= github.com/grafana/e2e v0.1.1 h1:/b6xcv5BtoBnx8cZnCiey9DbjEc8z7gXHO5edoeRYxc= github.com/grafana/e2e v0.1.1/go.mod h1:RpNLgae5VT+BUHvPE+/zSypmOXKwEu4t+tnEMS1ATaE= github.com/grafana/goautoneg v0.0.0-20231010094147-47ce5e72a9ae h1:Yxbw9jKGJVC6qAK5Ubzzb/qZwM6rRMMqaDc/d4Vp3pM= diff --git a/pkg/util/ballast_test.go b/pkg/util/ballast_test.go deleted file mode 100644 index 9e48c434043..00000000000 --- a/pkg/util/ballast_test.go +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: AGPL-3.0-only -package util - -import ( - "testing" - - "github.com/stretchr/testify/require" -) - -func TestAllocateBallast(t *testing.T) { - require.Nil(t, AllocateBallast(0)) - - for i := 1; i < 20; i++ { - size := i * 1024 * 1024 - - b := AllocateBallast(size).([][]byte) - - totalSize := 0 - for _, bs := range b { - totalSize += len(bs) - } - require.Equal(t, size, totalSize) - } -} diff --git a/pkg/util/ballast.go b/vendor/github.com/grafana/dskit/ballast/ballast.go similarity index 73% rename from pkg/util/ballast.go rename to vendor/github.com/grafana/dskit/ballast/ballast.go index 3ec0debe05d..41867e1f4eb 100644 --- a/pkg/util/ballast.go +++ b/vendor/github.com/grafana/dskit/ballast/ballast.go @@ -1,11 +1,10 @@ -// SPDX-License-Identifier: AGPL-3.0-only -package util +package ballast -// AllocateBallast allocates ballast of given size, to alter GC behaviour. See https://github.com/golang/go/issues/23044 +// Allocate allocates ballast of given size, to alter GC behaviour. See https://github.com/golang/go/issues/23044 // Instead of allocating one big slice, we allocate many small ones to avoid keeping too much data in memory when Go runtime // decides that it needs to zero the slice. // Returned value should not be used. -func AllocateBallast(ballastSize int) any { +func Allocate(ballastSize int) any { if ballastSize <= 0 { return nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index 75acfe32f13..13a9aa7f043 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -534,9 +534,10 @@ github.com/gosimple/slug # github.com/grafana-tools/sdk v0.0.0-20220919052116-6562121319fc ## explicit; go 1.13 github.com/grafana-tools/sdk -# github.com/grafana/dskit v0.0.0-20231126215014-4cfd2dc0d14c +# github.com/grafana/dskit v0.0.0-20231204113943-3040f31404f8 ## explicit; go 1.20 github.com/grafana/dskit/backoff +github.com/grafana/dskit/ballast github.com/grafana/dskit/cache github.com/grafana/dskit/concurrency github.com/grafana/dskit/crypto/tls