Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
1.98k stars 1.15k forks source link

costManagementClient.query.usage() returns wrong CAD unit instead of USD #29948

Open akumar-99 opened 4 weeks ago

akumar-99 commented 4 weeks ago

Describe the bug The azure account is Canada based. But the API Call being done here is for USD. Hence the unit should be USD. The value returned is correct but the inut is CAD for some reason.

"DailyTotalCost": {
  "...": {
    "code": 200,
    "data": {
      "id": "...",
      "name": "...",
      "type": "Microsoft.CostManagement/query",
      "location": null,
      "sku": null,
      "eTag": null,
      "nextLink": null,
      "columns": [
        {
          "name": "CostUSD",
          "type": "Number"
        },
        {
          "name": "UsageDate",
          "type": "Number"
        },
        {
          "name": "Currency",
          "type": "String"
        }
      ],
      "rows": [
        [
          0.00248,
          20240401,
          "CAD"
        ],
        [
          0.002096,
          20240402,
          "CAD"
        ],
        ...
      ]
    }
  }
}

To Reproduce Steps to reproduce the behavior:

  1. Run the code given below.

Expected behavior The unit should be USD for this API call.

Additional context

let subscriptionDailyTotalCost = {};
for (let i = 1; i <= retries; i++) {
    let successFlag = true;
    try {
        let result = costManagementClient.query.usage(
            `subscriptions/${subscriptionId}`,
            {
                type: 'ActualCost',
                timeframe: 'Custom',
                dataset: {
                    granularity: 'Daily',
                    aggregation: { totalCost: { name: 'CostUSD', function: 'Sum' } },
                },
                timePeriod: {
                    from: threeMonthsAgoDate,
                    to: currentDate,
                },
            },
        );

        subscriptionDailyTotalCost = {
            code: 200,
            data: await result,
        };
    } catch (error) {
        subscriptionDailyTotalCost = {
            code: _get(error, ['statusCode'], 400),
            data: error,
        };

        successFlag = false;
    }

    if (
        !successFlag &&
        _get(subscriptionDailyTotalCost, ['code'], 200) === 429
    ) {
        await new Promise((r) => setTimeout(r, delay * i));
    } else {
        break;
    }
}
dailyTotalCost[subscriptionId] = subscriptionDailyTotalCost;
jeremymeng commented 4 weeks ago

@akumar-99 thank you for reporting this issue! We will take a look as soon as possible.

qiaozha commented 3 weeks ago

@akumar-99 Thanks for reporting this to us, according to my understanding, the currency of Azure subscriptions is bind with your offer, and query usage details is not supposed to do the convert currency thing here. In the case that your offer supports multi currency, the query usage details should show the billed currency.

Here're some reference links, hope it helps.

  1. https://answers.microsoft.com/en-us/msoffice/forum/all/how-to-change-the-currency-for-azure-in-our/16b62cf6-7d5c-4864-b868-bb4da259aa4a
  2. https://learn.microsoft.com/en-us/answers/questions/1286171/how-can-i-change-currency-in-azure-cost-analysis-t
github-actions[bot] commented 3 weeks ago

Hi @akumar-99. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

github-actions[bot] commented 2 weeks ago

Hi @akumar-99, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

akumar-99 commented 1 week ago

@akumar-99 Thanks for reporting this to us, according to my understanding, the currency of Azure subscriptions is bind with your offer, and query usage details is not supposed to do the convert currency thing here. In the case that your offer supports multi currency, the query usage details should show the billed currency.

Here're some reference links, hope it helps.

1. https://answers.microsoft.com/en-us/msoffice/forum/all/how-to-change-the-currency-for-azure-in-our/16b62cf6-7d5c-4864-b868-bb4da259aa4a

2. https://learn.microsoft.com/en-us/answers/questions/1286171/how-can-i-change-currency-in-azure-cost-analysis-t

Hi @qiaozha, the call I am doing here is CostUSD. In context to the dashboard, we have the details available in the billed currency of the account and another is the cost in USD. The output I am getting through this function call is absolutely on point. My only concern is, that if the call is for USD, the data returned is in USD then why not return currency as USD too instead of the billed currency type.