-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add more precise logging for VPA resource recommendations #6723
Changes from 6 commits
dde06f5
33a2220
1277ff6
093618e
1800a6e
390b061
9a57ecd
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 | ||||
---|---|---|---|---|---|---|
|
@@ -18,7 +18,9 @@ package priority | |||||
|
||||||
import ( | ||||||
"flag" | ||||||
"fmt" | ||||||
"sort" | ||||||
"strings" | ||||||
"time" | ||||||
|
||||||
apiv1 "k8s.io/api/core/v1" | ||||||
|
@@ -140,7 +142,7 @@ func (calc *UpdatePriorityCalculator) AddPod(pod *apiv1.Pod, now time.Time) { | |||||
klog.V(4).Infof("not updating pod %v/%v because resource would not change", pod.Namespace, pod.Name) | ||||||
return | ||||||
} | ||||||
klog.V(2).Infof("pod accepted for update %v/%v with priority %v", pod.Namespace, pod.Name, updatePriority.ResourceDiff) | ||||||
klog.V(2).Infof("pod accepted for update %v/%v with priority %v - processed recommendations:\n%v", pod.Namespace, pod.Name, updatePriority.ResourceDiff, calc.GetProcessedRecommendationTargets(processedRecommendation)) | ||||||
calc.pods = append(calc.pods, prioritizedPod{ | ||||||
pod: pod, | ||||||
priority: updatePriority, | ||||||
|
@@ -163,6 +165,35 @@ func (calc *UpdatePriorityCalculator) GetSortedPods(admission PodEvictionAdmissi | |||||
return result | ||||||
} | ||||||
|
||||||
// GetProcessedRecommendationTargets takes a RecommendedPodResources object and returns a formatted string | ||||||
// with the recommended pod resources. Specifically, it formats the target and uncapped target CPU and memory. | ||||||
func (calc *UpdatePriorityCalculator) GetProcessedRecommendationTargets(r *vpa_types.RecommendedPodResources) string { | ||||||
sb := &strings.Builder{} | ||||||
for _, cr := range r.ContainerRecommendations { | ||||||
sb.WriteString(fmt.Sprintf("%s: ", cr.ContainerName)) | ||||||
if cr.Target != nil { | ||||||
sb.WriteString("target: ") | ||||||
if !cr.Target.Memory().IsZero() { | ||||||
sb.WriteString(fmt.Sprintf("%sK ", cr.Target.Memory().AsDec())) | ||||||
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 think we need to scale this in order to be Kilobytes, otherwise
Suggested change
whereas 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. Good point - added this in the latest commit + updated the tests! |
||||||
} | ||||||
if !cr.Target.Cpu().IsZero() { | ||||||
sb.WriteString(fmt.Sprintf("%vm; ", cr.Target.Cpu().MilliValue())) | ||||||
} | ||||||
} | ||||||
if cr.UncappedTarget != nil { | ||||||
sb.WriteString("uncappedTarget: ") | ||||||
if !cr.UncappedTarget.Memory().IsZero() { | ||||||
sb.WriteString(fmt.Sprintf("%sK ", cr.UncappedTarget.Memory().AsDec())) | ||||||
} | ||||||
if !cr.UncappedTarget.Cpu().IsZero() { | ||||||
sb.WriteString(fmt.Sprintf("%vm;", cr.UncappedTarget.Cpu().MilliValue())) | ||||||
} | ||||||
} | ||||||
sb.WriteString("\n") | ||||||
} | ||||||
return sb.String() | ||||||
} | ||||||
|
||||||
func parseVpaObservedContainers(pod *apiv1.Pod) (bool, sets.String) { | ||||||
observedContainers, hasObservedContainers := pod.GetAnnotations()[annotations.VpaObservedContainersLabel] | ||||||
vpaContainerSet := sets.NewString() | ||||||
|
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.
As you're already using the string builder here you could write this without fmt.Sprintf to be more efficient.