Skip to content

Commit

Permalink
fix the ci failures
Browse files Browse the repository at this point in the history
Signed-off-by: william-wang <wang.platform@gmail.com>
  • Loading branch information
william-wang committed Apr 2, 2022
1 parent c6cff6f commit 95f329f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.
16 changes: 8 additions & 8 deletions pkg/scheduler/api/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ type NodeState struct {
}

type NodeUsage struct {
CpuUsageAvg map[string]float64
MemUsageAvg map[string]float64
CPUUsageAvg map[string]float64
MEMUsageAvg map[string]float64
}

func (nu *NodeUsage) DeepCopy() *NodeUsage {
newUsage := &NodeUsage{
CpuUsageAvg: make(map[string]float64),
MemUsageAvg: make(map[string]float64),
CPUUsageAvg: make(map[string]float64),
MEMUsageAvg: make(map[string]float64),
}
for k, v := range nu.CpuUsageAvg {
newUsage.CpuUsageAvg[k] = v
for k, v := range nu.CPUUsageAvg {
newUsage.CPUUsageAvg[k] = v
}
for k, v := range nu.MemUsageAvg {
newUsage.MemUsageAvg[k] = v
for k, v := range nu.MEMUsageAvg {
newUsage.MEMUsageAvg[k] = v
}
return newUsage
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/scheduler/api/node_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func TestNodeInfo_AddPod(t *testing.T) {
OversubscriptionResource: EmptyResource(),
Allocatable: buildResource("8000m", "10G"),
Capability: buildResource("8000m", "10G"),
ResourceUsage: &NodeUsage{},
State: NodeState{Phase: Ready},
Tasks: map[TaskID]*TaskInfo{
"c1/p1": NewTaskInfo(case01Pod1),
Expand All @@ -80,6 +81,7 @@ func TestNodeInfo_AddPod(t *testing.T) {
OversubscriptionResource: EmptyResource(),
Allocatable: buildResource("2000m", "1G"),
Capability: buildResource("2000m", "1G"),
ResourceUsage: &NodeUsage{},
State: NodeState{Phase: Ready},
Tasks: map[TaskID]*TaskInfo{},
GPUDevices: make(map[int]*GPUDevice),
Expand Down Expand Up @@ -138,6 +140,7 @@ func TestNodeInfo_RemovePod(t *testing.T) {
Pipelined: EmptyResource(),
Allocatable: buildResource("8000m", "10G"),
Capability: buildResource("8000m", "10G"),
ResourceUsage: &NodeUsage{},
State: NodeState{Phase: Ready},
Tasks: map[TaskID]*TaskInfo{
"c1/p1": NewTaskInfo(case01Pod1),
Expand Down Expand Up @@ -198,6 +201,7 @@ func TestNodeInfo_SetNode(t *testing.T) {
Pipelined: EmptyResource(),
Allocatable: buildResource("10", "10G"),
Capability: buildResource("10", "10G"),
ResourceUsage: &NodeUsage{},
State: NodeState{Phase: NotReady, Reason: "OutOfSync"},
Tasks: map[TaskID]*TaskInfo{
"c1/p1": NewTaskInfo(case01Pod1),
Expand Down
9 changes: 4 additions & 5 deletions pkg/scheduler/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ func (sc *SchedulerCache) Run(stopCh <-chan struct{}) {
interval = time.Duration(defaultMetricsInternal)
}
go wait.Until(sc.GetMetricsData, interval, stopCh)

}

// WaitForCacheSync sync the cache with the api server
Expand Down Expand Up @@ -1200,8 +1199,8 @@ func (sc *SchedulerCache) GetMetricsData() {
sc.Mutex.Lock()
for k := range sc.Nodes {
nodeUsageMap[k] = &schedulingapi.NodeUsage{
CpuUsageAvg: make(map[string]float64),
MemUsageAvg: make(map[string]float64),
CPUUsageAvg: make(map[string]float64),
MEMUsageAvg: make(map[string]float64),
}
}
sc.Mutex.Unlock()
Expand All @@ -1227,11 +1226,11 @@ func (sc *SchedulerCache) GetMetricsData() {
switch metric {
case "cpu_usage_avg":
cpuUsage, _ := strconv.ParseFloat(value[0], 64)
nodeUsageMap[node].CpuUsageAvg[period] = cpuUsage
nodeUsageMap[node].CPUUsageAvg[period] = cpuUsage
klog.V(4).Infof("node: %v, CpuUsageAvg: %v, period:%v", node, cpuUsage, period)
case "mem_usage_avg":
memUsage, _ := strconv.ParseFloat(value[0], 64)
nodeUsageMap[node].MemUsageAvg[period] = memUsage
nodeUsageMap[node].MEMUsageAvg[period] = memUsage
klog.V(4).Infof("node: %v, MemUsageAvg: %v, period:%v", node, memUsage, period)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestSchedulerCache_Bind_NodeWithInsufficientResources(t *testing.T) {
t.Errorf("expected task to remain the same after failed bind: \n %#v\n %#v", taskBeforeBind, taskAfterBind)
}

nodeAfterBind := cache.Nodes["n1"]
nodeAfterBind := cache.Nodes["n1"].Clone()
if !reflect.DeepEqual(nodeBeforeBind, nodeAfterBind) {
t.Errorf("expected node to remain the same after failed bind")
}
Expand Down
36 changes: 18 additions & 18 deletions pkg/scheduler/plugins/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
const (
// PluginName indicates name of volcano scheduler plugin.
PluginName = "usage"
cpuUsageAvgPrefix = "CpuUsageAvg."
memUsageAvgPrefix = "MemUsageAvg."
cpuUsageAvgPrefix = "CPUUsageAvg."
memUsageAvgPrefix = "MEMUsageAvg."
thresholdSection = "thresholds"
cpuUsageAvg5m = "5m"
)
Expand All @@ -42,8 +42,8 @@ const (
- name: usage
arguments:
thresholds:
CpuUsageAvg.5m: 80
MemUsageAvg.5m: 90
CPUUsageAvg.5m: 80
MEMUsageAvg.5m: 90
*/

type thresholdConfig struct {
Expand All @@ -53,8 +53,8 @@ type thresholdConfig struct {

type usagePlugin struct {
pluginArguments framework.Arguments
weight int
threshold thresholdConfig
weight int
threshold thresholdConfig
}

// New function returns usagePlugin object
Expand Down Expand Up @@ -87,7 +87,7 @@ func (up *usagePlugin) OnSessionOpen(ssn *framework.Session) {
if klog.V(4) {
for node := range ssn.Nodes {
usage := ssn.Nodes[node].ResourceUsage
klog.V(4).Infof("node:%v, cpu usage:%v, mem usage:%v", node, usage.CpuUsageAvg["5m"], usage.MemUsageAvg["5m"])
klog.V(4).Infof("node:%v, cpu usage:%v, mem usage:%v", node, usage.CPUUsageAvg["5m"], usage.MEMUsageAvg["5m"])
}
}

Expand All @@ -100,19 +100,19 @@ func (up *usagePlugin) OnSessionOpen(ssn *framework.Session) {
for k, v := range args {
key, _ := k.(string)
var val float64
switch v.(type) {
switch a := v.(type) {
case string:
val, _ = strconv.ParseFloat(v.(string), 64)
val, _ = strconv.ParseFloat(a, 64)
case int:
val = float64(v.(int))
val = float64(a)
case float64:
val = v.(float64)
val = a
default:
klog.V(4).Infof("The threshold %v is an unknown type", v)
klog.V(4).Infof("The threshold %v is an unknown type", a)
}
if strings.Contains(key, cpuUsageAvgPrefix) {
periodKey := strings.Replace(key, cpuUsageAvgPrefix, "", 1)
up.threshold.cpuUsageAvg[periodKey] = val
up.threshold.cpuUsageAvg[periodKey] = val
}
if strings.Contains(key, memUsageAvgPrefix) {
periodKey := strings.Replace(key, memUsageAvgPrefix, "", 1)
Expand All @@ -127,16 +127,16 @@ func (up *usagePlugin) OnSessionOpen(ssn *framework.Session) {
predicateFn := func(task *api.TaskInfo, node *api.NodeInfo) error {
for period, value := range up.threshold.cpuUsageAvg {
klog.V(4).Infof("predicateFn cpuUsageAvg:%v", up.threshold.cpuUsageAvg)
if node.ResourceUsage.CpuUsageAvg[period] > value {
msg := fmt.Sprintf("Node %s cpu usage %f exceeds the threshold %f", node.Name, node.ResourceUsage.CpuUsageAvg[period], value)
if node.ResourceUsage.CPUUsageAvg[period] > value {
msg := fmt.Sprintf("Node %s cpu usage %f exceeds the threshold %f", node.Name, node.ResourceUsage.CPUUsageAvg[period], value)
return fmt.Errorf("plugin %s predicates failed %s", up.Name(), msg)
}
}

for period, value := range up.threshold.memUsageAvg {
klog.V(4).Infof("predicateFn memUsageAvg:%v", up.threshold.memUsageAvg)
if node.ResourceUsage.MemUsageAvg[period] > value {
msg := fmt.Sprintf("Node %s mem usage %f exceeds the threshold %f", node.Name, node.ResourceUsage.MemUsageAvg[period], value)
if node.ResourceUsage.MEMUsageAvg[period] > value {
msg := fmt.Sprintf("Node %s mem usage %f exceeds the threshold %f", node.Name, node.ResourceUsage.MEMUsageAvg[period], value)
return fmt.Errorf("plugin %s memory usage predicates failed %s", up.Name(), msg)
}
}
Expand All @@ -146,7 +146,7 @@ func (up *usagePlugin) OnSessionOpen(ssn *framework.Session) {

nodeOrderFn := func(task *api.TaskInfo, node *api.NodeInfo) (float64, error) {
score := 0.0
cpuUsage, exist := node.ResourceUsage.CpuUsageAvg[cpuUsageAvg5m]
cpuUsage, exist := node.ResourceUsage.CPUUsageAvg[cpuUsageAvg5m]
klog.V(4).Infof("Node %s cpu usage is %f.", node.Name, cpuUsage)
if !exist {
return 0, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/scheduler/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ tiers:

var expectedConfigurations []conf.Configuration

_, tiers, configurations, err := unmarshalSchedulerConf(configuration)
_, tiers, configurations, _, err := unmarshalSchedulerConf(configuration)
if err != nil {
t.Errorf("Failed to load scheduler configuration: %v", err)
}
Expand Down

0 comments on commit 95f329f

Please sign in to comment.