You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2020/11/10 10:20:18 UTC

[camel-k] 18/25: fix: Use attempt time to compute queuing duration on recovery

This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 2998f3a9bdeab6b0493185e4208296cb66b6d195
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Oct 21 18:40:31 2020 +0200

    fix: Use attempt time to compute queuing duration on recovery
---
 pkg/controller/build/metrics.go          | 8 ++++++++
 pkg/controller/build/schedule_pod.go     | 2 +-
 pkg/controller/build/schedule_routine.go | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/pkg/controller/build/metrics.go b/pkg/controller/build/metrics.go
index 20b052f..16fd330 100644
--- a/pkg/controller/build/metrics.go
+++ b/pkg/controller/build/metrics.go
@@ -102,3 +102,11 @@ func getBuildAttemptFor(build *v1.Build) (int, int) {
 	}
 	return attempt, attemptMax
 }
+
+func getBuildQueuingTime(build *v1.Build) time.Time {
+	queuingTime := build.CreationTimestamp.Time
+	if failure := build.Status.Failure; failure != nil {
+		queuingTime = failure.Recovery.AttemptTime.Time
+	}
+	return queuingTime
+}
diff --git a/pkg/controller/build/schedule_pod.go b/pkg/controller/build/schedule_pod.go
index e2bf606..0e17694 100644
--- a/pkg/controller/build/schedule_pod.go
+++ b/pkg/controller/build/schedule_pod.go
@@ -106,7 +106,7 @@ func (action *schedulePodAction) Handle(ctx context.Context, build *v1.Build) (*
 		}
 
 		// Report the duration the Build has been waiting in the build queue
-		queueDuration.Observe(time.Now().Sub(build.CreationTimestamp.Time).Seconds())
+		queueDuration.Observe(time.Now().Sub(getBuildQueuingTime(build)).Seconds())
 	}
 
 	build.Status.Phase = v1.BuildPhasePending
diff --git a/pkg/controller/build/schedule_routine.go b/pkg/controller/build/schedule_routine.go
index 56d0c6f..7797991 100644
--- a/pkg/controller/build/schedule_routine.go
+++ b/pkg/controller/build/schedule_routine.go
@@ -94,7 +94,7 @@ func (action *scheduleRoutineAction) Handle(ctx context.Context, build *v1.Build
 	}
 
 	// Report the duration the Build has been waiting in the build queue
-	queueDuration.Observe(time.Now().Sub(build.CreationTimestamp.Time).Seconds())
+	queueDuration.Observe(time.Now().Sub(getBuildQueuingTime(build)).Seconds())
 
 	camelevent.NotifyBuildUpdated(ctx, action.client, action.recorder, build, target)