diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-05-22 16:22:46 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-05-22 16:23:35 +0300 |
commit | 0978425094baf2d0f2c515da3446de6ff127f480 (patch) | |
tree | e7b195c0e0fb469ae1ed97eb6749b1b0a4d90e43 /internal/cgroups | |
parent | 25747c90707aed83e5ca3ebf85fc522a258f1392 (diff) |
go.mod: Update cgroups dependency to major version 3
Update the cgroups dependency to major version 3. This change includes a
bunch of renames where upstream moved the cgroups implementations into
different packages. Adapt our code accordingly.
Diffstat (limited to 'internal/cgroups')
-rw-r--r-- | internal/cgroups/mock_linux_test.go | 6 | ||||
-rw-r--r-- | internal/cgroups/v1_linux.go | 44 |
2 files changed, 28 insertions, 22 deletions
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 |