MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestProcessCollector

Function TestProcessCollector

pkg/util/process/collector_test.go:15–45  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestProcessCollector(t *testing.T) {
16 const pid = 1
17
18 // Create a mocked proc FS.
19 procDir := t.TempDir()
20
21 mapsPath := processMapsPath(procDir, pid)
22 mapsLimitPath := vmMapsLimitPath(procDir)
23
24 require.NoError(t, os.MkdirAll(filepath.Dir(mapsPath), os.ModePerm))
25 require.NoError(t, os.MkdirAll(filepath.Dir(mapsLimitPath), os.ModePerm))
26
27 require.NoError(t, os.WriteFile(mapsPath, []byte("1\n2\n3\n4\n5\n"), os.ModePerm))
28 require.NoError(t, os.WriteFile(mapsLimitPath, []byte("262144\n"), os.ModePerm))
29
30 // Create a new collector and test metrics.
31 c, err := newProcessCollector(pid, procDir)
32 require.NoError(t, err)
33
34 reg := prometheus.NewPedanticRegistry()
35 require.NoError(t, reg.Register(c))
36
37 assert.NoError(t, testutil.GatherAndCompare(reg, bytes.NewBufferString(`
38 # HELP process_memory_map_areas Number of memory map areas allocated by the process.
39 # TYPE process_memory_map_areas gauge
40 process_memory_map_areas 5
41 # HELP process_memory_map_areas_limit Maximum number of memory map ares the process can allocate.
42 # TYPE process_memory_map_areas_limit gauge
43 process_memory_map_areas_limit 262144
44 `)))
45}
46
47func TestProcessCollector_UnsupportedPlatform(t *testing.T) {
48 _, err := newProcessCollector(1, "/path/to/invalid/proc")

Callers

nothing calls this directly

Calls 4

processMapsPathFunction · 0.85
vmMapsLimitPathFunction · 0.85
newProcessCollectorFunction · 0.85
RegisterMethod · 0.80

Tested by

no test coverage detected