github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/agent/ebpfspy/sd/k8s_test.go (about) 1 package sd 2 3 import "testing" 4 5 func TestKubePodsCgroupsV1(t *testing.T) { 6 cg := "11:devices:/kubepods/besteffort/pod85adbef3-622f-4ef2-8f60-a8bdf3eb6c72/" + 7 "7edda1de1e0d1d366351e478359cf5fa16bb8ab53063a99bb119e56971bfb7e2" 8 cid := getContainerIDFromCGroup(cg) 9 expected := "7edda1de1e0d1d366351e478359cf5fa16bb8ab53063a99bb119e56971bfb7e2" 10 if cid != expected { 11 t.Fatalf("wrong cid %s != %s", cid, expected) 12 } 13 } 14 15 func TestContainerdCgroupsV2(t *testing.T) { 16 cg := "0::/kubepods.slice/kubepods-burstable.slice/" + 17 "kubepods-burstable-podf9a04ecc_1875_491b_926c_d2f64757704e.slice/" + 18 "cri-containerd-47e320f795efcec1ecf2001c3a09c95e3701ed87de8256837b70b10e23818251.scope" 19 cid := getContainerIDFromCGroup(cg) 20 expected := "47e320f795efcec1ecf2001c3a09c95e3701ed87de8256837b70b10e23818251" 21 if cid != expected { 22 t.Fatalf("wrong cid %s != %s", cid, expected) 23 } 24 } 25 26 func TestDockerCgroupsV2(t *testing.T) { 27 cg := "0::/../../kubepods-besteffort-pod88f6f4e3_59c0_4ce8_9ecf_391c8b5a60ad.slice/" + 28 "docker-656959d9ee87a0b131c601ce9d9f8f76b1dda60e8608c503b5979d849cbdc714.scope" 29 cid := getContainerIDFromCGroup(cg) 30 expected := "656959d9ee87a0b131c601ce9d9f8f76b1dda60e8608c503b5979d849cbdc714" 31 if cid != expected { 32 t.Fatalf("wrong cid %s != %s", cid, expected) 33 } 34 } 35 36 func TestCRI(t *testing.T) { 37 statusContainerID := "containerd://a534eb629135e43beb13213976e37bb2ab95cba4c0d1d0b4e27c6bc4d8091b83" 38 cgroup := "12:cpuset:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod471203d1_984f_477e_9c35_db96487ffe5e.slice/" + 39 "cri-containerd-a534eb629135e43beb13213976e37bb2ab95cba4c0d1d0b4e27c6bc4d8091b83.scope" 40 cid := getContainerIDFromCGroup(cgroup) 41 expected := "a534eb629135e43beb13213976e37bb2ab95cba4c0d1d0b4e27c6bc4d8091b83" 42 if cid != expected { 43 t.Fatalf("wrong cid %s != %s", cid, expected) 44 } 45 cid, err := getContainerIDFromK8S(statusContainerID) 46 if err != nil { 47 t.Fatal(err) 48 } 49 if cid != expected { 50 t.Fatalf("wrong cid %s != %s", cid, expected) 51 } 52 }