diff --git a/go.mod b/go.mod index 6debb32..ab83143 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21.5 require ( github.com/Asphaltt/go-iproute2 v0.0.0-20220404100349-2854774d085e - github.com/CloudDetail/metadata v0.0.0-20240809080233-394951895115 + github.com/CloudDetail/metadata v0.0.0-20240903055919-f0487c96aa95 github.com/mdlayher/netlink v1.7.2 github.com/prometheus/client_golang v1.19.1 github.com/vishvananda/netlink v1.2.1-beta.2.0.20220608195807-1a118fe229fc diff --git a/go.sum b/go.sum index 174fd9b..908aab7 100644 --- a/go.sum +++ b/go.sum @@ -17,6 +17,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/CloudDetail/metadata v0.0.0-20240809080233-394951895115 h1:6O9/rBmqa5Ig1n0xFTOqKoYT/7aGkzs2OYUmCr5PMg4= github.com/CloudDetail/metadata v0.0.0-20240809080233-394951895115/go.mod h1:YpCyr1yI2rybhXMo7STmU7qVvkRp6EDVaDRnU9Wf8ls= +github.com/CloudDetail/metadata v0.0.0-20240903055919-f0487c96aa95 h1:52seV0rUftzIronLQOHOHbnlz4YHS4/dAB9rSHa+24M= +github.com/CloudDetail/metadata v0.0.0-20240903055919-f0487c96aa95/go.mod h1:YpCyr1yI2rybhXMo7STmU7qVvkRp6EDVaDRnU9Wf8ls= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= diff --git a/proc/cgroup.go b/proc/cgroup.go index 7fceab5..5945a79 100644 --- a/proc/cgroup.go +++ b/proc/cgroup.go @@ -7,11 +7,12 @@ import ( ) var ( - dockerIdRegexp = regexp.MustCompile(`([a-z0-9]{64})`) - crioIdRegexp = regexp.MustCompile(`crio-([a-z0-9]{64})`) - containerdIdRegexp = regexp.MustCompile(`cri-containerd[-:]([a-z0-9]{64})`) - lxcIdRegexp = regexp.MustCompile(`/lxc/([^/]+)`) - systemSliceIdRegexp = regexp.MustCompile(`(/(system|runtime)\.slice/([^/]+))`) + dockerIdRegexp = regexp.MustCompile(`([a-z0-9]{64})`) + crioIdRegexp = regexp.MustCompile(`crio-([a-z0-9]{64})`) + containerdIdRegexp = regexp.MustCompile(`cri-containerd[-:]([a-z0-9]{64})`) + +// lxcIdRegexp = regexp.MustCompile(`/lxc/([^/]+)`) +// systemSliceIdRegexp = regexp.MustCompile(`(/(system|runtime)\.slice/([^/]+))`) ) func containerByCgroup(path string) (string, error) { @@ -48,19 +49,19 @@ func containerByCgroup(path string) (string, error) { } return matches[1], nil } - if prefix == "lxc" { - matches := lxcIdRegexp.FindStringSubmatch(path) - if matches == nil { - return "", fmt.Errorf("invalid lxc cgroup %s", path) - } - return matches[1], nil - } - if prefix == "system.slice" || prefix == "runtime.slice" { - matches := systemSliceIdRegexp.FindStringSubmatch(path) - if matches == nil { - return "", fmt.Errorf("invalid systemd cgroup %s", path) - } - return strings.Replace(matches[1], "\\x2d", "-", -1), nil - } + // if prefix == "lxc" { + // matches := lxcIdRegexp.FindStringSubmatch(path) + // if matches == nil { + // return "", fmt.Errorf("invalid lxc cgroup %s", path) + // } + // return matches[1], nil + // } + // if prefix == "system.slice" || prefix == "runtime.slice" { + // matches := systemSliceIdRegexp.FindStringSubmatch(path) + // if matches == nil { + // return "", fmt.Errorf("invalid systemd cgroup %s", path) + // } + // return strings.Replace(matches[1], "\\x2d", "-", -1), nil + // } return "", fmt.Errorf("unknown container: %s", path) }