Skip to content

refactor: remove tStart variable when it is not needed - #2168

Merged
TenSt merged 1 commit into
RedHatInsights:masterfrom
TenSt:stepan/refactor-tstart-variable
Apr 22, 2026
Merged

TenSt merged 1 commit into
RedHatInsights:masterfrom
TenSt:stepan/refactor-tstart-variable

Conversation

@TenSt

@TenSt TenSt commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

This PR is a small refactoring to remove the tStart variable when it is not needed (single-time usage in defer).

Note: the parameters in deferred functions are evaluated during registration not during execution, so using time.Now() as a parameter is completely safe.

Summary by Sourcery

Enhancements:

  • Remove unnecessary local tStart variables and pass time.Now() directly to utils.ObserveSecondsSince in all affected functions for clearer and more concise timing instrumentation.

@TenSt
TenSt requested a review from a team as a code owner April 22, 2026 13:34
@sourcery-ai

sourcery-ai Bot commented Apr 22, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors multiple timing/metrics call sites to remove unnecessary temporary tStart variables by passing time.Now() directly into deferred utils.ObserveSecondsSince calls, relying on the fact that defer arguments are evaluated at registration time.

File-Level Changes

Change Details Files
Inline time.Now() directly into deferred utils.ObserveSecondsSince calls instead of storing it in a temporary tStart variable at various evaluation, listener, and task entry points.
  • Replace local tStart := time.Now() declarations where the variable is only used once in a subsequent defer.
  • Update corresponding defer utils.ObserveSecondsSince(tStart, ...) calls to utils.ObserveSecondsSince(time.Now(), ...).
  • Apply this refactor consistently across evaluator, listener, and tasks packages for evaluation durations, message handling durations, and message send durations.
evaluator/evaluate.go
listener/upload.go
evaluator/evaluate_advisories.go
evaluator/evaluate_packages.go
evaluator/inventory_views.go
evaluator/notifications.go
evaluator/remediations.go
listener/event_buffers.go
listener/events.go
listener/templates.go
tasks/vmaas_sync/send_messages.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Given how often defer utils.ObserveSecondsSince(time.Now(), ...) now appears, consider adding a small helper (e.g. utils.ObserveSinceNow(metric ...)) to reduce repetition and make the intent clearer.
  • The subtle point about defer argument evaluation timing that you explained in the PR description might be worth capturing as a brief code comment near one representative usage to prevent future accidental re-introduction of a tStart variable.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Given how often `defer utils.ObserveSecondsSince(time.Now(), ...)` now appears, consider adding a small helper (e.g. `utils.ObserveSinceNow(metric ...)`) to reduce repetition and make the intent clearer.
- The subtle point about `defer` argument evaluation timing that you explained in the PR description might be worth capturing as a brief code comment near one representative usage to prevent future accidental re-introduction of a `tStart` variable.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.54%. Comparing base (2c0fa69) to head (5cadc8b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2168      +/-   ##
==========================================
- Coverage   57.66%   57.54%   -0.13%     
==========================================
  Files         134      134              
  Lines       10592    10569      -23     
==========================================
- Hits         6108     6082      -26     
- Misses       3940     3943       +3     
  Partials      544      544              
Flag Coverage Δ
unittests 57.54% <100.00%> (-0.13%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TenSt
TenSt merged commit 44f8d67 into RedHatInsights:master Apr 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants