Skip to content

Commit 7662097

Browse files
Improve avoid_contended_hosts_test and fine-tune scheduler steps
1 parent 1a81dea commit 7662097

File tree

2 files changed

+58
-52
lines changed

2 files changed

+58
-52
lines changed

helm/cortex/values.yaml

+26-26
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ conf:
368368
options:
369369
# Min-max scaling for avg CPU usage of the project on a host.
370370
avgCPUUsageLowerBound: 0 # pct
371-
avgCPUUsageUpperBound: 100 # pct
372-
avgCPUUsageActivationLowerBound: 0.25
373-
avgCPUUsageActivationUpperBound: -0.5
371+
avgCPUUsageUpperBound: 10 # pct
372+
avgCPUUsageActivationLowerBound: 0.0
373+
avgCPUUsageActivationUpperBound: -1.0
374374
dependencies:
375375
features:
376376
extractors:
@@ -379,14 +379,14 @@ conf:
379379
options:
380380
# Min-max scaling for avg CPU contention on the host.
381381
avgCPUContentionLowerBound: 0 # pct
382-
avgCPUContentionUpperBound: 100 # pct
383-
avgCPUContentionActivationLowerBound: 0.25
384-
avgCPUContentionActivationUpperBound: -0.5
382+
avgCPUContentionUpperBound: 10 # pct
383+
avgCPUContentionActivationLowerBound: 0.0
384+
avgCPUContentionActivationUpperBound: -0.75
385385
# Min-max scaling for max CPU contention on the host.
386386
maxCPUContentionLowerBound: 0 # pct
387-
maxCPUContentionUpperBound: 100 # pct
388-
maxCPUContentionActivationLowerBound: 0.25
389-
maxCPUContentionActivationUpperBound: -0.5
387+
maxCPUContentionUpperBound: 10 # pct
388+
maxCPUContentionActivationLowerBound: 0.0
389+
maxCPUContentionActivationUpperBound: -0.25
390390
dependencies:
391391
features:
392392
extractors:
@@ -397,14 +397,14 @@ conf:
397397
options:
398398
# Min-max scaling for avg CPU usage on the host.
399399
avgCPUUsageLowerBound: 0 # pct
400-
avgCPUUsageUpperBound: 100 # pct
401-
avgCPUUsageActivationLowerBound: 0.25
402-
avgCPUUsageActivationUpperBound: -0.5
400+
avgCPUUsageUpperBound: 10 # pct
401+
avgCPUUsageActivationLowerBound: 0.0
402+
avgCPUUsageActivationUpperBound: -0.75
403403
# Min-max scaling for max CPU usage on the host.
404404
maxCPUUsageLowerBound: 0 # pct
405-
maxCPUUsageUpperBound: 100 # pct
406-
maxCPUUsageActivationLowerBound: 0.25
407-
maxCPUUsageActivationUpperBound: -0.5
405+
maxCPUUsageUpperBound: 10 # pct
406+
maxCPUUsageActivationLowerBound: 0.0
407+
maxCPUUsageActivationUpperBound: -0.25
408408
dependencies:
409409
features:
410410
extractors:
@@ -413,14 +413,14 @@ conf:
413413
options:
414414
# Min-max scaling for avg memory usage on the host.
415415
avgMemoryUsageLowerBound: 0 # pct
416-
avgMemoryUsageUpperBound: 100 # pct
417-
avgMemoryUsageActivationLowerBound: 0.25
418-
avgMemoryUsageActivationUpperBound: -0.5
416+
avgMemoryUsageUpperBound: 10 # pct
417+
avgMemoryUsageActivationLowerBound: 0.0
418+
avgMemoryUsageActivationUpperBound: -0.75
419419
# Min-max scaling for max memory usage on the host.
420420
maxMemoryUsageLowerBound: 0 # pct
421-
maxMemoryUsageUpperBound: 100 # pct
422-
maxMemoryUsageActivationLowerBound: 0.25
423-
maxMemoryUsageActivationUpperBound: -0.5
421+
maxMemoryUsageUpperBound: 10 # pct
422+
maxMemoryUsageActivationLowerBound: 0.0
423+
maxMemoryUsageActivationUpperBound: -0.25
424424
dependencies:
425425
features:
426426
extractors:
@@ -435,21 +435,21 @@ conf:
435435
# Min-max scaling for gap-fitting based on cpu space left (vCPUs).
436436
cpuEnabled: true
437437
cpuFreeLowerBound: 0 # vCPUs
438-
cpuFreeUpperBound: 128 # vCPUs
439-
cpuFreeActivationLowerBound: 0.25
438+
cpuFreeUpperBound: 512 # vCPUs
439+
cpuFreeActivationLowerBound: 0.0
440440
cpuFreeActivationUpperBound: -0.5
441441
# Min-max scaling for gap-fitting based on memory space left (MB).
442442
ramEnabled: true
443443
ramFreeLowerBound: 0 # MB
444444
ramFreeUpperBound: 4000000 # MB
445-
ramFreeActivationLowerBound: 0.25
445+
ramFreeActivationLowerBound: 0.0
446446
ramFreeActivationUpperBound: -0.5
447447
# Min-max scaling for gap-fitting based on disk space left. (GB)
448448
diskEnabled: false
449449
diskFreeLowerBound: 0 # GB
450450
diskFreeUpperBound: 1000 # GB
451-
diskFreeActivationLowerBound: 0.25
452-
diskFreeActivationUpperBound: -0.5
451+
diskFreeActivationLowerBound: 0.0
452+
diskFreeActivationUpperBound: -0.25
453453
dependencies:
454454
features:
455455
extractors:

