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-10 22:09:53 +0300
committerJohn Cai <jcai@gitlab.com>2022-05-14 00:27:56 +0300
commit74dd68d43e4a7f66cba80fed2866543427f9ed69 (patch)
tree508aa91f95f708d91f3f90b48114a0fe365ed743
parent60a7383d965aa6a8e69aa2e33a84792cde486cd3 (diff)
cgroups: Add FallbackToOldVersion to support old cgroups config
Once the new configuration rolls out, we need to support old configurations for the time being until 16.0 when we can deprecate the old cgroups config. Until then, allow for a translation layer that translates the old version to the new version.
-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.go27
4 files changed, 168 insertions, 27 deletions
diff --git a/internal/gitaly/config/cgroups/cgroups.go b/internal/gitaly/config/cgroups/cgroups.go
index 00fb9f45e..935a1a565 100644
--- a/internal/gitaly/config/cgroups/cgroups.go
+++ b/internal/gitaly/config/cgroups/cgroups.go
@@ -22,6 +22,22 @@ 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
new file mode 100644
index 000000000..8b8bdf8cb
--- /dev/null
+++ b/internal/gitaly/config/cgroups/cgroups_test.go
@@ -0,0 +1,150 @@
+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 505a0fb9d..bad2091fc 100644
--- a/internal/gitaly/config/config.go
+++ b/internal/gitaly/config/config.go
@@ -291,6 +291,8 @@ 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 bbb348e60..a5d15003e 100644
--- a/internal/gitaly/config/config_test.go
+++ b/internal/gitaly/config/config_test.go
@@ -932,33 +932,6 @@ func TestValidateCgroups(t *testing.T) {
},
},
{
- 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,
- },
- },
- },
- {
name: "repositories - zero count",
rawCfg: `[cgroups]
mountpoint = "/sys/fs/cgroup"