optimize dynamicAdjust to be clear and add log
Signed-off-by: yangjiaqi <yangjiaqi16@huawei.com> (cherry picked from commit e59cabab80a5f030c4cb5789c4f3d214262bf9db)
This commit is contained in:
parent
d266585686
commit
b660199645
@ -1 +1 @@
|
|||||||
2.0.0-2
|
2.0.0-3
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
8eb2e8d8f046224de4cd37bb404ecc261668a6b3
|
fdaef8a93069235bac826890a028f8fa7e7d1620
|
||||||
|
|||||||
135
patch/0008-rubik-test-coverage-improvement-for-pkg-config.patch
Normal file
135
patch/0008-rubik-test-coverage-improvement-for-pkg-config.patch
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
From e30c428721ac2fd0da5152a28de04dbbf9c9d1ea Mon Sep 17 00:00:00 2001
|
||||||
|
From: jingxiaolu <lujingxiao@huawei.com>
|
||||||
|
Date: Sun, 11 Jun 2023 22:34:08 +0800
|
||||||
|
Subject: [PATCH 1/2] rubik: test coverage improvement for pkg/config
|
||||||
|
|
||||||
|
1. improve test coverage for pkg/config from 57.4% to 80.3%
|
||||||
|
2. change cpuLimit to 1 in TestStatusStore_AddCgroup-TC5 for nano vm
|
||||||
|
|
||||||
|
Signed-off-by: jingxiaolu <lujingxiao@huawei.com>
|
||||||
|
---
|
||||||
|
pkg/config/config_test.go | 69 ++++++++++++++++++++--
|
||||||
|
pkg/lib/cpu/quotaturbo/statusstore_test.go | 2 +-
|
||||||
|
2 files changed, 66 insertions(+), 5 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go
|
||||||
|
index 03ff4ca..8766e04 100644
|
||||||
|
--- a/pkg/config/config_test.go
|
||||||
|
+++ b/pkg/config/config_test.go
|
||||||
|
@@ -27,7 +27,8 @@ import (
|
||||||
|
"isula.org/rubik/pkg/common/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
-var rubikConfig string = `
|
||||||
|
+func TestNewConfig(t *testing.T) {
|
||||||
|
+ var rubikConfig string = `
|
||||||
|
{
|
||||||
|
"agent": {
|
||||||
|
"logDriver": "stdio",
|
||||||
|
@@ -85,27 +86,87 @@ var rubikConfig string = `
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
+ if !util.PathExist(constant.TmpTestDir) {
|
||||||
|
+ if err := os.Mkdir(constant.TmpTestDir, constant.DefaultDirMode); err != nil {
|
||||||
|
+ assert.NoError(t, err)
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
|
||||||
|
-func TestNewConfig(t *testing.T) {
|
||||||
|
+ defer os.RemoveAll(constant.TmpTestDir)
|
||||||
|
+
|
||||||
|
+ tmpConfigFile := filepath.Join(constant.TmpTestDir, "config.json")
|
||||||
|
+ defer os.Remove(tmpConfigFile)
|
||||||
|
+ if err := ioutil.WriteFile(tmpConfigFile, []byte(rubikConfig), constant.DefaultFileMode); err != nil {
|
||||||
|
+ assert.NoError(t, err)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ c := NewConfig(JSON)
|
||||||
|
+ if err := c.LoadConfig(tmpConfigFile); err != nil {
|
||||||
|
+ assert.NoError(t, err)
|
||||||
|
+ }
|
||||||
|
+ fmt.Printf("config: %v", c)
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func TestNewConfigNoConfig(t *testing.T) {
|
||||||
|
+ c := &Config{}
|
||||||
|
+ if err := c.LoadConfig(""); err == nil {
|
||||||
|
+ t.Fatalf("Config file exists")
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func TestNewConfigDamagedConfig(t *testing.T) {
|
||||||
|
+ var rubikConfig string = `{`
|
||||||
|
if !util.PathExist(constant.TmpTestDir) {
|
||||||
|
if err := os.Mkdir(constant.TmpTestDir, constant.DefaultDirMode); err != nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
+ defer os.RemoveAll(constant.TmpTestDir)
|
||||||
|
+
|
||||||
|
+ tmpConfigFile := filepath.Join(constant.TmpTestDir, "config.json")
|
||||||
|
+ defer os.Remove(tmpConfigFile)
|
||||||
|
+ if err := ioutil.WriteFile(tmpConfigFile, []byte(rubikConfig), constant.DefaultFileMode); err != nil {
|
||||||
|
+ assert.NoError(t, err)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ c := NewConfig(JSON)
|
||||||
|
+ if err := c.LoadConfig(tmpConfigFile); err == nil {
|
||||||
|
+ t.Fatalf("Damaged config file should not be loaded.")
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
|
||||||
|
+func TestNewConfigNoAgentConfig(t *testing.T) {
|
||||||
|
+ var rubikConfig string = `{}`
|
||||||
|
+ if !util.PathExist(constant.TmpTestDir) {
|
||||||
|
+ if err := os.Mkdir(constant.TmpTestDir, constant.DefaultDirMode); err != nil {
|
||||||
|
+ assert.NoError(t, err)
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
defer os.RemoveAll(constant.TmpTestDir)
|
||||||
|
|
||||||
|
tmpConfigFile := filepath.Join(constant.TmpTestDir, "config.json")
|
||||||
|
defer os.Remove(tmpConfigFile)
|
||||||
|
if err := ioutil.WriteFile(tmpConfigFile, []byte(rubikConfig), constant.DefaultFileMode); err != nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
- return
|
||||||
|
}
|
||||||
|
|
||||||
|
c := NewConfig(JSON)
|
||||||
|
if err := c.LoadConfig(tmpConfigFile); err != nil {
|
||||||
|
assert.NoError(t, err)
|
||||||
|
- return
|
||||||
|
}
|
||||||
|
fmt.Printf("config: %v", c)
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+func TestUnwrapServiceConfig(t *testing.T) {
|
||||||
|
+ c := &Config{}
|
||||||
|
+ c.Fields = make(map[string]interface{})
|
||||||
|
+ c.Fields["agent"] = nil
|
||||||
|
+ c.Fields["config"] = nil
|
||||||
|
+ sc := c.UnwrapServiceConfig()
|
||||||
|
+ if _, exist := sc["agent"]; exist {
|
||||||
|
+ t.Fatalf("agent is exists")
|
||||||
|
+ }
|
||||||
|
+ if _, exist := sc["config"]; !exist {
|
||||||
|
+ t.Fatalf("config is not exists")
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/pkg/lib/cpu/quotaturbo/statusstore_test.go b/pkg/lib/cpu/quotaturbo/statusstore_test.go
|
||||||
|
index 68c01c5..ce1684d 100644
|
||||||
|
--- a/pkg/lib/cpu/quotaturbo/statusstore_test.go
|
||||||
|
+++ b/pkg/lib/cpu/quotaturbo/statusstore_test.go
|
||||||
|
@@ -354,7 +354,7 @@ func TestStatusStore_AddCgroup(t *testing.T) {
|
||||||
|
name: "TC5-add successfully",
|
||||||
|
args: args{
|
||||||
|
cgroupPath: contPath,
|
||||||
|
- cpuLimit: 2,
|
||||||
|
+ cpuLimit: 1,
|
||||||
|
},
|
||||||
|
fields: fields{
|
||||||
|
Config: &Config{
|
||||||
|
--
|
||||||
|
2.30.0
|
||||||
|
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
From 72dbcc6acf989f7c3423b24091c0b9875d1f4872 Mon Sep 17 00:00:00 2001
|
||||||
|
From: hanchao <hanchao63@huawei.com>
|
||||||
|
Date: Mon, 19 Jun 2023 20:29:41 +0800
|
||||||
|
Subject: [PATCH 2/2] rubik: optimize `dynamicAdjust` to be clear and add log
|
||||||
|
for error
|
||||||
|
|
||||||
|
---
|
||||||
|
pkg/services/dynmemory/fssr.go | 18 ++++++++++++++----
|
||||||
|
1 file changed, 14 insertions(+), 4 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/pkg/services/dynmemory/fssr.go b/pkg/services/dynmemory/fssr.go
|
||||||
|
index e23a4bc..2c81ccf 100644
|
||||||
|
--- a/pkg/services/dynmemory/fssr.go
|
||||||
|
+++ b/pkg/services/dynmemory/fssr.go
|
||||||
|
@@ -4,6 +4,7 @@ import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
+ "math"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
@@ -76,26 +77,35 @@ func (f *fssrDynMemAdapter) dynamicAdjust() {
|
||||||
|
f.count++
|
||||||
|
return
|
||||||
|
}
|
||||||
|
- // no risk of overflow
|
||||||
|
+ // check int64 overflow
|
||||||
|
+ if f.memHigh > math.MaxInt64-f.memTotal/100 {
|
||||||
|
+ log.Errorf("int64 overflow")
|
||||||
|
+ return
|
||||||
|
+ }
|
||||||
|
memHigh = f.memHigh + f.memTotal/100
|
||||||
|
if memHigh > f.memTotal*8/10 {
|
||||||
|
memHigh = f.memTotal * 8 / 10
|
||||||
|
}
|
||||||
|
+ f.adjustMemoryHigh(memHigh)
|
||||||
|
} else if freeMem < f.reservedMem {
|
||||||
|
memHigh = f.memHigh - f.memTotal/10
|
||||||
|
- if memHigh < 0 {
|
||||||
|
+ if memHigh <= 0 {
|
||||||
|
+ log.Errorf("memHigh is equal to or less than 0")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if memHigh < f.memTotal*3/10 {
|
||||||
|
memHigh = f.memTotal * 3 / 10
|
||||||
|
}
|
||||||
|
+ f.adjustMemoryHigh(memHigh)
|
||||||
|
}
|
||||||
|
+ f.count = 0
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+func (f *fssrDynMemAdapter) adjustMemoryHigh(memHigh int64) {
|
||||||
|
if memHigh != f.memHigh {
|
||||||
|
f.memHigh = memHigh
|
||||||
|
f.adjustOfflinePodHighMemory()
|
||||||
|
}
|
||||||
|
-
|
||||||
|
- f.count = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// adjustOfflinePodHighMemory adjusts the memory.high of offline pods.
|
||||||
|
--
|
||||||
|
2.30.0
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
Name: rubik
|
Name: rubik
|
||||||
Version: 2.0.0
|
Version: 2.0.0
|
||||||
Release: 2
|
Release: 3
|
||||||
Summary: Hybrid Deployment for Cloud Native
|
Summary: Hybrid Deployment for Cloud Native
|
||||||
License: Mulan PSL V2
|
License: Mulan PSL V2
|
||||||
URL: https://gitee.com/openeuler/rubik
|
URL: https://gitee.com/openeuler/rubik
|
||||||
@ -56,6 +56,12 @@ install -Dp ./build_rubik_image.sh %{buildroot}%{_sharedstatedir}/%{name}/build_
|
|||||||
rm -rf %{buildroot}
|
rm -rf %{buildroot}
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Jun 19 2023 yangjiaqi <yangjiaqi16@huawei.com> - 2.0.0-3
|
||||||
|
- Type:bugfix
|
||||||
|
- CVE:NA
|
||||||
|
- SUG:restart
|
||||||
|
- DESC:optimize dynamicAdjust to be clear and add log
|
||||||
|
|
||||||
* Mon Jun 19 2023 vegbir <yangjiaqi16@huawei.com> - 2.0.0-2
|
* Mon Jun 19 2023 vegbir <yangjiaqi16@huawei.com> - 2.0.0-2
|
||||||
- Type:bugfix
|
- Type:bugfix
|
||||||
- CVE:NA
|
- CVE:NA
|
||||||
|
|||||||
@ -5,4 +5,6 @@ patch/0004-rubik-add-psi-design-documentation.patch
|
|||||||
patch/0005-rubik-move-fssr-design-document-to-design-dir.patch
|
patch/0005-rubik-move-fssr-design-document-to-design-dir.patch
|
||||||
patch/0006-rubik-fix-that-value-of-memory.high_async_ratio-lost.patch
|
patch/0006-rubik-fix-that-value-of-memory.high_async_ratio-lost.patch
|
||||||
patch/0007-bugfix-fix-typos-calling-order-of-waitgroup.patch
|
patch/0007-bugfix-fix-typos-calling-order-of-waitgroup.patch
|
||||||
|
patch/0008-rubik-test-coverage-improvement-for-pkg-config.patch
|
||||||
|
patch/0009-rubik-optimize-dynamicAdjust-to-be-clear-and-add-log.patch
|
||||||
#end of file
|
#end of file
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user