From c15a75b0076a6a69be0d0f0efb4c6129d3732ec5 Mon Sep 17 00:00:00 2001 From: AloysAqemia <135111228+AloysAqemia@users.noreply.github.com> Date: Mon, 5 Feb 2024 19:36:23 +0100 Subject: [PATCH] fix(resources): improve ressource accounting. Fixes #12468 (#12492) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Aloÿs Augustin --- util/resource/duration_test.go | 2 +- util/resource/summary.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/util/resource/duration_test.go b/util/resource/duration_test.go index 0330cb5c2bb9..8cb37836bec7 100644 --- a/util/resource/duration_test.go +++ b/util/resource/duration_test.go @@ -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"), diff --git a/util/resource/summary.go b/util/resource/summary.go index 56fc5c88c8ef..aa176cf1dd4c 100644 --- a/util/resource/summary.go +++ b/util/resource/summary.go @@ -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