-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add some race-condition protection to VPA recommender #8320
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: master
Are you sure you want to change the base?
Changes from all commits
6696344
4ee3cb6
bfc350a
4068a07
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 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |||||||||||||
"fmt" | ||||||||||||||
"net/http" | ||||||||||||||
"strconv" | ||||||||||||||
"sync" | ||||||||||||||
"time" | ||||||||||||||
|
||||||||||||||
"github.com/prometheus/client_golang/prometheus" | ||||||||||||||
|
@@ -119,7 +120,8 @@ type objectCounterKey struct { | |||||||||||||
|
||||||||||||||
// ObjectCounter helps split all VPA objects into buckets | ||||||||||||||
type ObjectCounter struct { | ||||||||||||||
cnt map[objectCounterKey]int | ||||||||||||||
cnt map[objectCounterKey]int | ||||||||||||||
mutex sync.Mutex | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Register initializes all metrics for VPA Recommender | ||||||||||||||
|
@@ -189,7 +191,9 @@ func (oc *ObjectCounter) Add(vpa *model.Vpa) { | |||||||||||||
matchesPods: vpa.HasMatchedPods(), | ||||||||||||||
unsupportedConfig: vpa.Conditions.ConditionActive(vpa_types.ConfigUnsupported), | ||||||||||||||
} | ||||||||||||||
oc.mutex.Lock() | ||||||||||||||
oc.cnt[key]++ | ||||||||||||||
oc.mutex.Unlock() | ||||||||||||||
Comment on lines
+194
to
+196
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. I looked at changing this to use It works, but my concern is that the map need to gaurentee that all keys exist in the map. This is possible by pre-filling the map with all possible combinations. However, we need to remember to update this file each time a new type is added. Ie: autoscaler/vertical-pod-autoscaler/pkg/utils/metrics/recommender/recommender.go Lines 41 to 46 in 9bc4220
The problem is that there doesn't seem to be a good way to dynamically generate that list in the VPA. |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Observe passes all the computed bucket values to metrics | ||||||||||||||
|
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.
I happen to notice this weirdness in the
--update-worker-count
due to the back-ticks, so I fixed them while I was here.Reference: https://pkg.go.dev/flag#PrintDefaults