Skip to content

Commit

Permalink
fix(resources): improve ressource accounting. Fixes #12468 (#12492)
Browse files Browse the repository at this point in the history
Signed-off-by: Aloÿs Augustin <aloys.augustin@aqemia.com>
  • Loading branch information
AloysAqemia committed Feb 5, 2024
1 parent 55e532b commit 09edbf7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion util/resource/duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestDurationForPod(t *testing.T) {
corev1.ResourceCPU: wfv1.NewResourceDuration(2 * time.Minute),
corev1.ResourceMemory: wfv1.NewResourceDuration(1 * time.Minute),
}},
{"ContainerWithCPURequest", &corev1.Pod{
{"ContainerWithGPULimit", &corev1.Pod{
Spec: corev1.PodSpec{Containers: []corev1.Container{{Name: "main", Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("2000m"),
Expand Down
7 changes: 6 additions & 1 deletion util/resource/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ func (ss Summaries) Duration() wfv1.ResourcesDuration {
// Add container states.
d := wfv1.ResourcesDuration{}
for _, s := range ss {
// age is converted to seconds, otherwise the multiplication below is very likely to overflow
age := int64(s.age().Seconds())
for n, q := range s.ResourceList {
d = d.Add(wfv1.ResourcesDuration{n: wfv1.NewResourceDuration(time.Duration(q.Value() * age / wfv1.ResourceQuantityDenominator(n).Value() * int64(time.Second)))})
d = d.Add(wfv1.ResourcesDuration{
n: wfv1.NewResourceDuration(time.Duration(
q.MilliValue()*age/wfv1.ResourceQuantityDenominator(n).MilliValue(),
) * time.Second),
})
}
}
return d
Expand Down

0 comments on commit 09edbf7

Please sign in to comment.