Skip to content

fix: avoid metrics for migrating NAR during an already in-progress - #1079

Merged
kalbasit merged 1 commit into
mainfrom
fix-do-not-record-metrics-for
Mar 12, 2026
Merged

kalbasit merged 1 commit into
mainfrom
fix-do-not-record-metrics-for

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

When a NAR migration is already in-progress, do not log metrics and logs
as if the migration has succeeded.

@kalbasit

kalbasit commented Mar 12, 2026 •

Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. bug Something isn't working go Pull requests that update go code labels Mar 12, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the handling of concurrent NAR (Nix Archive) migrations to prevent misleading metrics and logs. Previously, if a migration was already in progress, the system would silently return, potentially leading to inaccurate success metrics. The changes introduce a specific error for this scenario and ensure that subsequent attempts to migrate the same NAR gracefully exit without recording false positives or unnecessary logs, improving the accuracy of operational monitoring. Additionally, a new logging statement was added to provide more visibility into NAR compression.

Highlights

  • Error Handling for Concurrent Migrations: Introduced a new error ErrMigrationInProgress to explicitly signal when a NAR migration is already underway, preventing silent success.
  • Accurate Metric and Log Reporting: Modified MigrateNarToChunks to return ErrMigrationInProgress instead of nil when a concurrent migration is detected, ensuring that subsequent attempts to migrate the same NAR gracefully exit without recording false positives or unnecessary logs.
  • Background Migration Logic: Implemented error handling in BackgroundMigrateNarToChunks and pkg/ncps/migrateNarToChunks to check for ErrMigrationInProgress and return early, avoiding incorrect metric recording.
  • Enhanced Logging: Added a new informational log statement in the server's withNarURL middleware to provide more visibility into NAR compression details.
Changelog
  • pkg/cache/cache.go
    • Defined a new error ErrMigrationInProgress.
    • Changed MigrateNarToChunks to return ErrMigrationInProgress when a migration is already active.
    • Added a check for ErrMigrationInProgress in BackgroundMigrateNarToChunks to prevent further processing.
  • pkg/ncps/migrate_nar_to_chunks.go
    • Implemented a check for cache.ErrMigrationInProgress to avoid recording migration duration metrics when a migration is already in progress.
  • pkg/server/server.go
    • Added an Info level log message displaying the NAR compression type within the withNarURL function.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses the issue of logging metrics for NAR migrations that are already in progress. The introduction of ErrMigrationInProgress and its handling in MigrateNarToChunks and its callers is a good approach to make the control flow more explicit and prevent incorrect metric reporting. I have one suggestion regarding a new log line in pkg/server/server.go to reduce potential log verbosity.

Comment thread pkg/server/server.go Resolved
@codecov

codecov Bot commented Mar 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.04%. Comparing base (4d4123e) to head (560e09c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1079   +/-   ##
=====================================
  Coverage   5.04%   5.04%           
=====================================
  Files          6       6           
  Lines        436     436           
=====================================
  Hits          22      22           
  Misses       410     410           
  Partials       4       4           

☔ 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.

When a NAR migration is already in-progress, do not log metrics and logs
as if the migration has succeeded.
@kalbasit
kalbasit force-pushed the fix-do-not-record-metrics-for branch from c4dd402 to 560e09c Compare March 12, 2026 22:14
@kalbasit kalbasit added the backport release-0.9 Backport PR automatically label Mar 12, 2026
@kalbasit
kalbasit enabled auto-merge (squash) March 12, 2026 22:14
@kalbasit
kalbasit merged commit 4ea3739 into main Mar 12, 2026
17 checks passed
@kalbasit
kalbasit deleted the fix-do-not-record-metrics-for branch March 12, 2026 22:26
kalbasit added a commit that referenced this pull request Mar 12, 2026
…1079)

When a NAR migration is already in-progress, do not log metrics and logs
as if the migration has succeeded.

(cherry picked from commit 4ea3739)
@kalbasit

Copy link
Copy Markdown
Owner Author

Successfully created backport PR for release-0.9:

kalbasit added a commit that referenced this pull request Mar 12, 2026
…ackport #1079] (#1080)

Bot-based backport to `release-0.9`, triggered by a label in #1079.

When a NAR migration is already in-progress, do not log metrics and logs
as if the migration has succeeded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release-0.9 Backport PR automatically bug Something isn't working go Pull requests that update go code size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant