From b9e381cc6c9a56e6520b66e6a619e0e08468ce92 Mon Sep 17 00:00:00 2001 From: Antti Kervinen Date: Fri, 23 Dec 2022 13:00:19 +0200 Subject: [PATCH] metrics: fix collecting hugetlb statistics from cgroup v1 - Hugetlb statistics collector matched both usage and (later added) reservation accounting files (*.rsvd.*). When both were present, the collector tried to create duplicate metrics entries: usage and reservation values got the same name and labels. - This patch ignores *.rsvd.* files when collecting statistics in order to keep reporting exactly what was reported before them. - Fixes error "cgroup_hugetlb_usage... collected before with the same name and label values" error in cri-resmgr output. - Fixes issue #859. --- pkg/cgroups/cgroupstats.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cgroups/cgroupstats.go b/pkg/cgroups/cgroupstats.go index 941148c7e..a3bdf5a61 100644 --- a/pkg/cgroups/cgroupstats.go +++ b/pkg/cgroups/cgroupstats.go @@ -307,6 +307,10 @@ func GetHugetlbUsage(cgroupPath string) ([]HugetlbUsage, error) { result := make([]HugetlbUsage, 0, len(usageFiles)) for _, file := range usageFiles { + if strings.Contains(filepath.Base(file), ".rsvd") { + // Skip reservations files. + continue + } size := strings.SplitN(filepath.Base(file), ".", 3)[1] bytes, err := readCgroupSingleNumber(file) if err != nil {