internal/scheduler/plugins/vmware/avoid_contended_hosts_test.go

+32-26
Original file line numberDiff line numberDiff line change
@@ -29,62 +29,73 @@ func TestAvoidContendedHostsStep_Run(t *testing.T) {
2929
_, err = testDB.Exec(`
3030
INSERT INTO feature_vrops_hostsystem_contention (compute_host, avg_cpu_contention, max_cpu_contention)
3131
VALUES
32-
('host1', 15.0, 25.0),
33-
('host2', 5.0, 10.0),
34-
('host3', 20.0, 30.0)
32+
('host1', 0.0, 0.0),
33+
('host2', 100.0, 0.0),
34+
('host3', 0.0, 100.0),
35+
('host4', 100.0, 100.0)
3536
`)
3637
if err != nil {
3738
t.Fatalf("expected no error, got %v", err)
3839
}
3940

4041
// Create an instance of the step
4142
opts := conf.NewRawOpts(`{
42-
"avgCPUContentionLowerBound": 10,
43+
"avgCPUContentionLowerBound": 0,
4344
"avgCPUContentionUpperBound": 100,
4445
"avgCPUContentionActivationLowerBound": 0.0,
45-
"avgCPUContentionActivationUpperBound": -0.5,
46-
"maxCPUContentionLowerBound": 20,
46+
"avgCPUContentionActivationUpperBound": -1.0,
47+
"maxCPUContentionLowerBound": 0,
4748
"maxCPUContentionUpperBound": 100,
4849
"maxCPUContentionActivationLowerBound": 0.0,
49-
"maxCPUContentionActivationUpperBound": -0.5
50+
"maxCPUContentionActivationUpperBound": -1.0
5051
}`)
5152
step := &AvoidContendedHostsStep{}
5253
if err := step.Init(testDB, opts); err != nil {
5354
t.Fatalf("expected no error, got %v", err)
5455
}
5556

5657
tests := []struct {
57-
name string
58-
request testlibAPI.MockRequest
59-
downvotedHosts map[string]struct{}
58+
name string
59+
request testlibAPI.MockRequest
60+
expected map[string]float64
6061
}{
6162
{
6263
name: "Non-vmware vm",
6364
request: testlibAPI.MockRequest{
6465
VMware: false,
65-
Hosts: []string{"host1", "host2", "host3"},
66+
Hosts: []string{"host1", "host2", "host3", "host4"},
6667
},
6768
// Should not do anything
68-
downvotedHosts: map[string]struct{}{},
69+
expected: map[string]float64{
70+
"host1": 0,
71+
"host2": 0,
72+
"host3": 0,
73+
"host4": 0,
74+
},
6975
},
7076
{
7177
name: "Avoid contended hosts",
7278
request: testlibAPI.MockRequest{
7379
VMware: true,
74-
Hosts: []string{"host1", "host2", "host3"},
80+
Hosts: []string{"host1", "host2", "host3", "host4"},
7581
},
76-
downvotedHosts: map[string]struct{}{
77-
"host1": {},
78-
"host3": {},
82+
expected: map[string]float64{
83+
"host1": 0,
84+
"host2": -1,
85+
"host3": -1,
86+
"host4": -2, // Max and avg contention stack up.
7987
},
8088
},
8189
{
82-
name: "No contended hosts",
90+
name: "Missing data",
8391
request: testlibAPI.MockRequest{
8492
VMware: true,
8593
Hosts: []string{"host4", "host5"},
8694
},
87-
downvotedHosts: map[string]struct{}{},
95+
expected: map[string]float64{
96+
"host4": -2,
97+
"host5": 0, // No data but still contained in the result.
98+
},
8899
},
89100
}
90101

@@ -96,14 +107,9 @@ func TestAvoidContendedHostsStep_Run(t *testing.T) {
96107
}
97108
// Check that the weights have decreased
98109
for host, weight := range weights {
99-
if _, ok := tt.downvotedHosts[host]; ok {
100-
if weight >= 0 {
101-
t.Errorf("expected weight for host %s to be less than 0, got %f", host, weight)
102-
}
103-
} else {
104-
if weight != 0 {
105-
t.Errorf("expected weight for host %s to be 0, got %f", host, weight)
106-
}
110+
expected := tt.expected[host]
111+
if weight != expected {
112+
t.Errorf("expected weight for host %s to be %f, got %f", host, expected, weight)
107113
}
108114
}
109115
})

0 commit comments

Comments
 (0)