@@ -38,6 +38,7 @@ container_cpu_usage_seconds_total{id="/",name="cap",namespace="default"} 100.0 1
3838container_cpu_usage_seconds_total{id="/kubepods/burstable/pod1/c1",name="my-app",namespace="default"} 5.0 1678886400000
3939container_cpu_usage_seconds_total{id="/kubepods/burstable/pod1/c2",name="libops-cache",namespace="default"} 1.0 1678886400000
4040container_cpu_usage_seconds_total{id="/kubepods/burstable/pod1/c3",name="other-app",namespace="default"} 0.0 1678886400000
41+ container_cpu_usage_seconds_total{id="/system.slice/docker.service"} 2.0 1678886400000
4142# HELP container_tasks_state The state of the container's tasks.
4243# TYPE container_tasks_state gauge
4344container_tasks_state{state="running",name="my-app"} 1.0 1678886400000
@@ -55,21 +56,25 @@ container_tasks_state{state="running",name="my-app"} 1.0 1678886400000
5556 // Expected results:
5657 // 1. "cap" container (name="cap") -> EXCLUDED
5758 // 2. "my-app" container (name="my-app", metric="container_cpu_usage_seconds_total", val=5.0) -> INCLUDED
58- // 3. "libops-cache" container (name="libops-cache") -> EXCLUDED (HasPrefix)
59+ // 3. "libops-cache" container (name="libops-cache") -> INCLUDED
5960 // 4. "other-app" container (name="other-app", val=0.0) -> EXCLUDED (val <= 0.0)
60- // 5. "my-app" tasks_state (metric="container_tasks_state") -> EXCLUDED (Metric name check)
61+ // 5. "/system.slice/docker.service" (no name label) -> EXCLUDED (not a Docker container series)
62+ // 6. "my-app" tasks_state (metric="container_tasks_state") -> EXCLUDED (Metric name check)
6163
62- if len (batch ) != 1 {
63- t .Fatalf ("Expected 1 metric sample after filtering, got %d" , len (batch ))
64+ if len (batch ) != 2 {
65+ t .Fatalf ("Expected 2 metric samples after filtering, got %d" , len (batch ))
6466 }
6567
66- // Helper to find the original labels from the Ref
67- labelsByRef := s .GetLabelsByRef (storage .SeriesRef (batch [0 ].Ref ))
68- if labelsByRef .Get ("name" ) != "my-app" {
69- t .Errorf ("Included metric has wrong container name. Expected 'my-app', got '%s'" , labelsByRef .Get ("name" ))
68+ got := make (map [string ]float64 , len (batch ))
69+ for _ , sample := range batch {
70+ labelsByRef := s .GetLabelsByRef (storage .SeriesRef (sample .Ref ))
71+ got [labelsByRef .Get ("name" )] = sample .V
72+ }
73+ if got ["my-app" ] != 5.0 {
74+ t .Errorf ("Expected my-app value 5.0, got %f" , got ["my-app" ])
7075 }
71- if batch [ 0 ]. V != 5 .0 {
72- t .Errorf ("Included metric has wrong value. Expected 5 .0, got %f" , batch [ 0 ]. V )
76+ if got [ "libops-cache" ] != 1 .0 {
77+ t .Errorf ("Expected libops-cache value 1 .0, got %f" , got [ "libops-cache" ] )
7378 }
7479}
7580
0 commit comments