Update commitments with support for non-standard units#624
Conversation
…non-standard units (waiting for release)
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughAdds commitments e2e entrypoint, Prometheus monitors for the commitments API and syncer, unit-mismatch validation in the syncer (skips mismatched commitments), propagates reservation creator request IDs into reconcile contexts, and updates a dependency version. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 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 docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/scheduling/reservations/commitments/syncer.go (1)
240-243: Consider usingmaps.Copyfor merging the skipped UUIDs.Per coding guidelines, prefer
maps.Copyover iteratively copying map entries.♻️ Suggested refactor
// Also include skipped commitments - don't delete their CRDs - for uuid := range commitmentResult.skippedUUIDs { - activeCommitments[uuid] = true - } + maps.Copy(activeCommitments, commitmentResult.skippedUUIDs)You'll need to add
"maps"to the imports.As per coding guidelines: "Use
maps.Copyinstead of iteratively copying a map".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/scheduling/reservations/commitments/syncer.go` around lines 240 - 243, Replace the manual loop that merges commitmentResult.skippedUUIDs into activeCommitments by using maps.Copy to copy all entries at once; update the import list to include "maps" and call maps.Copy(activeCommitments, commitmentResult.skippedUUIDs) where the loop currently exists (referencing commitmentResult.skippedUUIDs and activeCommitments in syncer.go).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/scheduling/reservations/commitments/api_info.go`:
- Around line 111-123: The code calls a non-existent method
UnitMebibytes.MultiplyBy; replace that logic by calling
liquid.UnitMebibytes.Base() to get (baseUnit, multiplier), set unit = baseUnit
(or liquid.UnitNone on error), and compute any scaled value by multiplying
groupData.SmallestFlavor.MemoryMB by multiplier before assigning into resources;
update references around UnitMebibytes, Unit.Base(),
groupData.SmallestFlavor.MemoryMB, and the resources[resourceName] assignment to
use baseUnit and the computed scaled value.
---
Nitpick comments:
In `@internal/scheduling/reservations/commitments/syncer.go`:
- Around line 240-243: Replace the manual loop that merges
commitmentResult.skippedUUIDs into activeCommitments by using maps.Copy to copy
all entries at once; update the import list to include "maps" and call
maps.Copy(activeCommitments, commitmentResult.skippedUUIDs) where the loop
currently exists (referencing commitmentResult.skippedUUIDs and
activeCommitments in syncer.go).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 20815acc-9032-4ff8-83b9-0a8f96b961e1
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (9)
cmd/main.gogo.modinternal/scheduling/reservations/commitments/api_info.gointernal/scheduling/reservations/commitments/context.gointernal/scheduling/reservations/commitments/controller.gointernal/scheduling/reservations/commitments/syncer.gointernal/scheduling/reservations/commitments/syncer_monitor.gointernal/scheduling/reservations/commitments/syncer_test.gointernal/scheduling/reservations/scheduler_client.go
| // Build unit from smallest flavor memory (e.g., "131072 MiB" for 128 GiB) | ||
| unit, err := liquid.UnitMebibytes.MultiplyBy(groupData.SmallestFlavor.MemoryMB) | ||
| if err != nil { | ||
| logger.Error(err, "failed to create unit for flavor group", | ||
| "flavorGroup", groupName, | ||
| "smallestFlavorMemoryMB", groupData.SmallestFlavor.MemoryMB) | ||
| // Fall back to UnitNone if unit creation fails (should not happen in practice) | ||
| unit = liquid.UnitNone | ||
| } | ||
|
|
||
| resources[resourceName] = liquid.ResourceInfo{ | ||
| DisplayName: displayName, | ||
| Unit: liquid.UnitNone, // Countable: multiples of smallest flavor instances | ||
| Unit: unit, // Non-standard unit: multiples of smallest flavor RAM |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
go-api-declarations liquid Unit MultiplyBy method sapcc
💡 Result:
In github.com/sapcc/go-api-declarations/liquid, there is no Unit.MultiplyBy method. Instead, unit conversion is modeled via:
func (u Unit) Base() (Unit, uint64)which returns the base unit plus a multiplier to convert values inuinto that base unit. For all binary-size units (KiB,MiB, …), the base unit isB(bytes); otherwise it returns(u, 1). [1][2]
Multiplier mapping (from Base()): KiB=1<<10, MiB=1<<20, GiB=1<<30, TiB=1<<40, PiB=1<<50, EiB=1<<60. [2]
How to “multiply by” in practice:
base, mul := u.Base()
valueInBase := value * mul[1][2]
Sources: [1] [2]
Fix non-existent MultiplyBy API call — use Unit.Base() instead.
The liquid.UnitMebibytes.MultiplyBy() method does not exist in go-api-declarations/liquid. Use the Base() method to convert units:
baseUnit, multiplier := liquid.UnitMebibytes.Base()
// Then use: groupData.SmallestFlavor.MemoryMB * multiplier🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@internal/scheduling/reservations/commitments/api_info.go` around lines 111 -
123, The code calls a non-existent method UnitMebibytes.MultiplyBy; replace that
logic by calling liquid.UnitMebibytes.Base() to get (baseUnit, multiplier), set
unit = baseUnit (or liquid.UnitNone on error), and compute any scaled value by
multiplying groupData.SmallestFlavor.MemoryMB by multiplier before assigning
into resources; update references around UnitMebibytes, Unit.Base(),
groupData.SmallestFlavor.MemoryMB, and the resources[resourceName] assignment to
use baseUnit and the computed scaled value.
Test Coverage ReportTest Coverage 📊: 68.4% |
Blocked till https://github.com/sapcc/go-api-declarations has a new release