diff options
author | James Fargher <proglottis@gmail.com> | 2023-05-23 04:52:19 +0300 |
---|---|---|
committer | James Fargher <proglottis@gmail.com> | 2023-05-23 04:52:19 +0300 |
commit | f3bb073e6abd5b9ae591e1d83aeb40ffee3fc638 (patch) | |
tree | 79740db6e3c345056d95040a342b08298a050ab4 | |
parent | bce5c74f4db69569fb197e7affe39ed54c6f7f5b (diff) | |
parent | 0978425094baf2d0f2c515da3446de6ff127f480 (diff) |
Merge branch 'pks-go-update-cgroups-to-v3' into 'master'
go.mod: Update cgroups dependency to major version 3
See merge request https://gitlab.com/gitlab-org/gitaly/-/merge_requests/5822
Merged-by: James Fargher <proglottis@gmail.com>
Approved-by: John Cai <jcai@gitlab.com>
Approved-by: James Fargher <proglottis@gmail.com>
Co-authored-by: Patrick Steinhardt <psteinhardt@gitlab.com>
-rw-r--r-- | NOTICE | 2 | ||||
-rw-r--r-- | go.mod | 2 | ||||
-rw-r--r-- | go.sum | 4 | ||||
-rw-r--r-- | internal/cgroups/mock_linux_test.go | 6 | ||||
-rw-r--r-- | internal/cgroups/v1_linux.go | 44 |
5 files changed, 32 insertions, 26 deletions
@@ -6623,7 +6623,7 @@ Redistribution and use in source and binary forms, with or without modification, THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -LICENSE - github.com/containerd/cgroups +LICENSE - github.com/containerd/cgroups/v3 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -9,7 +9,7 @@ require ( github.com/ProtonMail/go-crypto v0.0.0-20230518184743-7afd39499903 github.com/beevik/ntp v0.3.2 github.com/cloudflare/tableflip v1.2.3 - github.com/containerd/cgroups v1.1.0 + github.com/containerd/cgroups/v3 v3.0.1 github.com/dgraph-io/badger/v3 v3.2103.5 github.com/getsentry/sentry-go v0.20.0 github.com/git-lfs/git-lfs/v3 v3.3.0 @@ -728,8 +728,8 @@ github.com/containerd/cgroups v0.0.0-20200824123100-0b889c03f102/go.mod h1:s5q4S github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68/go.mod h1:ZJeTFisyysqgcCdecO57Dj79RfL0LNeGiFUqLYQRYLE= github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU= github.com/containerd/cgroups v1.0.3/go.mod h1:/ofk34relqNjSGyqPrmEULrO4Sc8LJhvJmWbUCUKqj8= -github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= -github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= +github.com/containerd/cgroups/v3 v3.0.1 h1:4hfGvu8rfGIwVIDd+nLzn/B9ZXx4BcCjzt5ToenJRaE= +github.com/containerd/cgroups/v3 v3.0.1/go.mod h1:/vtwk1VXrtoa5AaZLkypuOJgA/6DyPMZHJPGQNtlHnw= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/console v0.0.0-20191206165004-02ecf6a7291e/go.mod h1:8Pf4gM6VEbTNRIT26AyyU7hxdQU3MvAvxVI0sc00XBE= diff --git a/internal/cgroups/mock_linux_test.go b/internal/cgroups/mock_linux_test.go index 9b3670af6..2cf735149 100644 --- a/internal/cgroups/mock_linux_test.go +++ b/internal/cgroups/mock_linux_test.go @@ -25,7 +25,7 @@ import ( "strconv" "testing" - "github.com/containerd/cgroups" + "github.com/containerd/cgroups/v3/cgroup1" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v16/internal/helper/perm" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" @@ -33,7 +33,7 @@ import ( type mockCgroup struct { root string - subsystems []cgroups.Subsystem + subsystems []cgroup1.Subsystem } func newMock(t *testing.T) *mockCgroup { @@ -54,7 +54,7 @@ func newMock(t *testing.T) *mockCgroup { } } -func (m *mockCgroup) hierarchy() ([]cgroups.Subsystem, error) { +func (m *mockCgroup) hierarchy() ([]cgroup1.Subsystem, error) { return m.subsystems, nil } diff --git a/internal/cgroups/v1_linux.go b/internal/cgroups/v1_linux.go index 70e0441e4..09bf23619 100644 --- a/internal/cgroups/v1_linux.go +++ b/internal/cgroups/v1_linux.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/containerd/cgroups" + "github.com/containerd/cgroups/v3/cgroup1" specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/prometheus/client_golang/prometheus" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config" @@ -22,7 +22,7 @@ const cfsPeriodUs uint64 = 100000 // CGroupV1Manager is the manager for cgroups v1 type CGroupV1Manager struct { cfg cgroupscfg.Config - hierarchy func() ([]cgroups.Subsystem, error) + hierarchy func() ([]cgroup1.Subsystem, error) memoryReclaimAttemptsTotal *prometheus.GaugeVec cpuUsage *prometheus.GaugeVec cpuCFSPeriods *prometheus.Desc @@ -36,7 +36,7 @@ func newV1Manager(cfg cgroupscfg.Config, pid int) *CGroupV1Manager { return &CGroupV1Manager{ cfg: cfg, pid: pid, - hierarchy: func() ([]cgroups.Subsystem, error) { + hierarchy: func() ([]cgroup1.Subsystem, error) { return defaultSubsystems(cfg.Mountpoint) }, memoryReclaimAttemptsTotal: prometheus.NewGaugeVec( @@ -99,10 +99,10 @@ func (cg *CGroupV1Manager) Setup() error { parentResources.Memory = &specs.LinuxMemory{Limit: &cg.cfg.MemoryBytes} } - if _, err := cgroups.New( - cg.hierarchy, - cgroups.StaticPath(cg.currentProcessCgroup()), + if _, err := cgroup1.New( + cgroup1.StaticPath(cg.currentProcessCgroup()), &parentResources, + cgroup1.WithHiearchy(cg.hierarchy), ); err != nil { return fmt.Errorf("failed creating parent cgroup: %w", err) } @@ -125,10 +125,10 @@ func (cg *CGroupV1Manager) Setup() error { } for i := 0; i < int(cg.cfg.Repositories.Count); i++ { - if _, err := cgroups.New( - cg.hierarchy, - cgroups.StaticPath(cg.repoPath(i)), + if _, err := cgroup1.New( + cgroup1.StaticPath(cg.repoPath(i)), &reposResources, + cgroup1.WithHiearchy(cg.hierarchy), ); err != nil { return fmt.Errorf("failed creating repository cgroup: %w", err) } @@ -169,12 +169,15 @@ func (cg *CGroupV1Manager) AddCommand( } func (cg *CGroupV1Manager) addToCgroup(pid int, cgroupPath string) error { - control, err := cgroups.Load(cg.hierarchy, cgroups.StaticPath(cgroupPath)) + control, err := cgroup1.Load( + cgroup1.StaticPath(cgroupPath), + cgroup1.WithHiearchy(cg.hierarchy), + ) if err != nil { return fmt.Errorf("failed loading %s cgroup: %w", cgroupPath, err) } - if err := control.Add(cgroups.Process{Pid: pid}); err != nil { + if err := control.Add(cgroup1.Process{Pid: pid}); err != nil { // Command could finish so quickly before we can add it to a cgroup, so // we don't consider it an error. if strings.Contains(err.Error(), "no such process") { @@ -195,9 +198,9 @@ func (cg *CGroupV1Manager) Collect(ch chan<- prometheus.Metric) { for i := 0; i < int(cg.cfg.Repositories.Count); i++ { repoPath := cg.repoPath(i) logger := log.Default().WithField("cgroup_path", repoPath) - control, err := cgroups.Load( - cg.hierarchy, - cgroups.StaticPath(repoPath), + control, err := cgroup1.Load( + cgroup1.StaticPath(repoPath), + cgroup1.WithHiearchy(cg.hierarchy), ) if err != nil { logger.WithError(err).Warn("unable to load cgroup controller") @@ -270,7 +273,10 @@ func (cg *CGroupV1Manager) Describe(ch chan<- *prometheus.Desc) { func (cg *CGroupV1Manager) Cleanup() error { processCgroupPath := cg.currentProcessCgroup() - control, err := cgroups.Load(cg.hierarchy, cgroups.StaticPath(processCgroupPath)) + control, err := cgroup1.Load( + cgroup1.StaticPath(processCgroupPath), + cgroup1.WithHiearchy(cg.hierarchy), + ) if err != nil { return fmt.Errorf("failed loading cgroup %s: %w", processCgroupPath, err) } @@ -290,10 +296,10 @@ func (cg *CGroupV1Manager) currentProcessCgroup() string { return config.GetGitalyProcessTempDir(cg.cfg.HierarchyRoot, cg.pid) } -func defaultSubsystems(root string) ([]cgroups.Subsystem, error) { - subsystems := []cgroups.Subsystem{ - cgroups.NewMemory(root, cgroups.OptionalSwap()), - cgroups.NewCpu(root), +func defaultSubsystems(root string) ([]cgroup1.Subsystem, error) { + subsystems := []cgroup1.Subsystem{ + cgroup1.NewMemory(root, cgroup1.OptionalSwap()), + cgroup1.NewCpu(root), } return subsystems, nil |