Skip to content

Commit

Permalink
update the codes according to the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
william-wang committed Apr 21, 2022
1 parent 95f329f commit 9970c72
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions pkg/scheduler/api/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type NodeState struct {
Reason string
}

// NodeUsage defines the real load usage of node
type NodeUsage struct {
CPUUsageAvg map[string]float64
MEMUsageAvg map[string]float64
Expand Down
31 changes: 15 additions & 16 deletions pkg/scheduler/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
"sync"
"time"

"github.com/prometheus/client_golang/api"
prometheusv1 "github.com/prometheus/client_golang/api/prometheus/v1"

v1 "k8s.io/api/core/v1"
schedulingv1 "k8s.io/api/scheduling/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -47,8 +50,6 @@ import (
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
volumescheduling "k8s.io/kubernetes/pkg/scheduler/framework/plugins/volumebinding"

"github.com/prometheus/client_golang/api"
prometheusv1 "github.com/prometheus/client_golang/api/prometheus/v1"
batch "volcano.sh/apis/pkg/apis/batch/v1alpha1"
"volcano.sh/apis/pkg/apis/scheduling"
schedulingscheme "volcano.sh/apis/pkg/apis/scheduling/scheme"
Expand All @@ -68,7 +69,7 @@ const (
cpuUsageAvg = "cpu_usage_avg"
// record name of mem average usage defined in prometheus rules
memUsageAvg = "mem_usage_avg"
// default interval for sync data from metrics server
// default interval for sync data from metrics server, the value is 5s
defaultMetricsInternal = 5
)

Expand Down Expand Up @@ -1220,19 +1221,17 @@ func (sc *SchedulerCache) GetMetricsData() {
klog.V(3).Infof("Warning querying Prometheus: %v", warnings)
}

if err == nil {
rowValues := strings.Split(strings.TrimSpace(res.String()), "=>")
value := strings.Split(strings.TrimSpace(rowValues[1]), " ")
switch metric {
case "cpu_usage_avg":
cpuUsage, _ := strconv.ParseFloat(value[0], 64)
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
klog.V(4).Infof("node: %v, MemUsageAvg: %v, period:%v", node, memUsage, period)
}
rowValues := strings.Split(strings.TrimSpace(res.String()), "=>")
value := strings.Split(strings.TrimSpace(rowValues[1]), " ")
switch metric {
case "cpu_usage_avg":
cpuUsage, _ := strconv.ParseFloat(value[0], 64)
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
klog.V(4).Infof("node: %v, MemUsageAvg: %v, period:%v", node, memUsage, period)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/scheduler/plugins/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package usage

import (
"fmt"
"k8s.io/klog"
k8sFramework "k8s.io/kubernetes/pkg/scheduler/framework"
"strconv"
"strings"

"k8s.io/klog"
k8sFramework "k8s.io/kubernetes/pkg/scheduler/framework"

"volcano.sh/volcano/pkg/scheduler/api"
"volcano.sh/volcano/pkg/scheduler/framework"
)
Expand Down

0 comments on commit 9970c72

Please sign in to comment.