@@ -36,9 +36,11 @@ import (
36
36
evictionpluginapi "github.com/kubewharf/katalyst-api/pkg/protocol/evictionplugin/v1alpha1"
37
37
qrmstate "github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state"
38
38
"github.com/kubewharf/katalyst-core/pkg/config"
39
+ pkgconsts "github.com/kubewharf/katalyst-core/pkg/consts"
39
40
"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/metric"
40
41
"github.com/kubewharf/katalyst-core/pkg/metrics"
41
42
"github.com/kubewharf/katalyst-core/pkg/util/machine"
43
+ utilmetric "github.com/kubewharf/katalyst-core/pkg/util/metric"
42
44
)
43
45
44
46
const (
@@ -53,6 +55,7 @@ func makeSuppressionEvictionConf(cpuMaxSuppressionToleranceRate float64,
53
55
conf .GetDynamicConfiguration ().EnableSuppressionEviction = true
54
56
conf .GetDynamicConfiguration ().MaxSuppressionToleranceRate = cpuMaxSuppressionToleranceRate
55
57
conf .GetDynamicConfiguration ().MinSuppressionToleranceDuration = cpuMinSuppressionToleranceDuration
58
+ conf .ReclaimRelativeRootCgroupPath = "test"
56
59
return conf
57
60
}
58
61
@@ -77,15 +80,7 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) {
77
80
78
81
as := require .New (t )
79
82
80
- cpuTopology , err := machine .GenerateDummyCPUTopology (16 , 2 , 4 )
81
- as .Nil (err )
82
- conf := makeSuppressionEvictionConf (defaultCPUMaxSuppressionToleranceRate , defaultCPUMinSuppressionToleranceDuration )
83
- metaServer := makeMetaServer (metric .NewFakeMetricsFetcher (metrics.DummyMetrics {}), cpuTopology )
84
- stateImpl , err := makeState (cpuTopology )
85
- as .Nil (err )
86
-
87
- plugin , _ := NewCPUPressureSuppressionEviction (metrics.DummyMetrics {}, metaServer , conf , stateImpl )
88
- as .NotNil (plugin )
83
+ now := time .Now ()
89
84
90
85
pod1UID := string (uuid .NewUUID ())
91
86
pod1Name := "pod-1"
@@ -95,6 +90,7 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) {
95
90
tests := []struct {
96
91
name string
97
92
podEntries qrmstate.PodEntries
93
+ setFakeMetric func (store * metric.FakeMetricsFetcher )
98
94
wantEvictPodUIDSet sets.String
99
95
}{
100
96
{
@@ -157,6 +153,20 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) {
157
153
},
158
154
},
159
155
wantEvictPodUIDSet : sets .NewString (),
156
+ setFakeMetric : func (store * metric.FakeMetricsFetcher ) {
157
+ store .SetCPUMetric (1 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
158
+ store .SetCPUMetric (3 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
159
+ store .SetCPUMetric (4 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
160
+ store .SetCPUMetric (5 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
161
+ store .SetCPUMetric (6 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
162
+ store .SetCPUMetric (9 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
163
+ store .SetCPUMetric (11 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
164
+ store .SetCPUMetric (12 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
165
+ store .SetCPUMetric (13 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
166
+ store .SetCPUMetric (14 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
167
+
168
+ store .SetCgroupMetric ("test" , pkgconsts .MetricCPUUsageCgroup , utilmetric.MetricData {Value : 5 , Time : & now })
169
+ },
160
170
},
161
171
{
162
172
name : "over tolerance rate" ,
@@ -253,72 +263,106 @@ func TestCPUPressureSuppression_GetEvictPods(t *testing.T) {
253
263
},
254
264
},
255
265
wantEvictPodUIDSet : sets .NewString (pod1UID ),
266
+ setFakeMetric : func (store * metric.FakeMetricsFetcher ) {
267
+ store .SetCPUMetric (1 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
268
+ store .SetCPUMetric (3 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
269
+ store .SetCPUMetric (4 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
270
+ store .SetCPUMetric (5 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
271
+ store .SetCPUMetric (6 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
272
+ store .SetCPUMetric (9 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
273
+ store .SetCPUMetric (11 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
274
+ store .SetCPUMetric (12 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
275
+ store .SetCPUMetric (13 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
276
+ store .SetCPUMetric (14 , pkgconsts .MetricCPUUsageRatio , utilmetric.MetricData {Value : 0.5 , Time : & now })
277
+
278
+ store .SetCgroupMetric ("test" , pkgconsts .MetricCPUUsageCgroup , utilmetric.MetricData {Value : 5 , Time : & now })
279
+ },
256
280
},
257
281
}
258
282
259
283
for _ , tt := range tests {
260
- stateImpl , err := makeState (cpuTopology )
261
- as .Nil (err )
284
+ tt := tt
285
+ t .Run (tt .name , func (t * testing.T ) {
286
+ t .Parallel ()
262
287
263
- pods := make ([]* v1.Pod , 0 , len (tt .podEntries ))
288
+ cpuTopology , err := machine .GenerateDummyCPUTopology (16 , 2 , 4 )
289
+ as .Nil (err )
290
+ conf := makeSuppressionEvictionConf (defaultCPUMaxSuppressionToleranceRate , defaultCPUMinSuppressionToleranceDuration )
264
291
265
- for entryName , entries := range tt .podEntries {
266
- for subEntryName , entry := range entries {
267
- stateImpl .SetAllocationInfo (entryName , subEntryName , entry )
292
+ metricsFetcher := metric .NewFakeMetricsFetcher (metrics.DummyMetrics {})
293
+ store := metricsFetcher .(* metric.FakeMetricsFetcher )
268
294
269
- if entries . IsPoolEntry () {
270
- continue
271
- }
295
+ metaServer := makeMetaServer ( metricsFetcher , cpuTopology )
296
+ stateImpl , err := makeState ( cpuTopology )
297
+ as . Nil ( err )
272
298
273
- pod := & v1.Pod {
274
- ObjectMeta : metav1.ObjectMeta {
275
- UID : types .UID (entry .PodUid ),
276
- Name : entry .PodName ,
277
- Namespace : entry .PodNamespace ,
278
- Annotations : maputil .CopySS (entry .Annotations ),
279
- Labels : maputil .CopySS (entry .Labels ),
280
- },
281
- Spec : v1.PodSpec {
282
- Containers : []v1.Container {
283
- {
284
- Name : entry .ContainerName ,
285
- Resources : v1.ResourceRequirements {
286
- Requests : v1.ResourceList {
287
- apiconsts .ReclaimedResourceMilliCPU : * resource .NewQuantity (int64 (entry .RequestQuantity * 1000 ), resource .DecimalSI ),
288
- },
289
- Limits : v1.ResourceList {
290
- apiconsts .ReclaimedResourceMilliCPU : * resource .NewQuantity (int64 (entry .RequestQuantity * 1000 ), resource .DecimalSI ),
299
+ plugin , _ := NewCPUPressureSuppressionEviction (metrics.DummyMetrics {}, metaServer , conf , stateImpl )
300
+ as .NotNil (plugin )
301
+
302
+ pods := make ([]* v1.Pod , 0 , len (tt .podEntries ))
303
+
304
+ if tt .setFakeMetric != nil {
305
+ tt .setFakeMetric (store )
306
+ }
307
+
308
+ for entryName , entries := range tt .podEntries {
309
+ for subEntryName , entry := range entries {
310
+ stateImpl .SetAllocationInfo (entryName , subEntryName , entry )
311
+
312
+ if entries .IsPoolEntry () {
313
+ continue
314
+ }
315
+
316
+ pod := & v1.Pod {
317
+ ObjectMeta : metav1.ObjectMeta {
318
+ UID : types .UID (entry .PodUid ),
319
+ Name : entry .PodName ,
320
+ Namespace : entry .PodNamespace ,
321
+ Annotations : maputil .CopySS (entry .Annotations ),
322
+ Labels : maputil .CopySS (entry .Labels ),
323
+ },
324
+ Spec : v1.PodSpec {
325
+ Containers : []v1.Container {
326
+ {
327
+ Name : entry .ContainerName ,
328
+ Resources : v1.ResourceRequirements {
329
+ Requests : v1.ResourceList {
330
+ apiconsts .ReclaimedResourceMilliCPU : * resource .NewQuantity (int64 (entry .RequestQuantity * 1000 ), resource .DecimalSI ),
331
+ },
332
+ Limits : v1.ResourceList {
333
+ apiconsts .ReclaimedResourceMilliCPU : * resource .NewQuantity (int64 (entry .RequestQuantity * 1000 ), resource .DecimalSI ),
334
+ },
291
335
},
292
336
},
293
337
},
294
338
},
295
- },
296
- }
339
+ }
297
340
298
- pods = append (pods , pod )
341
+ pods = append (pods , pod )
342
+ }
299
343
}
300
- }
301
344
302
- plugin .(* CPUPressureSuppression ).state = stateImpl
345
+ plugin .(* CPUPressureSuppression ).state = stateImpl
303
346
304
- resp , err := plugin .GetEvictPods (context .TODO (), & evictionpluginapi.GetEvictPodsRequest {
305
- ActivePods : pods ,
306
- })
307
- assert .NoError (t , err )
308
- assert .NotNil (t , resp )
347
+ resp , err := plugin .GetEvictPods (context .TODO (), & evictionpluginapi.GetEvictPodsRequest {
348
+ ActivePods : pods ,
349
+ })
350
+ assert .NoError (t , err )
351
+ assert .NotNil (t , resp )
352
+
353
+ time .Sleep (defaultCPUMinSuppressionToleranceDuration )
309
354
310
- time .Sleep (defaultCPUMinSuppressionToleranceDuration )
355
+ resp , err = plugin .GetEvictPods (context .TODO (), & evictionpluginapi.GetEvictPodsRequest {
356
+ ActivePods : pods ,
357
+ })
358
+ assert .NoError (t , err )
359
+ assert .NotNil (t , resp )
311
360
312
- resp , err = plugin .GetEvictPods (context .TODO (), & evictionpluginapi.GetEvictPodsRequest {
313
- ActivePods : pods ,
361
+ evictPodUIDSet := sets.String {}
362
+ for _ , pod := range resp .EvictPods {
363
+ evictPodUIDSet .Insert (string (pod .Pod .GetUID ()))
364
+ }
365
+ assert .Equal (t , tt .wantEvictPodUIDSet , evictPodUIDSet )
314
366
})
315
- assert .NoError (t , err )
316
- assert .NotNil (t , resp )
317
-
318
- evictPodUIDSet := sets.String {}
319
- for _ , pod := range resp .EvictPods {
320
- evictPodUIDSet .Insert (string (pod .Pod .GetUID ()))
321
- }
322
- assert .Equal (t , tt .wantEvictPodUIDSet , evictPodUIDSet )
323
367
}
324
368
}
0 commit comments