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

fix getProcessCpuStat return value (in percentage) breaks compatibility. #540

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sunyucheng
Copy link

@sunyucheng sunyucheng commented Jun 30, 2023

Describe what this PR does / why we need it

fix getProcessCpuStat return value (in percentage) breaks compatibility.

Does this pull request fix one issue?

Fix #539

Describe how you did it

fix the bug that the CPU usage from getProcessCpuStat was changed to percentage value (i.e. 0-100), which breaks compatibility and affects system adaptive rules.

Describe how to verify it

Added a unit test func TestRetrieveAndUpdateCpuStatReturnValueRange(t *testing.T)

Special notes for reviews

@CLAassistant
Copy link

CLAassistant commented Jun 30, 2023

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

codecov-commenter commented Jul 3, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.08 🎉

Comparison is base (0807185) 53.17% compared to head (5d210df) 53.25%.

❗ Current head 5d210df differs from pull request most recent head 0e75426. Consider uploading reports for the commit 0e75426 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #540      +/-   ##
==========================================
+ Coverage   53.17%   53.25%   +0.08%     
==========================================
  Files          91       91              
  Lines        5894     5896       +2     
==========================================
+ Hits         3134     3140       +6     
+ Misses       2413     2408       -5     
- Partials      347      348       +1     
Impacted Files Coverage Δ
core/system_metric/sys_metric_stat.go 21.80% <100.00%> (+4.24%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@HelloCarry
Copy link

Hi @binbin0325 @sczyh30, looking forward to your reply.

@@ -176,6 +177,10 @@ func retrieveAndUpdateCpuStat() {
return
}

// fix getProcessCpuStat return value (in percentage) breaks compatibility.
cpuNum := runtime.NumCPU()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it for CPU requests or CPU limits under container env?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How this works in container?

@HelloCarry
Copy link

HelloCarry commented Jul 5, 2023

Hi @sczyh30 @binbin0325, if there are no doubts, we look forward to the adoption of PR

@HelloCarry
Copy link

Hi @sczyh30 @binbin0325, looking forward to your reply

@HelloCarry
Copy link

Hi @sczyh30 @binbin0325, looking forward to your reply

@@ -176,6 +177,10 @@ func retrieveAndUpdateCpuStat() {
return
}

// fix getProcessCpuStat return value (in percentage) breaks compatibility.
cpuNum := runtime.NumCPU()
cpuPercent = cpuPercent / float64(cpuNum) / 100.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we divide by cpuNum

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实不应该除以 cpuNum 直接取百分比就好

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants