sentinel-golang icon indicating copy to clipboard operation
sentinel-golang copied to clipboard

[BUG]System Guard flow control | CPU thredshold| 系统自适应流控|以CPU作为阈值场景下的取值范围问题

Open sunyucheng opened this issue 1 year ago • 6 comments

背景: 我在测试使用CPU作为阈值的系统自适应流控方案。 问题: 1、在 func IsValidSystemRule(rule *Rule) error中校验的 cpu取值范围为0.0~1.0。但是在实际测试中发现func getProcessCpuStat() (float64, error)函数的实际返回值大小为0.0~100.0。导致在注册规则时因阈值非法invalid CPU usage, valid range is [0.0, 1.0]而失败。 该处是否应该修改一下cpu的合法性校验范围。

sunyucheng avatar Jun 28 '23 08:06 sunyucheng

我使用的gosutil是最新的版本v3.21.6,从gosutil的源码看,这里的p.Percent(0)的取值也似乎应该是0.0~100.0,在gosutil中的关键逻辑如下所示

func calculatePercent(t1, t2 *cpu.TimesStat, delta float64, numcpu int) float64 {
	if delta == 0 {
		return 0
	}
	delta_proc := t2.Total() - t1.Total()
	overall_percent := ((delta_proc / delta) * 100) * float64(numcpu)
	return overall_percent
}

https://github.com/shirou/gopsutil/blob/fb83fb22d68f468adf2a01a9ed4963e7d980cfd7/process/process.go#L308

sunyucheng avatar Jun 28 '23 08:06 sunyucheng

Hi @sczyh30 ,可以给我一些意见么

sunyucheng avatar Jun 28 '23 13:06 sunyucheng

this could be a bug, are you interested in fixing it

binbin0325 avatar Jun 30 '23 02:06 binbin0325

this could be a bug, are you interested in fixing it

Certainly

sunyucheng avatar Jun 30 '23 03:06 sunyucheng

Hi @binbin0325, I have already mentioned PR https://github.com/alibaba/sentinel-golang/pull/540

sunyucheng avatar Jun 30 '23 11:06 sunyucheng

May I ask why this fix has not passed? Is it not ready to be repaired?

erouss avatar Jan 18 '24 09:01 erouss