Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix streak length metric reporting #5172

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flytepropeller/pkg/controller/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (p *Propeller) Handle(ctx context.Context, namespace, name string) error {
}

streak := 0
defer p.metrics.StreakLength.Add(ctx, float64(streak))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Golang's defer semantics allows us to use this idiom with a slight change. From the spec:

Each time a "defer" statement executes, the function value and parameters to the call are evaluated as usual and saved anew but the actual function is not invoked.

This means that we can define a function that closes over streak like so:

defer func() { p.metrics.StreakLength.Add(ctx, float64(streak)) }()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. As you can probably tell I don't really know what I'm doing with golang 😅

defer func() { p.metrics.StreakLength.Add(ctx, float64(streak)) }()

maxLength := p.cfg.MaxStreakLength
if maxLength <= 0 {
Expand Down
Loading