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:
-rw-r--r--internal/cgroups/v1_linux.go4
-rw-r--r--internal/cgroups/v1_linux_test.go35
-rw-r--r--internal/gitaly/config/cgroups/cgroups.go3
-rw-r--r--internal/gitaly/config/config_test.go22
4 files changed, 52 insertions, 12 deletions
diff --git a/internal/cgroups/v1_linux.go b/internal/cgroups/v1_linux.go
index 201d098fe..3c6ec1055 100644
--- a/internal/cgroups/v1_linux.go
+++ b/internal/cgroups/v1_linux.go
@@ -142,6 +142,10 @@ func (cg *CGroupV1Manager) addToCgroup(pid int, cgroupPath string) error {
// Collect collects metrics from the cgroups controller
func (cg *CGroupV1Manager) Collect(ch chan<- prometheus.Metric) {
+ if !cg.cfg.MetricsEnabled {
+ return
+ }
+
for i := 0; i < int(cg.cfg.Repositories.Count); i++ {
repoPath := cg.repoPath(i)
logger := log.Default().WithField("cgroup_path", repoPath)
diff --git a/internal/cgroups/v1_linux_test.go b/internal/cgroups/v1_linux_test.go
index ede9155ba..89f78293a 100644
--- a/internal/cgroups/v1_linux_test.go
+++ b/internal/cgroups/v1_linux_test.go
@@ -200,17 +200,30 @@ gitaly_cgroup_memory_reclaim_attempts_total{path="%s"} 2
gitaly_cgroup_procs_total{path="%s",subsystem="cpu"} 1
gitaly_cgroup_procs_total{path="%s",subsystem="memory"} 1
`, repoCgroupPath, repoCgroupPath, repoCgroupPath, repoCgroupPath, repoCgroupPath))
- assert.NoError(t, testutil.CollectAndCompare(
- v1Manager1,
- expected))
-
- logEntry := hook.LastEntry()
- assert.Contains(
- t,
- logEntry.Data["command.cgroup_path"],
- repoCgroupPath,
- "log field includes a cgroup path that is a subdirectory of the current process' cgroup path",
- )
+
+ for _, metricsEnabled := range []bool{true, false} {
+ t.Run(fmt.Sprintf("metrics enabled: %v", metricsEnabled), func(t *testing.T) {
+ v1Manager1.cfg.MetricsEnabled = metricsEnabled
+
+ if metricsEnabled {
+ assert.NoError(t, testutil.CollectAndCompare(
+ v1Manager1,
+ expected))
+ } else {
+ assert.NoError(t, testutil.CollectAndCompare(
+ v1Manager1,
+ bytes.NewBufferString("")))
+ }
+
+ logEntry := hook.LastEntry()
+ assert.Contains(
+ t,
+ logEntry.Data["command.cgroup_path"],
+ repoCgroupPath,
+ "log field includes a cgroup path that is a subdirectory of the current process' cgroup path",
+ )
+ })
+ }
}
func readCgroupFile(t *testing.T, path string) []byte {
diff --git a/internal/gitaly/config/cgroups/cgroups.go b/internal/gitaly/config/cgroups/cgroups.go
index 935a1a565..8d9094552 100644
--- a/internal/gitaly/config/cgroups/cgroups.go
+++ b/internal/gitaly/config/cgroups/cgroups.go
@@ -14,7 +14,8 @@ type Config struct {
MemoryBytes int64 `toml:"memory_bytes"`
// CPUShares are the shares of CPU the parent cgroup is allowed to utilize. A value of 1024
// is full utilization of the CPU. 0 implies no CPU limit.
- CPUShares uint64 `toml:"cpu_shares"`
+ CPUShares uint64 `toml:"cpu_shares"`
+ MetricsEnabled bool `toml:"metrics_enabled"`
// Deprecated: No longer supported after 15.0
Count uint `toml:"count"`
diff --git a/internal/gitaly/config/config_test.go b/internal/gitaly/config/config_test.go
index 2967fd398..9c1961e99 100644
--- a/internal/gitaly/config/config_test.go
+++ b/internal/gitaly/config/config_test.go
@@ -1082,6 +1082,28 @@ func TestValidateCgroups(t *testing.T) {
},
validateErr: errors.New("cgroups.repositories: cpu shares cannot exceed parent"),
},
+ {
+ name: "metrics enabled",
+ rawCfg: `[cgroups]
+ mountpoint = "/sys/fs/cgroup"
+ hierarchy_root = "gitaly"
+ metrics_enabled = true
+ [cgroups.repositories]
+ count = 10
+ memory_bytes = 1024
+ cpu_shares = 512
+ `,
+ expect: cgroups.Config{
+ Mountpoint: "/sys/fs/cgroup",
+ HierarchyRoot: "gitaly",
+ MetricsEnabled: true,
+ Repositories: cgroups.Repositories{
+ Count: 10,
+ MemoryBytes: 1024,
+ CPUShares: 512,
+ },
+ },
+ },
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {