Skip to content

Commit

Permalink
Update MetaData (#4)
Browse files Browse the repository at this point in the history
* rm lxc and system.slice cgroup

* update metadata module
  • Loading branch information
fuwx295 authored Sep 4, 2024
1 parent 33f8355 commit b22e19c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
39 changes: 20 additions & 19 deletions proc/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

0 comments on commit b22e19c

Please sign in to comment.