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-04-14 21:23:37 +0300
committerJohn Cai <jcai@gitlab.com>2022-04-14 21:23:37 +0300
commit57311fd8ccfcc1ad12bade792bcfc53a9f708cac (patch)
treeaa0d65d96a518dac5123603130caf0a7c6f064e0
parent3f45156f54ea1994ec21388581efe83d18f05345 (diff)
update metric tests
-rw-r--r--internal/cgroups/mock_linux_test.go10
-rw-r--r--internal/cgroups/v1_linux.go29
-rw-r--r--internal/cgroups/v1_linux_test.go40
3 files changed, 71 insertions, 8 deletions
diff --git a/internal/cgroups/mock_linux_test.go b/internal/cgroups/mock_linux_test.go
index b941bda23..f21180e19 100644
--- a/internal/cgroups/mock_linux_test.go
+++ b/internal/cgroups/mock_linux_test.go
@@ -112,5 +112,15 @@ func (m *mockCgroup) setupMockCgroupFiles(
require.NoError(t, os.WriteFile(shardControlFilePath, []byte(content), 0o644))
}
}
+
+ for shard := uint(0); shard < manager.cfg.Git.Count; shard++ {
+ shardPath := filepath.Join(cgroupPath, fmt.Sprintf("git-commands-%d", shard))
+ require.NoError(t, os.MkdirAll(shardPath, 0o755))
+
+ for filename, content := range contentByFilename {
+ shardControlFilePath := filepath.Join(shardPath, filename)
+ require.NoError(t, os.WriteFile(shardControlFilePath, []byte(content), 0o644))
+ }
+ }
}
}
diff --git a/internal/cgroups/v1_linux.go b/internal/cgroups/v1_linux.go
index f5404fdfc..48d3aeb70 100644
--- a/internal/cgroups/v1_linux.go
+++ b/internal/cgroups/v1_linux.go
@@ -20,7 +20,8 @@ type CGroupV1Manager struct {
cfg cgroupscfg.Config
hierarchy func() ([]cgroups.Subsystem, error)
memoryFailedTotal, cpuUsage *prometheus.GaugeVec
- procs *prometheus.GaugeVec
+ procs, gitCgroups *prometheus.GaugeVec
+ gitWithoutCgroup prometheus.Counter
gitCmds map[string]cgroupscfg.Command
gitCgroupPool chan string
}
@@ -52,6 +53,19 @@ func newV1Manager(cfg cgroupscfg.Config) *CGroupV1Manager {
},
[]string{"path", "subsystem"},
),
+ gitCgroups: prometheus.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Name: "gitaly_cgroup_git_cgroups",
+ Help: "Total number of git cgroups in use",
+ },
+ []string{"status"},
+ ),
+ gitWithoutCgroup: prometheus.NewCounter(
+ prometheus.CounterOpts{
+ Name: "gitaly_cgroup_git_without_cgroup_total",
+ Help: "Total number of git commands without a cgroup",
+ },
+ ),
gitCmds: make(map[string]cgroupscfg.Command),
}
}
@@ -139,6 +153,10 @@ func (cg *CGroupV1Manager) AddCommand(
return fmt.Errorf("failed adding process to cgroup: %w", err)
}
default:
+ cg.gitWithoutCgroup.Inc()
+ log.Default().WithField("git_cmd", gitCmdName).
+ WithField("relative_path", repo.GetRelativePath()).
+ Warn("git command could not be added to a cgroup")
return nil
}
@@ -218,6 +236,15 @@ func (cg *CGroupV1Manager) Collect(ch chan<- prometheus.Metric) {
ch <- procsMetric
}
}
+
+ gitCgroupsTotalMetric := cg.gitCgroups.WithLabelValues("total")
+ gitCgroupsTotalMetric.Set(float64(cg.cfg.Git.Count))
+ ch <- gitCgroupsTotalMetric
+
+ gitCgroupsInUseMetric := cg.gitCgroups.WithLabelValues("in_use")
+ gitCgroupsInUseMetric.Set(float64(int(cg.cfg.Git.Count) - len(cg.gitCgroupPool)))
+ ch <- gitCgroupsInUseMetric
+ ch <- cg.gitWithoutCgroup
}
// Describe describes the cgroup metrics that Collect provides
diff --git a/internal/cgroups/v1_linux_test.go b/internal/cgroups/v1_linux_test.go
index 8bf769e15..1ce1c6f94 100644
--- a/internal/cgroups/v1_linux_test.go
+++ b/internal/cgroups/v1_linux_test.go
@@ -186,6 +186,16 @@ func TestMetrics(t *testing.T) {
}
config := defaultCgroupsConfig()
+ config.Git = cgroups.Git{
+ Count: 1,
+ Commands: []cgroups.Command{
+ cgroups.Command{
+ Name: "git-cmd-1",
+ MemoryBytes: 1048576,
+ CPUShares: 16,
+ },
+ },
+ }
v1Manager1 := newV1Manager(config)
v1Manager1.hierarchy = mock.hierarchy
@@ -198,12 +208,18 @@ func TestMetrics(t *testing.T) {
logger.SetLevel(logrus.DebugLevel)
ctx = ctxlogrus.ToContext(ctx, logrus.NewEntry(logger))
- cmd1 := exec.Command("ls", "-hal", ".")
- cmd2, err := command.New(ctx, cmd1, nil, nil, nil)
+ 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)
require.NoError(t, err)
- require.NoError(t, v1Manager1.AddCommand(cmd2, "git-cmd", repo))
- require.NoError(t, cmd2.Wait())
+ require.NoError(t, v1Manager1.AddCommand(cmd, "cmd-1", repo))
+ require.NoError(t, v1Manager1.AddCommand(gitCmd1, "git-cmd-1", repo))
+ require.NoError(t, v1Manager1.AddCommand(gitCmd2, "git-cmd-1", repo))
+ require.NoError(t, cmd.Wait())
+ require.NoError(t, gitCmd1.Wait())
processCgroupPath := v1Manager1.currentProcessCgroup()
@@ -211,20 +227,30 @@ func TestMetrics(t *testing.T) {
# TYPE gitaly_cgroup_cpu_usage gauge
gitaly_cgroup_cpu_usage{path="%s",type="kernel"} 0
gitaly_cgroup_cpu_usage{path="%s",type="user"} 0
+# HELP gitaly_cgroup_git_cgroups Total number of git cgroups in use
+# TYPE gitaly_cgroup_git_cgroups gauge
+gitaly_cgroup_git_cgroups{status="in_use"} 0
+gitaly_cgroup_git_cgroups{status="total"} 1
+# HELP gitaly_cgroup_git_without_cgroup_total Total number of git commands without a cgroup
+# TYPE gitaly_cgroup_git_without_cgroup_total counter
+gitaly_cgroup_git_without_cgroup_total 1
# HELP gitaly_cgroup_memory_failed_total Number of memory usage hits limits
# TYPE gitaly_cgroup_memory_failed_total gauge
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="memory"} 1
-gitaly_cgroup_procs_total{path="%s",subsystem="cpu"} 1
+gitaly_cgroup_procs_total{path="%s",subsystem="memory"} 2
+gitaly_cgroup_procs_total{path="%s",subsystem="cpu"} 2
`, processCgroupPath, processCgroupPath, processCgroupPath, processCgroupPath, processCgroupPath))
assert.NoError(t, testutil.CollectAndCompare(
v1Manager1,
expected,
"gitaly_cgroup_memory_failed_total",
"gitaly_cgroup_cpu_usage",
- "gitaly_cgroup_procs_total"))
+ "gitaly_cgroup_procs_total",
+ "gitaly_cgroup_git_cgroups",
+ "gitaly_cgroup_git_without_cgroup_total",
+ ))
logEntry := hook.LastEntry()
assert.Contains(