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

Conversation

Tom-Newton
Copy link
Contributor

@Tom-Newton Tom-Newton commented Apr 3, 2024

Tracking issue

Closes #5170

Why are the changes needed?

Accurate metrics are useful.

What changes were proposed in this pull request?

Fix the streak length metric reporting by avoiding use of defer. Included slightly simplifying the branching logic.

How was this patch tested?

I've been using it in production.
image

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly - not applicable
  • All new and existing tests passed
  • All commits are signed-off.

Related PRs

Docs link

@Tom-Newton Tom-Newton force-pushed the tomnewton/fix_streak_length_reporting/GH-5170 branch from 131bbff to faca8b9 Compare April 3, 2024 09:58
@Tom-Newton Tom-Newton marked this pull request as ready for review April 3, 2024 10:02
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Apr 3, 2024
@@ -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))
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 😅

@Tom-Newton Tom-Newton force-pushed the tomnewton/fix_streak_length_reporting/GH-5170 branch from 416c72f to a80f1df Compare April 4, 2024 08:55
@Tom-Newton
Copy link
Contributor Author

I rebased on latest master, which I'm hoping will fix the docs build error

@Tom-Newton Tom-Newton requested a review from eapolinario April 4, 2024 08:56
Copy link

codecov bot commented Apr 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.06%. Comparing base (f1c2231) to head (e0a414a).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5172      +/-   ##
==========================================
- Coverage   59.06%   59.06%   -0.01%     
==========================================
  Files         646      646              
  Lines       55714    55725      +11     
==========================================
+ Hits        32910    32915       +5     
- Misses      20208    20214       +6     
  Partials     2596     2596              
Flag Coverage Δ
unittests 59.06% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Thomas Newton <[email protected]>
@Tom-Newton Tom-Newton force-pushed the tomnewton/fix_streak_length_reporting/GH-5170 branch from a6f2cb9 to e0a414a Compare April 4, 2024 22:33
@Tom-Newton
Copy link
Contributor Author

Tom-Newton commented Apr 4, 2024

Pretty sure I fixed the linter error. Initially I struggled a bit to run linting locally.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 5, 2024
@eapolinario eapolinario merged commit 14eaa16 into flyteorg:master Apr 5, 2024
47 of 48 checks passed
Jeinhaus pushed a commit to Jeinhaus/flyte that referenced this pull request Apr 8, 2024
* Don't use `defer` for streak length reporting

Signed-off-by: Thomas Newton <[email protected]>

* Make it work with defer

Signed-off-by: Thomas Newton <[email protected]>

* Fix lint

Signed-off-by: Thomas Newton <[email protected]>

---------

Signed-off-by: Thomas Newton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Streak length metric reporting is broken
2 participants