Skip to content

Support OpenCost currency detection and overrides - #1472

Open
nadaverell wants to merge 4 commits into
mainfrom
fix/opencost-currency
Open

Support OpenCost currency detection and overrides#1472
nadaverell wants to merge 4 commits into
mainfrom
fix/opencost-currency

Conversation

@nadaverell

@nadaverell nadaverell commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

OpenCost reports numeric costs without a dependable currency label on its normal allocation and asset responses. This PR gives Radar a trustworthy currency contract without pretending to perform conversion:

  • use an explicit Radar setting when configured
  • otherwise detect OpenCost custom-pricing currency only from an active in-cluster OpenCost or Kubecost workload and its referenced ConfigMap
  • otherwise label values as USD
  • keep all cost surfaces and diagnostics on the same resolved label

Closes #1355 and #1470.

What changed

Resolution and API contract

  • Added a currency field to every cost API response, including unavailable and error-shaped responses.
  • Resolves currency at request time with precedence: explicit override, trusted OpenCost ConfigMap detection, USD fallback.
  • Retains the last trusted detected currency through a transient OpenCost workload outage, but resets to USD on active ambiguity, invalid configuration, or cluster/config changes.
  • Skips cluster ConfigMap inference for manually configured Prometheus URLs, where the queried OpenCost may be remote.

Configuration

  • Added a Cost section in Settings with Auto and a searchable currency picker. Currency names and ISO codes come from the browser internationalization data, and users can search by either name or code.
  • Settings changes apply immediately when Radar is not started with an explicit currency override.
  • Tracks explicit CLI/Helm ownership separately from the saved setting. Settings shows the active managed value and persists edits for a later run without replacing the running CLI/Helm label.
  • Added JSON config, --opencost-currency, desktop, and Helm cost.currency support.
  • Keeps backend ISO 4217 validation for every configuration path.

Presentation

  • Formats every cost surface with Intl.NumberFormat, including zero-decimal currencies such as JPY, and no longer renders malformed runtime codes as dollars.
  • Replaces dollar-specific copy and icons with currency-neutral presentation.
  • Updates diagnostics and documentation to state that currency is a display label only; Radar does not convert OpenCost values.

Testing

  • make test
  • npm --prefix web test — 54 files, 470 tests
  • npm --prefix packages/k8s-ui test — 145 files, 2,555 passed, 1 skipped
  • make tsc
  • make build
  • ./scripts/test-chart.sh
  • Focused Go tests for server, OpenCost, Prometheus, desktop, explorer, and app packages
  • Visual testing on live GKE and AWS/EKS clusters at 1280px and 1920px, light and dark themes
  • Verified Auto, searchable name/code lookup, keyboard selection, explicit EUR, managed CLI/Helm EUR, application, workload, home-card, and unavailable states
  • Browser console errors on tested pages: 0

Notes

Currency detection is intentionally conservative. It reads only explicit or official OpenCost custom-pricing ConfigMaps referenced by active workloads; it does not infer from arbitrary namespace data. Conflicting active configuration falls back to USD. Radar labels values but never converts them.

@nadaverell
nadaverell requested a review from hisco as a code owner August 23, 2026 21:05
Comment thread internal/server/opencost_workload_test.go
@nadaverell nadaverell changed the title Support configured currency for OpenCost costs Support OpenCost currency detection and overrides Aug 24, 2026
Comment thread internal/server/server.go

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 740d267. Configure here.

onChange={onChange}
ariaLabel="Currency override"
searchPlaceholder="Search currencies by name or code"
className="w-full"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Escape closes Settings over menu

Medium Severity

Opening the currency SelectMenu inside Settings and pressing Escape dismisses the whole Settings dialog (or the unsaved-changes confirm) instead of closing the dropdown. Settings listens for Escape in the capture phase and stops propagation, so the menu never gets a chance to handle it.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 740d267. Configure here.

label: name && name !== code ? `${name} (${code})` : code,
}
})
.sort((a, b) => a.label.localeCompare(b.label, 'en')),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Non-monetary codes selectable

Medium Severity

CURRENCY_OPTIONS is built from Intl.supportedValuesOf('currency') with no filter, so non-monetary codes such as XXX and XTS appear in the Settings picker. Saving those values fails because NormalizeOpenCostCurrency rejects them.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 740d267. Configure here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenCost cost summary always shows currency as USD, ignoring actual cluster currency

1 participant