From f13e62d82bafe2257d371b15c9e49d4d845a1d80 Mon Sep 17 00:00:00 2001 From: Thomas Newton Date: Wed, 3 Apr 2024 10:53:15 +0100 Subject: [PATCH 1/3] Don't use `defer` for streak length reporting Signed-off-by: Thomas Newton --- flytepropeller/pkg/controller/handler.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/flytepropeller/pkg/controller/handler.go b/flytepropeller/pkg/controller/handler.go index 94e8ab6c12..03b6494751 100644 --- a/flytepropeller/pkg/controller/handler.go +++ b/flytepropeller/pkg/controller/handler.go @@ -230,7 +230,6 @@ func (p *Propeller) Handle(ctx context.Context, namespace, name string) error { } streak := 0 - defer p.metrics.StreakLength.Add(ctx, float64(streak)) maxLength := p.cfg.MaxStreakLength if maxLength <= 0 { @@ -239,16 +238,15 @@ func (p *Propeller) Handle(ctx context.Context, namespace, name string) error { for streak = 0; streak < maxLength; streak++ { w, err = p.streak(ctx, w, wfClosureCrdFields) - if err != nil { - return err - } else if w == nil { + if err != nil || w == nil { break } logger.Infof(ctx, "FastFollow Enabled. Detected State change, we will try another round. StreakLength [%d]", streak) } logger.Infof(ctx, "Streak ended at [%d]/Max: [%d]", streak, maxLength) - return nil + p.metrics.StreakLength.Add(ctx, float64(streak)) + return err } // parseWorkflowClosureCrdFields attempts to retrieve offloaded static workflow closure data from the specified From a80f1df327c587ed6869601b88f5c9a4dc2f048c Mon Sep 17 00:00:00 2001 From: Thomas Newton Date: Thu, 4 Apr 2024 08:50:54 +0100 Subject: [PATCH 2/3] Make it work with defer Signed-off-by: Thomas Newton --- flytepropeller/pkg/controller/handler.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/flytepropeller/pkg/controller/handler.go b/flytepropeller/pkg/controller/handler.go index 03b6494751..675c82d317 100644 --- a/flytepropeller/pkg/controller/handler.go +++ b/flytepropeller/pkg/controller/handler.go @@ -230,6 +230,7 @@ func (p *Propeller) Handle(ctx context.Context, namespace, name string) error { } streak := 0 + defer func() { p.metrics.StreakLength.Add(ctx, float64(streak)) }() maxLength := p.cfg.MaxStreakLength if maxLength <= 0 { @@ -238,15 +239,16 @@ func (p *Propeller) Handle(ctx context.Context, namespace, name string) error { for streak = 0; streak < maxLength; streak++ { w, err = p.streak(ctx, w, wfClosureCrdFields) - if err != nil || w == nil { + if err != nil { + return err + } else if w == nil { break } logger.Infof(ctx, "FastFollow Enabled. Detected State change, we will try another round. StreakLength [%d]", streak) } logger.Infof(ctx, "Streak ended at [%d]/Max: [%d]", streak, maxLength) - p.metrics.StreakLength.Add(ctx, float64(streak)) - return err + return nil } // parseWorkflowClosureCrdFields attempts to retrieve offloaded static workflow closure data from the specified From e0a414a8bda308a0198d3e100c62a4fb31d900fb Mon Sep 17 00:00:00 2001 From: Thomas Newton Date: Thu, 4 Apr 2024 23:32:24 +0100 Subject: [PATCH 3/3] Fix lint Signed-off-by: Thomas Newton --- flytepropeller/pkg/controller/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flytepropeller/pkg/controller/handler.go b/flytepropeller/pkg/controller/handler.go index 675c82d317..49c2c21549 100644 --- a/flytepropeller/pkg/controller/handler.go +++ b/flytepropeller/pkg/controller/handler.go @@ -230,7 +230,7 @@ func (p *Propeller) Handle(ctx context.Context, namespace, name string) error { } streak := 0 - defer func() { p.metrics.StreakLength.Add(ctx, float64(streak)) }() + defer func() { p.metrics.StreakLength.Add(ctx, float64(streak)) }() maxLength := p.cfg.MaxStreakLength if maxLength <= 0 {