@@ -151,13 +151,27 @@ func TestPowerCollector(t *testing.T) {
151151 },
152152 }
153153
154+ testPods := monitor.Pods {
155+ "test-pod" : {
156+ Name : "test-pod" ,
157+ Namespace : "default" ,
158+ Zones : monitor.ZoneUsageMap {
159+ packageZone : {
160+ EnergyTotal : 100 * device .Joule ,
161+ Power : 5 * device .Watt ,
162+ },
163+ },
164+ },
165+ }
166+
154167 // Create test Snapshot
155168 testData := & monitor.Snapshot {
156169 Timestamp : time .Now (),
157170 Node : & testNodeData ,
158171 Processes : testProcesses ,
159172 Containers : testContainers ,
160173 VirtualMachines : testVMs ,
174+ Pods : testPods ,
161175 }
162176
163177 // Mock Snapshot method
@@ -200,6 +214,9 @@ func TestPowerCollector(t *testing.T) {
200214
201215 "kepler_vm_cpu_joules_total" ,
202216 "kepler_vm_cpu_watts" ,
217+
218+ "kepler_pod_cpu_joules_total" ,
219+ "kepler_pod_cpu_watts" ,
203220 }
204221
205222 assert .ElementsMatch (t , expectedMetricNames , metricNames (metrics ))
@@ -309,6 +326,86 @@ func TestPowerCollector(t *testing.T) {
309326 })
310327 })
311328
329+ t .Run ("Process Metrics Node Name Label" , func (t * testing.T ) {
330+ metrics , err := registry .Gather ()
331+ assert .NoError (t , err )
332+
333+ for _ , metric := range metrics {
334+ if metric .GetName () == "kepler_process_cpu_joules_total" {
335+ for _ , m := range metric .GetMetric () {
336+ nodeName := valueOfLabel (m , "node_name" )
337+ assert .Equal (t , "test-node" , nodeName , "Process metrics should have node_name label" )
338+ }
339+ }
340+ if metric .GetName () == "kepler_process_cpu_watts" {
341+ for _ , m := range metric .GetMetric () {
342+ nodeName := valueOfLabel (m , "node_name" )
343+ assert .Equal (t , "test-node" , nodeName , "Process metrics should have node_name label" )
344+ }
345+ }
346+ }
347+ })
348+
349+ t .Run ("Container Metrics Node Name Label" , func (t * testing.T ) {
350+ metrics , err := registry .Gather ()
351+ assert .NoError (t , err )
352+
353+ for _ , metric := range metrics {
354+ if metric .GetName () == "kepler_container_cpu_joules_total" {
355+ for _ , m := range metric .GetMetric () {
356+ nodeName := valueOfLabel (m , "node_name" )
357+ assert .Equal (t , "test-node" , nodeName , "Container metrics should have node_name label" )
358+ }
359+ }
360+ if metric .GetName () == "kepler_container_cpu_watts" {
361+ for _ , m := range metric .GetMetric () {
362+ nodeName := valueOfLabel (m , "node_name" )
363+ assert .Equal (t , "test-node" , nodeName , "Container metrics should have node_name label" )
364+ }
365+ }
366+ }
367+ })
368+
369+ t .Run ("VM Metrics Node Name Label" , func (t * testing.T ) {
370+ metrics , err := registry .Gather ()
371+ assert .NoError (t , err )
372+
373+ for _ , metric := range metrics {
374+ if metric .GetName () == "kepler_vm_cpu_joules_total" {
375+ for _ , m := range metric .GetMetric () {
376+ nodeName := valueOfLabel (m , "node_name" )
377+ assert .Equal (t , "test-node" , nodeName , "VM metrics should have node_name label" )
378+ }
379+ }
380+ if metric .GetName () == "kepler_vm_cpu_watts" {
381+ for _ , m := range metric .GetMetric () {
382+ nodeName := valueOfLabel (m , "node_name" )
383+ assert .Equal (t , "test-node" , nodeName , "VM metrics should have node_name label" )
384+ }
385+ }
386+ }
387+ })
388+
389+ t .Run ("Pod Metrics Node Name Label" , func (t * testing.T ) {
390+ metrics , err := registry .Gather ()
391+ assert .NoError (t , err )
392+
393+ for _ , metric := range metrics {
394+ if metric .GetName () == "kepler_pod_cpu_joules_total" {
395+ for _ , m := range metric .GetMetric () {
396+ nodeName := valueOfLabel (m , "node_name" )
397+ assert .Equal (t , "test-node" , nodeName , "Pod metrics should have node_name label" )
398+ }
399+ }
400+ if metric .GetName () == "kepler_pod_cpu_watts" {
401+ for _ , m := range metric .GetMetric () {
402+ nodeName := valueOfLabel (m , "node_name" )
403+ assert .Equal (t , "test-node" , nodeName , "Pod metrics should have node_name label" )
404+ }
405+ }
406+ }
407+ })
408+
312409 // Verify mock expectations
313410 mockMonitor .AssertExpectations (t )
314411}
0 commit comments