Skip to content

Commit

Permalink
ioweight: adding pod level setting
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Lu <robin.lu@bytedance.com>
  • Loading branch information
lubinszARM committed Jun 12, 2024
1 parent ddfa0c4 commit a47564a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/agent/qrm-plugins/io/handlers/ioweight/ioweight_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ package ioweight

import (
"context"
"fmt"
"strconv"

v1 "k8s.io/api/core/v1"

"github.com/kubewharf/katalyst-core/pkg/agent/qrm-plugins/commonstate"
coreconfig "github.com/kubewharf/katalyst-core/pkg/config"
dynamicconfig "github.com/kubewharf/katalyst-core/pkg/config/agent/dynamic"
Expand Down Expand Up @@ -64,6 +67,26 @@ func applyIOWeightCgroupLevelConfig(conf *coreconfig.Configuration, emitter metr
}
}

func applyPodIOWeight(pod *v1.Pod, defaultDevID, qosLevelDefaultValue string) error {
ioWeightValue, err := strconv.ParseInt(qosLevelDefaultValue, 10, 64)
if err != nil {
return fmt.Errorf("strconv.ParseInt failed, string=%v, err=%v", qosLevelDefaultValue, err)
}

podAbsCGPath, err := common.GetPodAbsCgroupPath(common.CgroupSubsysIO, string(pod.UID))
if err != nil {
return fmt.Errorf("GetPodAbsCgroupPath for pod: %s/%s failed with error: %v", pod.Namespace, pod.Name, err)
}

err = cgroupmgr.ApplyIOWeightWithAbsolutePath(podAbsCGPath, defaultDevID, uint64(ioWeightValue))
if err != nil {
return fmt.Errorf("ApplyIOWeightWithAbsolutePath for pod: %s/%s failed with error: %v", pod.Namespace, pod.Name, err)
}

general.Infof("ApplyIOWeightWithRelativePath for pod: %s/%s, weight: %d successfully", pod.Namespace, pod.Name, ioWeightValue)
return nil
}

func applyIOWeightQoSLevelConfig(conf *coreconfig.Configuration,
emitter metrics.MetricEmitter, metaServer *metaserver.MetaServer,
) {
Expand Down Expand Up @@ -102,6 +125,15 @@ func applyIOWeightQoSLevelConfig(conf *coreconfig.Configuration,
if !ok {
continue
}

// setup pod level.
err = applyPodIOWeight(pod, defaultDevID, qosLevelDefaultValue)
if err != nil {
general.Errorf("Failed to apply IO weight for pod %s/%s: %v", pod.Namespace, pod.Name, err)
continue
}

// setup contaienr level.
for _, containerStatus := range pod.Status.ContainerStatuses {
podUID, containerID := string(pod.UID), native.TrimContainerIDPrefix(containerStatus.ContainerID)
err := cgroupmgr.ApplyUnifiedDataForContainer(podUID, containerID, extraControlKnobConfigs[controlKnobKeyIOWeight].CgroupSubsysName, cgroupIOWeightName, qosLevelDefaultValue)
Expand Down
21 changes: 21 additions & 0 deletions pkg/agent/qrm-plugins/io/handlers/ioweight/ioweight_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,24 @@ func TestIOWeightTaskFunc(t *testing.T) {
},
}, metrics.DummyMetrics{}, metaServerEmpty)
}

func TestApplyPodIOWeight(t *testing.T) {
t.Parallel()

pod := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
UID: "test-uid",
Namespace: "default",
Name: "test-pod",
},
}

defaultDevID := "test-dev-id"
qosLevelDefaultValue := "500"

err := applyPodIOWeight(pod, defaultDevID, qosLevelDefaultValue)
assert.Error(t, err)

err = applyPodIOWeight(pod, defaultDevID, "test")
assert.Error(t, err)
}

0 comments on commit a47564a

Please sign in to comment.