fix: CR syncer uses units correctly#859
Conversation
📝 WalkthroughWalkthroughThis PR parametrizes the RAM unit conversion in commitment state calculations, replacing a fixed 1 GiB-per-unit assumption with a flavor-group-aware dynamic conversion via ChangesVariable RAM Unit Conversion for Commitment State
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/scheduling/reservations/commitments/syncer.go`:
- Around line 148-153: When the expected RAM unit computation fails in the block
that logs "failed to compute expected RAM unit for flavor group" (using
variables flavorGroupName and ramUnitMiB), ensure the current commitment's
identity is recorded so it isn't treated as inactive by GC; specifically, before
continuing, add the commitment's UUID (commitment.UUID) to the same
processed/skipped tracking structure you use elsewhere (e.g.
processedCommitmentIDs or skippedCommitments map) and/or set a skipped status
field on the commitment object so it is considered active, then continue; this
preserves the UUID and prevents accidental cleanup.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5867d6d0-cb3f-496a-bee2-6b1cef52124c
📒 Files selected for processing (3)
internal/scheduling/reservations/commitments/state.gointernal/scheduling/reservations/commitments/state_test.gointernal/scheduling/reservations/commitments/syncer.go
| if err != nil { | ||
| log.Error(err, "failed to compute expected RAM unit for flavor group", | ||
| "flavorGroup", flavorGroupName, | ||
| "ramUnitMiB", ramUnitMiB) | ||
| continue | ||
| } |
There was a problem hiding this comment.
Preserve UUID on unit-computation failure to avoid accidental cleanup.
When expected unit computation fails, the commitment is neither processed nor marked as skipped. That can make later GC treat existing CRDs/reservations as inactive and delete them.
Suggested fix
expectedLiquidUnit, err := liquid.UnitMebibytes.MultiplyBy(ramUnitMiB)
if err != nil {
log.Error(err, "failed to compute expected RAM unit for flavor group",
"flavorGroup", flavorGroupName,
"ramUnitMiB", ramUnitMiB)
+ // Preserve existing CRDs/reservations for this commitment until unit
+ // computation can be evaluated successfully again.
+ if commitment.UUID != "" {
+ result.skippedUUIDs[commitment.UUID] = true
+ }
+ if s.monitor != nil {
+ s.monitor.RecordError()
+ }
continue
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if err != nil { | |
| log.Error(err, "failed to compute expected RAM unit for flavor group", | |
| "flavorGroup", flavorGroupName, | |
| "ramUnitMiB", ramUnitMiB) | |
| continue | |
| } | |
| if err != nil { | |
| log.Error(err, "failed to compute expected RAM unit for flavor group", | |
| "flavorGroup", flavorGroupName, | |
| "ramUnitMiB", ramUnitMiB) | |
| // Preserve existing CRDs/reservations for this commitment until unit | |
| // computation can be evaluated successfully again. | |
| if commitment.UUID != "" { | |
| result.skippedUUIDs[commitment.UUID] = true | |
| } | |
| if s.monitor != nil { | |
| s.monitor.RecordError() | |
| } | |
| continue | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/scheduling/reservations/commitments/syncer.go` around lines 148 -
153, When the expected RAM unit computation fails in the block that logs "failed
to compute expected RAM unit for flavor group" (using variables flavorGroupName
and ramUnitMiB), ensure the current commitment's identity is recorded so it
isn't treated as inactive by GC; specifically, before continuing, add the
commitment's UUID (commitment.UUID) to the same processed/skipped tracking
structure you use elsewhere (e.g. processedCommitmentIDs or skippedCommitments
map) and/or set a skipped status field on the commitment object so it is
considered active, then continue; this preserves the UUID and prevents
accidental cleanup.
Test Coverage ReportTest Coverage 📊: 69.6% |
No description provided.