-
Notifications
You must be signed in to change notification settings - Fork 61
feat: Add currency selection support to UI #158
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
base: main
Are you sure you want to change the base?
feat: Add currency selection support to UI #158
Conversation
✅ Deploy Preview for opencost-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
- Wire currency dropdowns to backend API - Add currency parameter to all cost endpoints - Persist currency preference in URL - Prepare UI for OpenCost v1.120 currency conversion Signed-off-by: ADITYA TIWARI <adityatiwari342005@gmail.com>
b15bb83 to
64091ee
Compare
|
Hi @ameijer, this PR fixes #5, the currency conversion feature. I have tested the functionality locally; however, I could not verify backward compatibility as that version is yet to be released. these are the logs that verified it. Terminal logs (click to expand)adityatiwari@DeathNote:~/opencost-ui$ # Check OpenCost backend version kubectl get deployment -n opencost opencost -o yaml | grep "image:" image: ghcr.io/opencost/opencost:1.119.1@sha256:43fbd73e2d13f79c07801511877b6c9d70896bc10e2cadcf6a04f4c5d37f6ed3 image: ghcr.io/opencost/opencost-ui:1.119.1@sha256:ae134411a088658d003a06bb3cdfe03336abfc861c2fbe2e7cb54dd54b26714badityatiwari@DeathNote:~/opencost-ui$ # Verify latest OpenCost release adityatiwari@DeathNote:~/opencost-ui$ # Check for currency-related logs in backend adityatiwari@DeathNote:~/opencost-ui$ # Test currency parameter with different currencies adityatiwari@DeathNote:~/opencost-ui$ echo "Testing USD:" adityatiwari@DeathNote:~/opencost-ui$ echo "Testing EUR:" adityatiwari@DeathNote:~/opencost-ui$ echo "Testing INR:" adityatiwari@DeathNote:~/opencost-ui$ # All three currencies return identical values - no conversion happening adityatiwari@DeathNote:~/opencost-ui$ # Search for currency conversion PR in OpenCost repository adityatiwari@DeathNote:~/opencost-ui$ # Get details of the currency conversion PR adityatiwari@DeathNote:~/opencost-ui$ # Check if PR #3315 is in current release adityatiwari@DeathNote:~/opencost-ui$ # Verify backend accepts currency parameter but doesn't convert adityatiwari@DeathNote:~/opencost-ui$ curl -s "http://localhost:9003/allocation/compute?window=today¤cy=INR" | adityatiwari@DeathNote:~/opencost-ui$ # Same value (0.01073) for both USD and INR adityatiwari@DeathNote:~/opencost-ui$ pkill -f port-forward adityatiwari@DeathNote: |
|
@ameijer Please review it! |
|
Also fixes #3 . |
Signed-off-by: Aditya Tiwari <adityatiwari342005@gmail.com>
Signed-off-by: Aditya Tiwari <adityatiwari342005@gmail.com>
Signed-off-by: Aditya Tiwari <adityatiwari342005@gmail.com>
|
Hi @ameijer Apologies for bothering you, but I require your review on this, as it addresses 2 issues and cannot be verified on Netlify preview to be functional because the latest released version of OpenCost is v1.119.1, which was released on January 6, 2025, and the backend integration of currency conversion was done by opencost/opencost#3315, (merged Sept 5, 2025). Any suggestions on how to proceed? (I have tested the fix on localhost backend by curl.) |
|
@ADITYATIWARI342005 want to implement BE currency conversion? |
I have attempted to, based on your feedback on the earlier PR on that issue and comment #5 (comment) @ameijer Should I refactor the approach? Whatever you prefer. |
@ameijer After reading it again, I am not sure. Did it mean implementation in |
|
yes, that's right. if you inspect opencost/opencost, you will see that recently a community member contributed code that implements forex conversion. however, that code isn't called anywhere. we need an enhancement on that repo that reads the params you send here, then jams all costs into the converter before returning. |
@ameijer Thanks for the descriptive explanation. I have a high-level overview about what is to be done. I am looking into this. |
Hi @ameijer At first it seemed tough, but given your description and guidance, I attempted to successfully implement it, I have tested the build and functionality thoroughly. Looking forward to your valuable reviews! on opencost/opencost#3553 |
What does this PR change?
?currency=EUR) for shareable linksDoes this PR relate to any other PRs?
mainbranchHow will this PR impact users?
Does this PR address any GitHub or Zendesk issues?
How was this PR tested?
Manual testing on local kind cluster with OpenCost v1.119.1
Functional verification:
?currency=EURBackend verification:
Version compatibility testing:
INF Unsupported provider, falling back to defaultCode review: Verified consistent patterns across all modified files
Does this PR require changes to documentation?
CURRENCY_PROVIDER=exchangerateapi CURRENCY_API_KEY=<your_api_key>Developer Docs: No - implementation follows existing patterns
API Docs: No - UI only change, no API modifications
Have you labeled this PR and its corresponding Issue as "next release" if it should be part of the next OpenCost release? If not, why not?
Additional Context
Backend Currency Conversion Status:
The backend currency conversion package (PR #3315) was merged on September 4, 2025, but is not yet included in a release. It provides:
Current Behavior (v1.119.1):
INF Unsupported provider, falling back to defaultFuture Behavior (v1.120+):
Testing Evidence:
Click to expand terminal output showing backend verification
```bash adityatiwari@DeathNote:~/opencost-ui$ # Check OpenCost backend version kubectl get deployment -n opencost opencost -o yaml | grep "image:" image: ghcr.io/opencost/opencost:1.119.1@sha256:43fbd73e2d13f79c07801511877b6c9d70896bc10e2cadcf6a04f4c5d37f6ed3 image: ghcr.io/opencost/opencost-ui:1.119.1@sha256:ae134411a088658d003a06bb3cdfe03336abfc861c2fbe2e7cb54dd54b26714badityatiwari@DeathNote:~/opencost-ui$ # Verify latest OpenCost release
curl -s https://api.github.com/repos/opencost/opencost/releases/latest | jq -r '.tag_name'
v1.119.1
adityatiwari@DeathNote:~/opencost-ui$ # Check for currency-related logs in backend
kubectl logs -n opencost deployment/opencost --tail=200 | grep -i "currency|exchange|provider"
Defaulted container "opencost" out of: opencost, opencost-ui
2026-01-17T03:07:57.611848613Z INF Unsupported provider, falling back to default
2026-01-17T03:07:57.611960736Z INF Prometheus Client Max Concurrency set to 5
adityatiwari@DeathNote:~/opencost-ui$ # Test currency parameter with different currencies
echo "Testing USD:"
curl -s "http://localhost:9003/allocation/compute?window=today¤cy=USD&aggregate=namespace" | jq '.data[0] | to_entries[0].value.totalCost'
Testing USD:
0.09659
adityatiwari@DeathNote:~/opencost-ui$ echo "Testing EUR:"
curl -s "http://localhost:9003/allocation/compute?window=today¤cy=EUR&aggregate=namespace" | jq '.data[0] | to_entries[0].value.totalCost'
Testing EUR:
0.09659
adityatiwari@DeathNote:~/opencost-ui$ echo "Testing INR:"
curl -s "http://localhost:9003/allocation/compute?window=today¤cy=INR&aggregate=namespace" | jq '.data[0] | to_entries[0].value.totalCost'
Testing INR:
0.09659
adityatiwari@DeathNote:~/opencost-ui$ # All three currencies return identical values - no conversion happening
Expected: USD=0.09659, EUR≈0.082 (0.85x), INR≈8.69 (90x)
Actual: All return 0.09659
adityatiwari@DeathNote:~/opencost-ui$ # Search for currency conversion PR in OpenCost repository
curl -s "https://api.github.com/search/commits?q=repo:opencost/opencost+currency&sort=committer-date&order=desc"
-H "Accept: application/vnd.github.cloak-preview+json" |
jq -r '.items[0:5] | .[] | "(.commit.author.date | split("T")[0]) - (.commit.message | split("\n")[0])"'
2025-09-04 - feat: Add generic currency conversion package (#3315)
2023-05-24 - Merge pull request #1940 from saifullah619/feat/multipleCurrencySupport
2023-05-23 - [UI]-Added the support for multiple currencies
adityatiwari@DeathNote:~/opencost-ui$ # Get details of the currency conversion PR
curl -s "https://api.github.com/repos/opencost/opencost/pulls/3315" |
jq '{title: .title, state: .state, merged: .merged, merged_at: .merged_at}'
{
"title": "feat: Add generic currency conversion package",
"state": "closed",
"merged": true,
"merged_at": "2025-09-04T20:51:53Z"
}
adityatiwari@DeathNote:~/opencost-ui$ # Backend accepts currency parameter but doesn't convert
curl -s "http://localhost:9003/allocation/compute?window=today¤cy=USD" |
jq '.data[0]."default-cluster/kind-control-plane/kube-system/coredns-5d78c9869d-6d6rm/coredns".totalCost'
0.01073
adityatiwari@DeathNote:~/opencost-ui$ curl -s "http://localhost:9003/allocation/compute?window=today¤cy=INR" |
jq '.data[0]."default-cluster/kind-control-plane/kube-system/coredns-5d78c9869d-6d6rm/coredns".totalCost'
0.01073
adityatiwari@DeathNote:~/opencost-ui$ # Same value (0.01073) for both USD and INR
Expected INR value: 0.01073 * 90 ≈ 0.9657
Backend accepts parameter but does not perform conversion