Skip to content

perf(common): extend ComputeDetails with VCPU + MemoryGB#97

Merged
cristim merged 1 commit intofeat/multicloud-web-frontendfrom
perf/computedetails-vcpu-memory
Apr 30, 2026
Merged

perf(common): extend ComputeDetails with VCPU + MemoryGB#97
cristim merged 1 commit intofeat/multicloud-web-frontendfrom
perf/computedetails-vcpu-memory

Conversation

@cristim
Copy link
Copy Markdown
Member

@cristim cristim commented Apr 27, 2026

Summary

Adds VCPU int + MemoryGB float64 (both omitempty) to
common.ComputeDetails so per-provider catalogue lookups can enrich compute
recommendations with sizing data. Foundation work for the deferred Azure /
AWS / GCP compute SKU enrichment tracked in #82.

GetDetailDescription now appends " (N vCPU / M GB)" when both values
are populated; the existing "platform/tenancy" form is preserved when
either is zero (so today's call sites stay unchanged).

Scope decision — schema-only foundation

This PR intentionally lands only the shared-type schema + matcher
formatting + tests. Per-provider catalogue wiring is out of scope:

The schema change is the prerequisite that unblocks every one of those
follow-ups.

Changes

  • pkg/common/types.go::ComputeDetails gains VCPU + MemoryGB
    (omitempty) with a doc comment explaining the catalogue-source
    contract.
  • ComputeDetails.GetDetailDescription() appends the size suffix when
    both fields are > 0; uses %g so 16 GB renders without trailing
    zeros while 0.5 GB (smallest Azure SKU) renders verbatim.
  • pkg/common/types_test.go adds 4 table rows covering VCPU-only,
    MemoryGB-only (both fall back to base form), integer GB, and
    fractional GB.

Test plan

  • go build ./... (root + pkg/)
  • go test ./... (root)
  • go test ./... from pkg/
  • Pre-commit hooks (gofmt, govet, gosec, gocyclo, etc.) all green
  • Existing ComputeDetails consumers (Azure converter, AWS parser,
    cmd/main.go switch) continue compiling — no field is removed and
    omitempty keeps the JSON payload unchanged when fields aren't
    populated

Follow-up issues (to file post-merge)

Refs #82

Summary by CodeRabbit

  • New Features
    • Compute details now display vCPU and memory sizing information alongside platform and tenancy data when available.

Adds optional VCPU (int) and MemoryGB (float64) fields to
common.ComputeDetails so per-provider catalogue lookups can enrich
compute recommendations with sizing data. Both fields use json
omitempty — converters that don't yet wire a catalogue leave them at
the zero value and the API payload stays clean.

GetDetailDescription appends " (N vCPU / M GB)" when both values are
> 0, otherwise returns the existing "platform/tenancy" form. Format
uses %g so 16 GB renders as "16 GB" (not "16.000000 GB") while 0.5 GB
SKUs render as "0.5 GB".

Scope decision — schema-only foundation:

- Azure: PR #81 (perf/azure-batched-sku-lookup) introduces the
  cachedSKULookup helper for cache/cosmos/database. Compute was
  scoped back from #81 because these fields didn't exist. With the
  schema in place, a follow-up PR can wire compute on top of #81 once
  it merges (filed as a separate issue post-merge to avoid an
  unmerged-PR dependency in this changeset).
- AWS: ce.EC2InstanceDetails (Cost-Explorer) has no vCPU/Memory
  fields; populating would require a new ec2:DescribeInstanceTypes
  caller + cache + mocks. Substantial net-new code, tracked as a
  separate follow-up.
- GCP: no compute recommendation converter exists today. N/A.
- Frontend: api.Recommendation has no `details` field and the detail
  drawer renders a hard-coded list. Surfacing the new fields needs
  separate API + UI work; tracked as follow-up once at least one
  provider populates the fields.

Tests: extend pkg/common/types_test.go::TestComputeDetails_GetDetail
Description with 4 new table rows — VCPU-only, MemoryGB-only,
integer-GB, and fractional-GB (Azure 0.5 GB SKU shape).

Refs #82
@cristim
Copy link
Copy Markdown
Member Author

cristim commented Apr 27, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 48c6463e-f517-4e6d-a897-711602c55853

📥 Commits

Reviewing files that changed from the base of the PR and between 2e33c88 and de195f9.

📒 Files selected for processing (2)
  • pkg/common/types.go
  • pkg/common/types_test.go

📝 Walkthrough

Walkthrough

The ComputeDetails struct gains optional compute sizing fields (VCPU, MemoryGB) with JSON omitempty tags. The GetDetailDescription() method is updated to conditionally append a formatted size descriptor when both fields are populated and greater than zero. Comprehensive test coverage verifies the conditional rendering behavior across multiple scenarios.

Changes

Cohort / File(s) Summary
Compute Details Enhancement
pkg/common/types.go
Added VCPU (int) and MemoryGB (float64) fields to ComputeDetails struct. Updated GetDetailDescription() to conditionally append (<vcpu> vCPU / <memory> GB) suffix when both sizing fields are non-zero.
Test Coverage
pkg/common/types_test.go
Extended TestComputeDetails_GetDetailDescription with table-driven test cases verifying suffix omission when either field is zero, inclusion when both are non-zero, and proper formatting for integer and fractional memory values.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Poem

🐰 Hop hop, compute details grow,
vCPU and memory now on show!
With omitempty tags so clean,
The finest sizing specs you've seen.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding VCPU and MemoryGB fields to ComputeDetails, which is the primary alteration in the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/computedetails-vcpu-memory

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim
Copy link
Copy Markdown
Member Author

cristim commented Apr 27, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/few Limited audience priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/feat New capability urgency/this-quarter Within the quarter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant