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-06-13 20:29:34 +0300
committerJohn Cai <jcai@gitlab.com>2022-07-08 18:14:23 +0300
commitfde4a4702a17509f12e63732f7778da19972278f (patch)
treee0d22247bd7cbe2ef3301a23840a0c55a76dd413
parentc0955807f263552ff28ef09519f249498aa3b7cd (diff)
cgroups: Only enable metrics if option is turned on
On many cloud providers, cadvisor runs and keeps track of cgroups. To have Gitaly expose its own metrics is redundant at this point. Allow users to configure whether or not they would like Gitaly to collect its own metrics about cgroups. Changelog: added
-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) {