Skip to content

Commit

Permalink
feat: support node memory collect policy
Browse files Browse the repository at this point in the history
  • Loading branch information
j4ckstraw committed Nov 22, 2024
1 parent 2b3669e commit db3e629
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/klog/v2"

slov1alpha1 "github.com/koordinator-sh/koordinator/apis/slo/v1alpha1"
"github.com/koordinator-sh/koordinator/pkg/koordlet/metriccache"
"github.com/koordinator-sh/koordinator/pkg/koordlet/metrics"
"github.com/koordinator-sh/koordinator/pkg/koordlet/metricsadvisor/framework"
Expand Down Expand Up @@ -86,13 +87,26 @@ func (h *hostAppCollector) Started() bool {
return h.started.Load()
}

var (
defaultMemoryCollectPolicy slov1alpha1.NodeMemoryCollectPolicy = slov1alpha1.UsageWithoutPageCache
)

func (h *hostAppCollector) collectHostAppResUsed() {
klog.V(6).Info("start collectHostAppResUsed")
nodeSLO := h.statesInformer.GetNodeSLO()
if nodeSLO == nil {
klog.Warningf("get nil node slo during collect host application resource usage")
return
}

nodeMetric := h.statesInformer.GetNodeMetric()
nodeMemoryCollectPolicy := defaultMemoryCollectPolicy
if nodeMetric == nil {
klog.Warningf("get nil nodemetric, use default node memory collect policy: %v", defaultMemoryCollectPolicy)
} else if nodeMetric.Spec.CollectPolicy != nil && nodeMetric.Spec.CollectPolicy.NodeMemoryCollectPolicy != nil {
nodeMemoryCollectPolicy = *nodeMetric.Spec.CollectPolicy.NodeMemoryCollectPolicy
}

count := 0
resourceMetrics := make([]metriccache.MetricSample, 0)
allCPUUsageCores := metriccache.Point{Timestamp: timeNow(), Value: 0}
Expand Down Expand Up @@ -157,7 +171,16 @@ func (h *hostAppCollector) collectHostAppResUsed() {
klog.V(6).Infof("collect host application %v finished, metric cpu=%v, memory=%v", hostApp.Name, cpuUsageValue, memoryUsageValue)
count++
allCPUUsageCores.Value += cpuUsageValue
allMemoryUsage.Value += float64(memoryUsageValue)
// sum memory usage according to NodeMemoryCollectPolicy
switch nodeMemoryCollectPolicy {
case slov1alpha1.UsageWithoutPageCache:
allMemoryUsage.Value += float64(memoryUsageValue)
case slov1alpha1.UsageWithPageCache:
allMemoryUsage.Value += float64(memUsageWithPageCache)
default:
klog.Warning("unrecognized node memory colleect policy, use UsageWithoutPageCache as default")
allMemoryUsage.Value += float64(memoryUsageValue)
}
}

appender := h.appendableDB.Appender()
Expand Down

0 comments on commit db3e629

Please sign in to comment.