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-06-14 21:42:01 +0300
commitc8a0c775f6d40f087fd6dffcaaccd5d7010db7dd (patch)
tree55d85760fc5cff93f359a1c59f0cde401a99cc3f
parente81362b53558de8aa578aaf2b7b6662b42fc00ea (diff)
cgroups: Only enable metrics if option is turned onjc-rename-cgroup-metric
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
3 files changed, 30 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"`