Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2022-05-18 03:16:03 +0300
committerJohn Cai <jcai@gitlab.com>2022-05-18 03:16:03 +0300
commit8c752c30029762e08e791516c6cb9bc35c2a130f (patch)
treeed394590b3c727be3c1731a43a103966e89c8400
parent9d6e877727a092094c2900a5db7ddae1a9969904 (diff)
Revert "Merge branch 'jc-cgroups-repository-isolation' into 'master'"jc-revert-repository-isolation
This reverts commit 5452f5693f9d87ec217ea943e6de77ca045a73b3, reversing changes made to c559ccf807030ea0e35db7c579fc88603ccfc5fa.
-rw-r--r--internal/cgroups/cgroups.go6
-rw-r--r--internal/cgroups/cgroups_linux_test.go2
-rw-r--r--internal/cgroups/mock_linux_test.go5
-rw-r--r--internal/cgroups/noop.go3
-rw-r--r--internal/cgroups/v1_linux.go148
-rw-r--r--internal/cgroups/v1_linux_test.go76
-rw-r--r--internal/git/command_factory.go2
-rw-r--r--internal/git/command_factory_cgroup_test.go7
-rw-r--r--internal/gitaly/config/cgroups/cgroups.go16
-rw-r--r--internal/gitaly/config/cgroups/cgroups_test.go150
-rw-r--r--internal/gitaly/config/config.go2
-rw-r--r--internal/gitaly/config/config_test.go44
12 files changed, 125 insertions, 336 deletions
diff --git a/internal/cgroups/cgroups.go b/internal/cgroups/cgroups.go
index 55e603de9..dc0cf0066 100644
--- a/internal/cgroups/cgroups.go
+++ b/internal/cgroups/cgroups.go
@@ -3,7 +3,6 @@ package cgroups
import (
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitaly/v14/internal/command"
- "gitlab.com/gitlab-org/gitaly/v14/internal/git/repository"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config/cgroups"
)
@@ -14,7 +13,7 @@ type Manager interface {
// instance of the Manager.
Setup() error
// AddCommand adds a Command to a cgroup
- AddCommand(*command.Command, repository.GitRepo) error
+ AddCommand(*command.Command) error
// Cleanup cleans up cgroups created in Setup.
// It is expected to be called once at Gitaly shutdown from any
// instance of the Manager.
@@ -25,7 +24,8 @@ type Manager interface {
// NewManager returns the appropriate Cgroups manager
func NewManager(cfg cgroups.Config) Manager {
- if cfg.Repositories.Count > 0 {
+ // nolint:staticcheck // we will deprecate the old cgroups config in 15.0
+ if cfg.Count > 0 {
return newV1Manager(cfg)
}
diff --git a/internal/cgroups/cgroups_linux_test.go b/internal/cgroups/cgroups_linux_test.go
index 29246cd76..9d8267bff 100644
--- a/internal/cgroups/cgroups_linux_test.go
+++ b/internal/cgroups/cgroups_linux_test.go
@@ -13,7 +13,7 @@ func TestMain(m *testing.M) {
}
func TestNewManager(t *testing.T) {
- cfg := cgroups.Config{Repositories: cgroups.Repositories{Count: 10}}
+ cfg := cgroups.Config{Count: 10}
require.IsType(t, &CGroupV1Manager{}, &CGroupV1Manager{cfg: cfg})
require.IsType(t, &NoopManager{}, NewManager(cgroups.Config{}))
diff --git a/internal/cgroups/mock_linux_test.go b/internal/cgroups/mock_linux_test.go
index b941bda23..620ea06d5 100644
--- a/internal/cgroups/mock_linux_test.go
+++ b/internal/cgroups/mock_linux_test.go
@@ -103,8 +103,9 @@ func (m *mockCgroup) setupMockCgroupFiles(
require.NoError(t, os.WriteFile(controlFilePath, []byte(content), 0o644))
}
- for shard := uint(0); shard < manager.cfg.Repositories.Count; shard++ {
- shardPath := filepath.Join(cgroupPath, fmt.Sprintf("repos-%d", shard))
+ // nolint:staticcheck // we will deprecate the old cgroups config in 15.0
+ for shard := uint(0); shard < manager.cfg.Count; shard++ {
+ shardPath := filepath.Join(cgroupPath, fmt.Sprintf("shard-%d", shard))
require.NoError(t, os.MkdirAll(shardPath, 0o755))
for filename, content := range contentByFilename {
diff --git a/internal/cgroups/noop.go b/internal/cgroups/noop.go
index ff4ca2e49..57f552902 100644
--- a/internal/cgroups/noop.go
+++ b/internal/cgroups/noop.go
@@ -3,7 +3,6 @@ package cgroups
import (
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitaly/v14/internal/command"
- "gitlab.com/gitlab-org/gitaly/v14/internal/git/repository"
)
// NoopManager is a cgroups manager that does nothing
@@ -15,7 +14,7 @@ func (cg *NoopManager) Setup() error {
}
//nolint: revive,stylecheck // This is unintentionally missing documentation.
-func (cg *NoopManager) AddCommand(cmd *command.Command, repo repository.GitRepo) error {
+func (cg *NoopManager) AddCommand(cmd *command.Command) error {
return nil
}
diff --git a/internal/cgroups/v1_linux.go b/internal/cgroups/v1_linux.go
index 49802bcb8..75573e96a 100644
--- a/internal/cgroups/v1_linux.go
+++ b/internal/cgroups/v1_linux.go
@@ -10,7 +10,6 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitaly/v14/internal/command"
- "gitlab.com/gitlab-org/gitaly/v14/internal/git/repository"
cgroupscfg "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config/cgroups"
"gitlab.com/gitlab-org/gitaly/v14/internal/log"
)
@@ -55,41 +54,25 @@ func newV1Manager(cfg cgroupscfg.Config) *CGroupV1Manager {
//nolint: revive,stylecheck // This is unintentionally missing documentation.
func (cg *CGroupV1Manager) Setup() error {
- var parentResources specs.LinuxResources
+ resources := &specs.LinuxResources{}
- if cg.cfg.CPUShares > 0 {
- parentResources.CPU = &specs.LinuxCPU{Shares: &cg.cfg.CPUShares}
- }
-
- if cg.cfg.MemoryBytes > 0 {
- parentResources.Memory = &specs.LinuxMemory{Limit: &cg.cfg.MemoryBytes}
- }
-
- if _, err := cgroups.New(
- cg.hierarchy,
- cgroups.StaticPath(cg.currentProcessCgroup()),
- &parentResources,
- ); err != nil {
- return fmt.Errorf("failed creating parent cgroup: %w", err)
- }
-
- var reposResources specs.LinuxResources
-
- if cg.cfg.Repositories.CPUShares > 0 {
- reposResources.CPU = &specs.LinuxCPU{Shares: &cg.cfg.Repositories.CPUShares}
+ if cg.cfg.CPU.Enabled {
+ resources.CPU = &specs.LinuxCPU{
+ Shares: &cg.cfg.CPU.Shares,
+ }
}
- if cg.cfg.Repositories.MemoryBytes > 0 {
- reposResources.Memory = &specs.LinuxMemory{Limit: &cg.cfg.Repositories.MemoryBytes}
+ if cg.cfg.Memory.Enabled {
+ resources.Memory = &specs.LinuxMemory{
+ Limit: &cg.cfg.Memory.Limit,
+ }
}
- for i := 0; i < int(cg.cfg.Repositories.Count); i++ {
- if _, err := cgroups.New(
- cg.hierarchy,
- cgroups.StaticPath(cg.repoPath(i)),
- &reposResources,
- ); err != nil {
- return fmt.Errorf("failed creating repository cgroup: %w", err)
+ // nolint:staticcheck // we will deprecate the old cgroups config in 15.0
+ for i := 0; i < int(cg.cfg.Count); i++ {
+ _, err := cgroups.New(cg.hierarchy, cgroups.StaticPath(cg.cgroupPath(i)), resources)
+ if err != nil {
+ return fmt.Errorf("failed creating cgroup: %w", err)
}
}
@@ -97,30 +80,20 @@ func (cg *CGroupV1Manager) Setup() error {
}
// AddCommand adds the given command to one of the CGroup's buckets. The bucket used for the command
-// is determined by hashing the repository storage and path. No error is returned if the command has already
+// is determined by hashing the commands arguments. No error is returned if the command has already
// exited.
-func (cg *CGroupV1Manager) AddCommand(
- cmd *command.Command,
- repo repository.GitRepo,
-) error {
- checksum := crc32.ChecksumIEEE(
- []byte(repo.GetStorageName() + "/" + repo.GetRelativePath()),
- )
- groupID := uint(checksum) % cg.cfg.Repositories.Count
- cgroupPath := cg.repoPath(int(groupID))
-
- cmd.SetCgroupPath(cgroupPath)
+func (cg *CGroupV1Manager) AddCommand(cmd *command.Command) error {
+ checksum := crc32.ChecksumIEEE([]byte(strings.Join(cmd.Args(), "")))
+ // nolint:staticcheck // we will deprecate the old cgroups config in 15.0
+ groupID := uint(checksum) % cg.cfg.Count
+ cgroupPath := cg.cgroupPath(int(groupID))
- return cg.addToCgroup(cmd.Pid(), cgroupPath)
-}
-
-func (cg *CGroupV1Manager) addToCgroup(pid int, cgroupPath string) error {
control, err := cgroups.Load(cg.hierarchy, cgroups.StaticPath(cgroupPath))
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(cgroups.Process{Pid: cmd.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") {
@@ -129,55 +102,52 @@ func (cg *CGroupV1Manager) addToCgroup(pid int, cgroupPath string) error {
return fmt.Errorf("failed adding process to cgroup: %w", err)
}
+ cmd.SetCgroupPath(cgroupPath)
+
return nil
}
// Collect collects metrics from the cgroups controller
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),
- )
- if err != nil {
- logger.WithError(err).Warn("unable to load cgroup controller")
- return
- }
+ path := cg.currentProcessCgroup()
+ logger := log.Default().WithField("cgroup_path", path)
+ control, err := cgroups.Load(cg.hierarchy, cgroups.StaticPath(path))
+ if err != nil {
+ logger.WithError(err).Warn("unable to load cgroup controller")
+ return
+ }
- if metrics, err := control.Stat(); err != nil {
- logger.WithError(err).Warn("unable to get cgroup stats")
- } else {
- memoryMetric := cg.memoryFailedTotal.WithLabelValues(repoPath)
- memoryMetric.Set(float64(metrics.Memory.Usage.Failcnt))
- ch <- memoryMetric
+ if metrics, err := control.Stat(); err != nil {
+ logger.WithError(err).Warn("unable to get cgroup stats")
+ } else {
+ memoryMetric := cg.memoryFailedTotal.WithLabelValues(path)
+ memoryMetric.Set(float64(metrics.Memory.Usage.Failcnt))
+ ch <- memoryMetric
- cpuUserMetric := cg.cpuUsage.WithLabelValues(repoPath, "user")
- cpuUserMetric.Set(float64(metrics.CPU.Usage.User))
- ch <- cpuUserMetric
+ cpuUserMetric := cg.cpuUsage.WithLabelValues(path, "user")
+ cpuUserMetric.Set(float64(metrics.CPU.Usage.User))
+ ch <- cpuUserMetric
- cpuKernelMetric := cg.cpuUsage.WithLabelValues(repoPath, "kernel")
- cpuKernelMetric.Set(float64(metrics.CPU.Usage.Kernel))
- ch <- cpuKernelMetric
- }
+ cpuKernelMetric := cg.cpuUsage.WithLabelValues(path, "kernel")
+ cpuKernelMetric.Set(float64(metrics.CPU.Usage.Kernel))
+ ch <- cpuKernelMetric
+ }
- if subsystems, err := cg.hierarchy(); err != nil {
- logger.WithError(err).Warn("unable to get cgroup hierarchy")
- } else {
- for _, subsystem := range subsystems {
- processes, err := control.Processes(subsystem.Name(), true)
- if err != nil {
- logger.WithField("subsystem", subsystem.Name()).
- WithError(err).
- Warn("unable to get process list")
- continue
- }
-
- procsMetric := cg.procs.WithLabelValues(repoPath, string(subsystem.Name()))
- procsMetric.Set(float64(len(processes)))
- ch <- procsMetric
+ if subsystems, err := cg.hierarchy(); err != nil {
+ logger.WithError(err).Warn("unable to get cgroup hierarchy")
+ } else {
+ for _, subsystem := range subsystems {
+ processes, err := control.Processes(subsystem.Name(), true)
+ if err != nil {
+ logger.WithField("subsystem", subsystem.Name()).
+ WithError(err).
+ Warn("unable to get process list")
+ continue
}
+
+ procsMetric := cg.procs.WithLabelValues(path, string(subsystem.Name()))
+ procsMetric.Set(float64(len(processes)))
+ ch <- procsMetric
}
}
}
@@ -203,8 +173,8 @@ func (cg *CGroupV1Manager) Cleanup() error {
return nil
}
-func (cg *CGroupV1Manager) repoPath(groupID int) string {
- return fmt.Sprintf("%s/repos-%d", cg.currentProcessCgroup(), groupID)
+func (cg *CGroupV1Manager) cgroupPath(groupID int) string {
+ return fmt.Sprintf("/%s/shard-%d", cg.currentProcessCgroup(), groupID)
}
func (cg *CGroupV1Manager) currentProcessCgroup() string {
diff --git a/internal/cgroups/v1_linux_test.go b/internal/cgroups/v1_linux_test.go
index 347973374..7de3d910d 100644
--- a/internal/cgroups/v1_linux_test.go
+++ b/internal/cgroups/v1_linux_test.go
@@ -20,16 +20,19 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/internal/command"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config/cgroups"
"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
- "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
)
func defaultCgroupsConfig() cgroups.Config {
return cgroups.Config{
+ Count: 3,
HierarchyRoot: "gitaly",
- Repositories: cgroups.Repositories{
- Count: 3,
- MemoryBytes: 1024000,
- CPUShares: 256,
+ CPU: cgroups.CPU{
+ Enabled: true,
+ Shares: 256,
+ },
+ Memory: cgroups.Memory{
+ Enabled: true,
+ Limit: 1024000,
},
}
}
@@ -45,14 +48,14 @@ func TestSetup(t *testing.T) {
for i := 0; i < 3; i++ {
memoryPath := filepath.Join(
- mock.root, "memory", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("repos-%d", i), "memory.limit_in_bytes",
+ mock.root, "memory", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("shard-%d", i), "memory.limit_in_bytes",
)
memoryContent := readCgroupFile(t, memoryPath)
require.Equal(t, string(memoryContent), "1024000")
cpuPath := filepath.Join(
- mock.root, "cpu", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("repos-%d", i), "cpu.shares",
+ mock.root, "cpu", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("shard-%d", i), "cpu.shares",
)
cpuContent := readCgroupFile(t, cpuPath)
@@ -63,16 +66,7 @@ func TestSetup(t *testing.T) {
func TestAddCommand(t *testing.T) {
mock := newMock(t)
- repo := &gitalypb.Repository{
- StorageName: "default",
- RelativePath: "path/to/repo.git",
- }
-
config := defaultCgroupsConfig()
- config.Repositories.Count = 1
- config.Repositories.MemoryBytes = 1024
- config.Repositories.CPUShares = 16
-
v1Manager1 := &CGroupV1Manager{
cfg: config,
hierarchy: mock.hierarchy,
@@ -89,15 +83,14 @@ func TestAddCommand(t *testing.T) {
cfg: config,
hierarchy: mock.hierarchy,
}
+ require.NoError(t, v1Manager2.AddCommand(cmd2))
- require.NoError(t, v1Manager2.AddCommand(cmd2, repo))
-
- checksum := crc32.ChecksumIEEE([]byte(strings.Join([]string{"default", "path/to/repo.git"}, "")))
- groupID := uint(checksum) % config.Repositories.Count
+ checksum := crc32.ChecksumIEEE([]byte(strings.Join(cmd2.Args(), "")))
+ // nolint:staticcheck // we will deprecate the old cgroups config in 15.0
+ groupID := uint(checksum) % config.Count
for _, s := range mock.subsystems {
- path := filepath.Join(mock.root, string(s.Name()), "gitaly",
- fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("repos-%d", groupID), "cgroup.procs")
+ path := filepath.Join(mock.root, string(s.Name()), "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("shard-%d", groupID), "cgroup.procs")
content := readCgroupFile(t, path)
pid, err := strconv.Atoi(string(content))
@@ -118,8 +111,8 @@ func TestCleanup(t *testing.T) {
require.NoError(t, v1Manager.Cleanup())
for i := 0; i < 3; i++ {
- memoryPath := filepath.Join(mock.root, "memory", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("repos-%d", i))
- cpuPath := filepath.Join(mock.root, "cpu", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("repos-%d", i))
+ memoryPath := filepath.Join(mock.root, "memory", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("shard-%d", i))
+ cpuPath := filepath.Join(mock.root, "cpu", "gitaly", fmt.Sprintf("gitaly-%d", os.Getpid()), fmt.Sprintf("shard-%d", i))
require.NoDirExists(t, memoryPath)
require.NoDirExists(t, cpuPath)
@@ -128,16 +121,8 @@ func TestCleanup(t *testing.T) {
func TestMetrics(t *testing.T) {
mock := newMock(t)
- repo := &gitalypb.Repository{
- StorageName: "default",
- RelativePath: "path/to/repo.git",
- }
config := defaultCgroupsConfig()
- config.Repositories.Count = 1
- config.Repositories.MemoryBytes = 1048576
- config.Repositories.CPUShares = 16
-
v1Manager1 := newV1Manager(config)
v1Manager1.hierarchy = mock.hierarchy
@@ -150,20 +135,14 @@ func TestMetrics(t *testing.T) {
logger.SetLevel(logrus.DebugLevel)
ctx = ctxlogrus.ToContext(ctx, logrus.NewEntry(logger))
- cmd, err := command.New(ctx, exec.Command("ls", "-hal", "."), nil, nil, nil)
- require.NoError(t, err)
- gitCmd1, err := command.New(ctx, exec.Command("ls", "-hal", "."), nil, nil, nil)
- require.NoError(t, err)
- gitCmd2, err := command.New(ctx, exec.Command("ls", "-hal", "."), nil, nil, nil)
+ cmd1 := exec.Command("ls", "-hal", ".")
+ cmd2, err := command.New(ctx, cmd1, nil, nil, nil)
require.NoError(t, err)
- require.NoError(t, v1Manager1.AddCommand(cmd, repo))
- require.NoError(t, v1Manager1.AddCommand(gitCmd1, repo))
- require.NoError(t, v1Manager1.AddCommand(gitCmd2, repo))
- require.NoError(t, cmd.Wait())
- require.NoError(t, gitCmd1.Wait())
+ require.NoError(t, v1Manager1.AddCommand(cmd2))
+ require.NoError(t, cmd2.Wait())
- repoCgroupPath := filepath.Join(v1Manager1.currentProcessCgroup(), "repos-0")
+ processCgroupPath := v1Manager1.currentProcessCgroup()
expected := bytes.NewBufferString(fmt.Sprintf(`# HELP gitaly_cgroup_cpu_usage CPU Usage of Cgroup
# TYPE gitaly_cgroup_cpu_usage gauge
@@ -174,18 +153,21 @@ gitaly_cgroup_cpu_usage{path="%s",type="user"} 0
gitaly_cgroup_memory_failed_total{path="%s"} 2
# HELP gitaly_cgroup_procs_total Total number of procs
# TYPE gitaly_cgroup_procs_total gauge
-gitaly_cgroup_procs_total{path="%s",subsystem="cpu"} 1
gitaly_cgroup_procs_total{path="%s",subsystem="memory"} 1
-`, repoCgroupPath, repoCgroupPath, repoCgroupPath, repoCgroupPath, repoCgroupPath))
+gitaly_cgroup_procs_total{path="%s",subsystem="cpu"} 1
+`, processCgroupPath, processCgroupPath, processCgroupPath, processCgroupPath, processCgroupPath))
assert.NoError(t, testutil.CollectAndCompare(
v1Manager1,
- expected))
+ expected,
+ "gitaly_cgroup_memory_failed_total",
+ "gitaly_cgroup_cpu_usage",
+ "gitaly_cgroup_procs_total"))
logEntry := hook.LastEntry()
assert.Contains(
t,
logEntry.Data["command.cgroup_path"],
- repoCgroupPath,
+ processCgroupPath,
"log field includes a cgroup path that is a subdirectory of the current process' cgroup path",
)
}
diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go
index 14f94ade8..f5a07c265 100644
--- a/internal/git/command_factory.go
+++ b/internal/git/command_factory.go
@@ -383,7 +383,7 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.Gi
command.SetMetricsSubCmd(sc.Subcommand())
if featureflag.RunCommandsInCGroup.IsEnabled(ctx) {
- if err := cf.cgroupsManager.AddCommand(command, repo); err != nil {
+ if err := cf.cgroupsManager.AddCommand(command); err != nil {
return nil, err
}
}
diff --git a/internal/git/command_factory_cgroup_test.go b/internal/git/command_factory_cgroup_test.go
index 813961586..922e3d12a 100644
--- a/internal/git/command_factory_cgroup_test.go
+++ b/internal/git/command_factory_cgroup_test.go
@@ -9,7 +9,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/command"
- "gitlab.com/gitlab-org/gitaly/v14/internal/git/repository"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config/cgroups"
"gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag"
@@ -24,7 +23,7 @@ func (m *mockCgroupsManager) Setup() error {
return nil
}
-func (m *mockCgroupsManager) AddCommand(c *command.Command, repo repository.GitRepo) error {
+func (m *mockCgroupsManager) AddCommand(c *command.Command) error {
m.commands = append(m.commands, c)
return nil
}
@@ -42,9 +41,7 @@ func TestNewCommandAddsToCgroup(t *testing.T) {
cfg := config.Cfg{
SocketPath: "/path/to/socket",
Cgroups: cgroups.Config{
- Repositories: cgroups.Repositories{
- Count: 1,
- },
+ Count: 1,
},
Storages: []config.Storage{{
Name: "storage-1",
diff --git a/internal/gitaly/config/cgroups/cgroups.go b/internal/gitaly/config/cgroups/cgroups.go
index 935a1a565..00fb9f45e 100644
--- a/internal/gitaly/config/cgroups/cgroups.go
+++ b/internal/gitaly/config/cgroups/cgroups.go
@@ -22,22 +22,6 @@ type Config struct {
Memory Memory `toml:"memory"`
}
-// FallbackToOldVersion translates the old format of cgroups into the new
-// format.
-func (c *Config) FallbackToOldVersion() {
- if c.Repositories.Count == 0 {
- c.Repositories.Count = c.Count
-
- if c.Repositories.MemoryBytes == 0 && c.Memory.Enabled {
- c.Repositories.MemoryBytes = c.Memory.Limit
- }
-
- if c.Repositories.CPUShares == 0 && c.CPU.Enabled {
- c.Repositories.CPUShares = c.CPU.Shares
- }
- }
-}
-
// Repositories configures cgroups to be created that are isolated by repository.
type Repositories struct {
// Count is the number of cgroups that will be created for repository-level isolation
diff --git a/internal/gitaly/config/cgroups/cgroups_test.go b/internal/gitaly/config/cgroups/cgroups_test.go
deleted file mode 100644
index 8b8bdf8cb..000000000
--- a/internal/gitaly/config/cgroups/cgroups_test.go
+++ /dev/null
@@ -1,150 +0,0 @@
-package cgroups
-
-import (
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestFallbackToOldVersion(t *testing.T) {
- testCases := []struct {
- desc string
- configBefore Config
- configAfter Config
- }{
- {
- desc: "empty config",
- configBefore: Config{},
- configAfter: Config{},
- },
- {
- desc: "new format",
- configBefore: Config{
- Mountpoint: "some/mountpoint",
- HierarchyRoot: "gitaly",
- Repositories: Repositories{
- Count: 100,
- MemoryBytes: 1024,
- CPUShares: 16,
- },
- },
- configAfter: Config{
- Mountpoint: "some/mountpoint",
- HierarchyRoot: "gitaly",
- Repositories: Repositories{
- Count: 100,
- MemoryBytes: 1024,
- CPUShares: 16,
- },
- },
- },
- {
- desc: "old format",
- configBefore: Config{
- Mountpoint: "some/mountpoint",
- HierarchyRoot: "gitaly",
- Count: 100,
- Memory: Memory{
- Enabled: true,
- Limit: 1024,
- },
- CPU: CPU{
- Enabled: true,
- Shares: 16,
- },
- },
- configAfter: Config{
- Mountpoint: "some/mountpoint",
- HierarchyRoot: "gitaly",
- Count: 100,
- Memory: Memory{
- Enabled: true,
- Limit: 1024,
- },
- CPU: CPU{
- Enabled: true,
- Shares: 16,
- },
- Repositories: Repositories{
- Count: 100,
- MemoryBytes: 1024,
- CPUShares: 16,
- },
- },
- },
- {
- desc: "old format, memory only",
- configBefore: Config{
- Mountpoint: "some/mountpoint",
- HierarchyRoot: "gitaly",
- Count: 100,
- Memory: Memory{
- Enabled: true,
- Limit: 1024,
- },
- CPU: CPU{
- Enabled: false,
- Shares: 16,
- },
- },
- configAfter: Config{
- Mountpoint: "some/mountpoint",
- HierarchyRoot: "gitaly",
- Count: 100,
- Memory: Memory{
- Enabled: true,
- Limit: 1024,
- },
- CPU: CPU{
- Enabled: false,
- Shares: 16,
- },
-
- Repositories: Repositories{
- Count: 100,
- MemoryBytes: 1024,
- },
- },
- },
- {
- desc: "old format, cpu only",
- configBefore: Config{
- Mountpoint: "some/mountpoint",
- HierarchyRoot: "gitaly",
- Count: 100,
- Memory: Memory{
- Enabled: false,
- Limit: 1024,
- },
- CPU: CPU{
- Enabled: true,
- Shares: 16,
- },
- },
- configAfter: Config{
- Mountpoint: "some/mountpoint",
- HierarchyRoot: "gitaly",
- Count: 100,
- Memory: Memory{
- Enabled: false,
- Limit: 1024,
- },
- CPU: CPU{
- Enabled: true,
- Shares: 16,
- },
- Repositories: Repositories{
- Count: 100,
- CPUShares: 16,
- },
- },
- },
- }
-
- for _, tc := range testCases {
- t.Run(tc.desc, func(t *testing.T) {
- tc.configBefore.FallbackToOldVersion()
- assert.Equal(t, tc.configAfter, tc.configBefore)
- })
- }
-}
diff --git a/internal/gitaly/config/config.go b/internal/gitaly/config/config.go
index bad2091fc..505a0fb9d 100644
--- a/internal/gitaly/config/config.go
+++ b/internal/gitaly/config/config.go
@@ -291,8 +291,6 @@ func (cfg *Cfg) setDefaults() error {
cfg.Cgroups.HierarchyRoot = "gitaly"
}
- cfg.Cgroups.FallbackToOldVersion()
-
return nil
}
diff --git a/internal/gitaly/config/config_test.go b/internal/gitaly/config/config_test.go
index 2bc299506..bbb348e60 100644
--- a/internal/gitaly/config/config_test.go
+++ b/internal/gitaly/config/config_test.go
@@ -851,11 +851,6 @@ func TestValidateCgroups(t *testing.T) {
Enabled: true,
Shares: 512,
},
- Repositories: cgroups.Repositories{
- Count: 10,
- MemoryBytes: 1024,
- CPUShares: 512,
- },
},
},
{
@@ -869,9 +864,6 @@ func TestValidateCgroups(t *testing.T) {
Count: 10,
Mountpoint: "/sys/fs/cgroup",
HierarchyRoot: "baz",
- Repositories: cgroups.Repositories{
- Count: 10,
- },
},
},
{
@@ -884,9 +876,6 @@ func TestValidateCgroups(t *testing.T) {
Count: 10,
Mountpoint: "/sys/fs/cgroup",
HierarchyRoot: "gitaly",
- Repositories: cgroups.Repositories{
- Count: 10,
- },
},
},
{
@@ -913,10 +902,6 @@ func TestValidateCgroups(t *testing.T) {
Enabled: true,
Shares: 0,
},
- Repositories: cgroups.Repositories{
- Count: 10,
- MemoryBytes: 1024,
- },
},
},
{
@@ -944,9 +929,32 @@ func TestValidateCgroups(t *testing.T) {
Enabled: true,
Shares: 512,
},
- Repositories: cgroups.Repositories{
- Count: 10,
- CPUShares: 512,
+ },
+ },
+ {
+ name: "memory limit - negative",
+ rawCfg: `[cgroups]
+ count = 10
+ mountpoint = "/sys/fs/cgroup"
+ hierarchy_root = "gitaly"
+ [cgroups.memory]
+ enabled = true
+ limit = -5
+ [cgroups.cpu]
+ enabled = true
+ shares = 512
+ `,
+ expect: cgroups.Config{
+ Count: 10,
+ Mountpoint: "/sys/fs/cgroup",
+ HierarchyRoot: "gitaly",
+ Memory: cgroups.Memory{
+ Enabled: true,
+ Limit: -5,
+ },
+ CPU: cgroups.CPU{
+ Enabled: true,
+ Shares: 512,
},
},
},