Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update codecov configuration #131

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ jobs:
- name: Run Go test
run: make test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
flags: unittests
file: cover.out
fail_ci_if_error: true
verbose: true
17 changes: 17 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
flag_management:
default_rules:
carryforward: true
statuses:
- name_prefix: project-
type: project
target: auto
threshold: 5%
if_no_uploads: error
if_not_found: success # no commit found? still set a success
- name_prefix: patch-
type: patch
target: 70%
if_no_uploads: success
if_not_found: success
github_checks:
annotations: true
2 changes: 1 addition & 1 deletion pkg/util/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func GetPodCgroupCPUStatPath(podParentDir string) string {

func GetKubeQosClass(pod *corev1.Pod) corev1.PodQOSClass {
qosClass := pod.Status.QOSClass
if qosClass == "" {
if len(qosClass) <= 0 {
qosClass = qos.GetPodQOS(pod)
}
return qosClass
Expand Down
34 changes: 23 additions & 11 deletions pkg/util/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package util

import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
Expand Down Expand Up @@ -98,11 +99,14 @@ func Test_readPodCPUStatUsageTicks(t *testing.T) {
tempDir := t.TempDir()
tempInvalidPodCgroupDir := filepath.Join(tempDir, "no_cgroup")
tempPodStatPath := filepath.Join(tempDir, system.CpuacctStatFileName)
statContentStr := getStatContents()
err := ioutil.WriteFile(tempPodStatPath, []byte(statContentStr), 0666)
if err != nil {
t.Error(err)
}
err := ioutil.WriteFile(tempPodStatPath, []byte(getStatContents()), 0666)
assert.NoError(t, err)
tempInvalidPodCgroupDir1 := filepath.Join(tempDir, "no_cgroup_1")
err = os.Mkdir(tempInvalidPodCgroupDir1, 0755)
assert.NoError(t, err)
tempPodInvalidStatPath := filepath.Join(tempInvalidPodCgroupDir1, system.CpuacctStatFileName)
err = ioutil.WriteFile(tempPodInvalidStatPath, []byte(getInvalidStatContents()), 0666)
assert.NoError(t, err)
type args struct {
podCgroupDir string
}
Expand All @@ -124,16 +128,18 @@ func Test_readPodCPUStatUsageTicks(t *testing.T) {
want: 1356232,
wantErr: false,
},
{
name: "read invalid cpu stat content",
args: args{podCgroupDir: tempPodInvalidStatPath},
want: 0,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := readCPUAcctStatUsageTicks(tt.args.podCgroupDir)
if (err != nil) != tt.wantErr {
t.Errorf("readCPUAcctStatUsageTicks wantErr %v but got err %s", tt.wantErr, err)
}
if !tt.wantErr && got != tt.want {
t.Errorf("readCPUAcctStatUsageTicks want %v but got %v", tt.want, got)
}
assert.Equal(t, tt.wantErr, err != nil)
assert.Equal(t, tt.want, got)
})
}
}
Expand All @@ -151,6 +157,12 @@ func getStatContents() string {
"nr_running 0\nnr_uninterrupible 0\nnr_switches 234453363\n"
}

func getInvalidStatContents() string {
return "user 407232\nnice a\nsystem a\nidle a\niowait a\nirq 0\nsoftirq 0\n" +
"steal 1115801\nguest 0\nload average(1min) 5\nload average(5min) 1\nload average(15min) 0\n" +
"nr_running 0\nnr_uninterrupible 0\nnr_switches 234453363\n"
}

func TestGetContainerCPUStatUsageTicks(t *testing.T) {
helper := system.NewFileTestUtil(t)
podCgroupDir := "pod-cgroup-dir"
Expand Down