Skip to content
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

Querying exchange rate (api.exchangerate.host) always fails (self hosted infracost) #2766

Open
Tomasz-Kluczkowski opened this issue Nov 29, 2023 · 2 comments

Comments

@Tomasz-Kluczkowski
Copy link

Hi,

I just noticed in the self hosted infracost-cloud-pricing-api pod's logs that it keeps repeating this set of error logs when cost estimations happen:

2023-11-29T09:23:52Z {"level":50,"time":1701249832660,"pid":18,"hostname":"infracost-cloud-pricing-api-7555d776c9-sttsg","msg":"Error querying exchange rate:"}
2023-11-29T09:23:52Z {"level":50,"time":1701249832660,"pid":18,"hostname":"infracost-cloud-pricing-api-7555d776c9-sttsg","err":{"type":"TypeError","message":"Cannot read properties of undefined (reading 'GBP')","stack":"TypeError: Cannot read properties of undefined (reading 'GBP')\n    at /usr/src/app/dist/utils/currency.js:281:58\n    at step (/usr/src/app/dist/utils/currency.js:33:23)\n    at Object.next (/usr/src/app/dist/utils/currency.js:14:53)\n    at fulfilled (/usr/src/app/dist/utils/currency.js:5:58)\n    at processTicksAndRejections (node:internal/process/task_queues:96:5)"},"msg":"Cannot read properties of undefined (reading 'GBP')"}
2023-11-29T09:23:52Z {"level":40,"time":1701249832660,"pid":18,"hostname":"infracost-cloud-pricing-api-7555d776c9-sttsg","msg":"No exchange rate found, falling back to default rate"}

I have checked and firewall does not block calls to api.exchangerate.host, I can see a bunch of them corresponding to the error logs from the infracost-cloud-pricing-api pod looking like this:

 HTTPS request from <pod's node ip address> to dashboard.api.infracost.io:443. Action: Allow.
-- | -- | -- | --

HTTPS request from  <pod's node ip address> to api.exchangerate.host:443. Action: Allow. <--- this one is repeated many times, corresponds to error logs in the infracost-cloud-pricing-api pod.

The commands for infracost are running in gitlab and I am using these variables to control currency and location:

variables:
  INFRACOST_AZURE_OVERRIDE_REGION: uksouth
  INFRACOST_CURRENCY: GBP

This is my script:

  script:
    - git clone $CI_REPOSITORY_URL --branch=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME --single-branch /tmp/base

    - |
      cd /tmp/base
      infracost breakdown --config-file=${CONFIG_FILE} \
                          --format=json \
                          --out-file=infracost-base.json

    - |
      cd -
      infracost diff --config-file=${CONFIG_FILE} \
                     --compare-to=/tmp/base/infracost-base.json \
                     --format=json \
                     --out-file=infracost.json

    - |
      infracost comment gitlab --path=infracost.json \
                               --repo=$CI_PROJECT_PATH \
                               --merge-request=$CI_MERGE_REQUEST_IID \
                               --gitlab-server-url=$CI_SERVER_URL \
                               --gitlab-token=$GITLAB_API_TOKEN \
                               --behavior=update

is GBP incorrect value for exchangerate.host or for self hosted infracost it does not work as some kind of account needs to be set up with exchangerate.host?

Am I missing something?

Is there a way to debug this better and see more detail of the error log?

@Tomasz-Kluczkowski
Copy link
Author

is it because for self hosted infracost I have no ability to specify API key for exchangerate.host as documented here? https://exchangerate.host/

@borjapenman
Copy link

exchangeapi.io works the same api.exchangerate.host worked wothout the key

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

No branches or pull requests

2 participants