This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit fd743b7fe69f52834568eeef636ccdbeac5eb7c0 Author: Antonin Stefanutti <anto...@stefanutti.fr> AuthorDate: Mon Oct 11 09:45:24 2021 +0200 fix: Race condition when observing integration first readiness metric --- pkg/controller/integration/integration_controller.go | 17 +++++++++++++---- pkg/controller/integration/monitor.go | 10 ---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pkg/controller/integration/integration_controller.go b/pkg/controller/integration/integration_controller.go index 2501740..cb67e53 100644 --- a/pkg/controller/integration/integration_controller.go +++ b/pkg/controller/integration/integration_controller.go @@ -83,13 +83,22 @@ func add(mgr manager.Manager, c client.Client, r reconcile.Reconciler) error { For(&v1.Integration{}, builder.WithPredicates( predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { - oldIntegration := e.ObjectOld.(*v1.Integration) - newIntegration := e.ObjectNew.(*v1.Integration) + old := e.ObjectOld.(*v1.Integration) + it := e.ObjectNew.(*v1.Integration) + // Observe the time to first readiness metric + previous := old.Status.GetCondition(v1.IntegrationConditionReady) + if next := it.Status.GetCondition(v1.IntegrationConditionReady); (previous == nil || previous.Status != corev1.ConditionTrue && (previous.FirstTruthyTime == nil || previous.FirstTruthyTime.IsZero())) && + next != nil && next.Status == corev1.ConditionTrue && next.FirstTruthyTime != nil && !next.FirstTruthyTime.IsZero() { + duration := next.FirstTruthyTime.Time.Sub(it.Status.InitializationTimestamp.Time) + Log.WithValues("request-namespace", it.Namespace, "request-name", it.Name). + ForIntegration(it).Infof("First readiness after %s", duration) + timeToFirstReadiness.Observe(duration.Seconds()) + } // Ignore updates to the integration status in which case metadata.Generation does not change, // or except when the integration phase changes as it's used to transition from one phase // to another. - return oldIntegration.Generation != newIntegration.Generation || - oldIntegration.Status.Phase != newIntegration.Status.Phase + return old.Generation != it.Generation || + old.Status.Phase != it.Status.Phase }, DeleteFunc: func(e event.DeleteEvent) bool { // Evaluates to false if the object has been confirmed deleted diff --git a/pkg/controller/integration/monitor.go b/pkg/controller/integration/monitor.go index 990aa6b..cd5300d 100644 --- a/pkg/controller/integration/monitor.go +++ b/pkg/controller/integration/monitor.go @@ -153,21 +153,11 @@ func (action *monitorAction) Handle(ctx context.Context, integration *v1.Integra return integration, nil } - previous := integration.Status.GetCondition(v1.IntegrationConditionReady) - err = action.updateIntegrationPhaseAndReadyCondition(ctx, integration, pendingPods.Items, runningPods.Items) if err != nil { return nil, err } - if next := integration.Status.GetCondition(v1.IntegrationConditionReady); (previous == nil || previous.FirstTruthyTime == nil || previous.FirstTruthyTime.IsZero()) && - next != nil && next.Status == corev1.ConditionTrue && !(next.FirstTruthyTime == nil || next.FirstTruthyTime.IsZero()) { - // Observe the time to first readiness metric - duration := next.FirstTruthyTime.Time.Sub(integration.Status.InitializationTimestamp.Time) - action.L.Infof("First readiness after %s", duration) - timeToFirstReadiness.Observe(duration.Seconds()) - } - return integration, nil }