-
Notifications
You must be signed in to change notification settings - Fork 136
fix: treat prometheus counters as rates in autoscaling signals #1042
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,3 +234,19 @@ func (window *SnapshotSlidingWindow[T]) GetLastUnfreshSnapshot() (value T, ok bo | |
| } | ||
| return front.value, true | ||
| } | ||
|
|
||
| func (window *SnapshotSlidingWindow[T]) GetLastUnfreshSnapshotWithTimestamp() (value T, timestamp int64, ok bool) { | ||
| if window.freshMilliseconds == 0 { | ||
| return value, 0, false | ||
| } | ||
| currentTimestamp := window.getCurrentTimestamp() | ||
| window.expire(currentTimestamp) | ||
| if window.pool.Len() == 0 { | ||
| return value, 0, false | ||
| } | ||
| front := window.pool.Front() | ||
| if isFresh(window.freshMilliseconds, currentTimestamp, front.timestamp) { | ||
| return value, 0, false | ||
| } | ||
| return front.value, front.timestamp, true | ||
| } | ||
|
Comment on lines
+238
to
+252
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic inside this new function is nearly identical to |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For improved precision in rate calculation, it's better to determine the current scrape timestamp once per pod and use it consistently. Currently,
util.GetCurrentTimestamp()is called insideprocessPrometheusStringfor each metric, and again when creatingHistogramInfo. This can introduce minor inaccuracies because the timestamp used for the rate calculation (now) will be slightly different from the timestamp stored for the next cycle (ScrapeTimestamp).To improve this, you can get the timestamp once before processing the metrics and use it in both places. This ensures the
elapsed_secondsfor the rate calculation is based on the exact interval between the stored scrape timestamps.Example of the proposed change: