Skip to content

Conversation

@malpou
Copy link

@malpou malpou commented Jul 23, 2025

What does this PR change?

  • Adds a generic currency conversion package that can be reused across all OpenCost plugins
  • Integrates currency conversion into the MongoDB Atlas plugin, allowing costs to be converted from USD to any ISO 4217 currency
  • Implements caching with 24-hour TTL to minimize API calls (stays within free tier limit of 1,500 requests/month)
  • Adds configuration options for target currency and exchange rate API key

Does this PR relate to any other PRs?

  • No

How will this PR impact users?

  • Users can now view MongoDB Atlas costs in their preferred currency by configuring target_currency and exchange_api_key in their plugin configuration
  • No breaking changes - defaults to USD if not configured
  • Other plugin developers can reuse the currency package for their own plugins

Does this PR address any GitHub or Zendesk issues?

  • No

How was this PR tested?

  • Unit tests for the currency package with mock implementations
  • Integration tests for MongoDB Atlas plugin currency conversion

Does this PR require changes to documentation?

  • Yes - users need to know about the new configuration options:
    • target_currency: ISO 4217 currency code (e.g., "EUR", "GBP")
    • exchange_api_key: API key from exchangerate-api.com

- Create generic currency package for reuse across plugins
- Implement exchange rate fetching from exchangerate-api.com
- Add thread-safe caching with 24-hour TTL
- Support all ISO 4217 currency codes
- Update MongoDB Atlas plugin to support currency conversion
- Add configuration for target currency and API key
- Include comprehensive tests for currency conversion

Signed-off-by: Malthe Poulsen <malthe@grundtvigsvej.dk>
@malpou malpou force-pushed the feature/currency-conversion branch from 509aa4c to a88ae8c Compare July 23, 2025 13:55
malpou added 4 commits July 23, 2025 16:33
Signed-off-by: Malthe Poulsen <malthe@grundtvigsvej.dk>
Signed-off-by: Malthe Poulsen <malthe@grundtvigsvej.dk>
…and replacing hardcoded "USD" references.

Signed-off-by: Malthe Poulsen <malthe@grundtvigsvej.dk>
…e unexported types/fields and camelCase for uniformity. Update associated tests and methods accordingly.

Signed-off-by: Malthe Poulsen <malthe@grundtvigsvej.dk>
@malpou malpou marked this pull request as ready for review July 24, 2025 12:34
@malpou malpou changed the title feat(mongodb-atlas): add currency conversion support [WIP] feat(mongodb-atlas): add currency conversion support Jul 24, 2025
@ameijer
Copy link
Member

ameijer commented Aug 7, 2025

@malpou would you be willing to move into opencost, then invoke the APIs from there? we would love to bring this functionality to all parts of the product

@malpou
Copy link
Author

malpou commented Aug 9, 2025

@ameijer Yes of course.

If you can give a little guidance to where and how it should land in the opencost project then I'd move it in there 😄

@ameijer
Copy link
Member

ameijer commented Aug 12, 2025

Could I suggest you move your 'currency' package to https://github.com/opencost/opencost/tree/develop/pkg? I think that is a logical home for it

@@ -0,0 +1,99 @@
package currency
Copy link
Member

Choose a reason for hiding this comment

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

@malpou can we update this to remove currency conversion since we merged your PR upstream?

Copy link
Author

@malpou malpou Oct 4, 2025

Choose a reason for hiding this comment

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

Sorry for the long time of nothing happening been busy, @ameijer it should be good now 😄

…encost

- Remove local currency package from opencost-plugins/common/currency
- Update imports to use github.com/opencost/opencost/pkg/currency
- Fix duplicate imports and incorrect replace directives in go.mod
- Remove unused standard library plugin import

Signed-off-by: malpou <malthe@grundtvigsvej.dk>
@malpou malpou force-pushed the feature/currency-conversion branch from 4cc4a21 to 556dc03 Compare October 4, 2025 06:24
@malpou malpou requested a review from ameijer October 4, 2025 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants