-
Notifications
You must be signed in to change notification settings - Fork 1
Make instance UUIDs stable across restarts #51
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
Conversation
WalkthroughAdds a new file-based InstanceLock class and tests, integrates it into ApitallyClient (replacing direct UUID generation), and updates .gitignore to ignore the VS Code folder. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/main/java/io/apitally/common/InstanceLock.java`:
- Around line 64-85: The FileLock obtained by channel.tryLock() must be retained
and released explicitly: modify the InstanceLock class to add a private final
FileLock lock field, update the constructor(s) to accept and store the FileLock
(in addition to the existing FileChannel parameter), and change the factory code
that currently calls new InstanceLock(uuid, channel) to pass the acquired
FileLock (the local variable from tryLock) so the lock isn't only a transient
local. Implement or update InstanceLock.close() to first call lock.release()
(guarded for null/closed), then close the channel, ensuring deterministic,
platform-independent lock release instead of relying on GC/close behavior.
In `@src/test/java/io/apitally/common/InstanceLockTest.java`:
- Around line 32-43: The tearDown method uses Files.walk(tempDir) but never
closes the returned Stream<Path>, leaving directory handles open; change the
cleanup to use a try-with-resources around Stream<Path> (e.g., try (Stream<Path>
stream = Files.walk(tempDir)) {
stream.sorted(Comparator.reverseOrder()).forEach(...); }) so the stream is
closed automatically, keeping the existing deletion logic and exception handling
inside the forEach; reference the tearDown method, tempDir variable, and
Files.walk call when making this change.
🧹 Nitpick comments (1)
src/main/java/io/apitally/common/InstanceLock.java (1)
120-123: Consider a longer hash prefix to lower collision risk.
A 4‑byte prefix (32‑bit) can collide when multiple clientId/env pairs exist on the same host, leading to shared lock files/UUIDs. Expanding to 8+ bytes keeps filenames short but meaningfully reduces risk.♻️ Suggested tweak
- return HexFormat.of().formatHex(hash, 0, 4); + return HexFormat.of().formatHex(hash, 0, 8);
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #51 +/- ##
============================================
- Coverage 77.37% 77.07% -0.31%
- Complexity 314 326 +12
============================================
Files 31 32 +1
Lines 1061 1121 +60
Branches 134 140 +6
============================================
+ Hits 821 864 +43
- Misses 163 175 +12
- Partials 77 82 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary by CodeRabbit
New Features
Chores
Tests
✏️ Tip: You can customize this high-level summary in your review settings.