Skip to content

Conversation

@inqrphl
Copy link
Contributor

@inqrphl inqrphl commented Dec 2, 2025

The cpu utilization check will always return the default value, if it cannot get proper values from the cpuinfo counter.
It will complain to the logs better.

By default I set the acceptablePercentage to %50. If there is a check of 100s, and the values I get from the counter is currently < 50s apart, it will complain differently to the log. It will still return the calculated values for that <50s period though. If its above >50s it is deemed representative.

Ahmet Oeztuerk added 2 commits November 28, 2025 17:13
- log error explanations before returning default values in cpu utilization
- WIP: wait during the cpu utilization check if the gathered points are not enough apart for the range. now the checks will return a valid value instead of zeros, causing problems rn
- add counter.GetFirst() to get the oldest value of the counter
- add counter.checkRetenton() to see if the designed counter retention time is adequate
- fix counter.AvgForDuration function possibly including the latest value twice in its calculation
- add tests for the new counter functions
- check_cpu_utilization -> check ahread if the counter can fit the requested period
- check_cpu_utlization -> print logs if the counter is not filled up enough for the requested period
- check_cpu_utilization -> print logs about after looking for a value in the past according to the requested period
Copy link
Contributor

@sni sni left a comment

Choose a reason for hiding this comment

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

looks good, i have only some minor notes

// round retention time to a multiple of interval
retention := int64(math.Ceil(float64(retentionMilli)/float64(intervalMilli))) * intervalMilli
size := retention / intervalMilli
// round retentionMili time to a multiple of interval
Copy link
Contributor

Choose a reason for hiding this comment

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

typo Milli

for seen := int64(0); seen <= c.size; seen++ {

//nolint:intrange // tracking the seen elements is easier
for seen := int64(0); seen < c.size; seen++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

what the linter suggested here is:
for range c.size {
which is simpler and cleaner.

if val.UnixMilli < useAfterUnix {
return last
var previouslyComparedValue *Value
for valuesSeen := int64(0); valuesSeen <= c.size; valuesSeen++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

a simple for range c.size should work here as well.

}

if err = counter.CheckRetention(time.Second*time.Duration(scanLookBack64), 0); err != nil {
log.Tracef("cpuinfo counter cant hold the query range: %s", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: cant

}

if err = counter.CheckRetention(time.Second*time.Duration(scanLookBack64), 100); err != nil {
log.Warnf("cpuinfo counter cant hold the query range even when extended: %s", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants