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

BadRequest running azure-cost show #6

Closed
RikGr opened this issue Apr 15, 2023 · 24 comments
Closed

BadRequest running azure-cost show #6

RikGr opened this issue Apr 15, 2023 · 24 comments
Labels
bug Something isn't working

Comments

@RikGr
Copy link

RikGr commented Apr 15, 2023

Reproduction steps:

  1. az login
  2. az account set -s [subscriptionId]
  3. azure-cost show -s [subscriptionId] --debug

I receive:

Response status code is BadRequest and got payload size of 905
Response content: {"error":{"code":"BadRequest","message":"Invalid query definition: Invalid dataset grouping: 'BillingPeriod'; valid values:
'ResourceGroup','ResourceGroupName','ResourceType','ResourceId','ResourceLocation','SubscriptionId','SubscriptionName','MeterCategory','MeterSubcategory','Meter
','ServiceFamily','UnitOfMeasure','PartNumber','BillingAccountName','BillingProfileId','BillingProfileName','InvoiceSection','InvoiceSectionId','InvoiceSectionN
ame','Product','ResourceGuid','ChargeType','ServiceName','ProductOrderId','ProductOrderName','PublisherType','ReservationId','ReservationName','Frequency','Invo
iceId','PricingModel','CostAllocationRuleName','MarkupRuleName','BillingMonth','Provider','BenefitId','BenefitName','CustomerTenantId','CustomerTenantDomainName
','ResellerMPNId','PartnerEarnedCreditApplied','CustomerName','PartnerName',''.\r\n\r\n (Request ID: 3075b6e8-3c39-4607-8823-b42d43bd3226)"}}
Error: Response status code does not indicate success: 400 (Bad Request).
@klagan
Copy link

klagan commented Apr 15, 2023

snap!!

Response status code is BadRequest and got payload size of 905 Response content: {"error":{"code":"BadRequest","message":"Invalid query definition: Invalid dataset grouping: 'BillingPeriod'; valid values: 'ResourceGroup','ResourceGroupName','ResourceType','ResourceId','ResourceLocation','SubscriptionId','SubscriptionName','MeterCategory','MeterSubcategory','Meter' ,'ServiceFamily','UnitOfMeasure','PartNumber','BillingAccountName','BillingProfileId','BillingProfileName','InvoiceSection','InvoiceSectionId','InvoiceSectionNam e','Product','ResourceGuid','ChargeType','ServiceName','ProductOrderId','ProductOrderName','PublisherType','ReservationId','ReservationName','Frequency','Invoice Id','PricingModel','CostAllocationRuleName','MarkupRuleName','BillingMonth','Provider','BenefitId','BenefitName','CustomerTenantId','CustomerTenantDomainName','R esellerMPNId','PartnerEarnedCreditApplied','CustomerName','PartnerName',''.\r\n\r\n (Request ID: 977a12a8-a345-44ae-81a0-cbcafdaf5e38)"}} Error: Response status code does not indicate success: 400 (Bad Request).

@FrancescoBonizzi
Copy link

Same here! I'm on macOS 13.3.1 (22E261).

@mivano
Copy link
Owner

mivano commented Apr 15, 2023

Would you/someone be able to send me the full output of the --debug statement? So I can also see the payload/url?

@FrancescoBonizzi
Copy link

Sure!

Using token credential: ChainedTokenCredential to fetch a token.
Token retrieved and expires at: 15/04/2023 21:20:10 +00:00
Retrieving costs from 
/subscriptions/[subscriptionId]/providers/Microsoft.CostMana
gement/query?api-version=2021-10-01&$top=5000 using the following payload:
{
   "type": "ActualCost",
   "timeframe": "BillingMonthToDate",
   "timePeriod": null,
   "dataSet": {
      "granularity": "Daily",
      "aggregation": {
         "totalCost": {
            "name": "Cost",
            "function": "Sum"
         },
         "totalCostUSD": {
            "name": "CostUSD",
            "function": "Sum"
         }
      },
      "sorting": [
         {
            "direction": "Ascending",
            "name": "UsageDate"
         }
      ]
   }
}
Response status code is OK and got payload size of 
Retrieving costs from 
/subscriptions/[subscriptionId]/providers/Microsoft.CostMana
gement/forecast?api-version=2021-10-01&$top=5000 using the following payload:
{
   "type": "ActualCost",
   "dataSet": {
      "granularity": "Daily",
      "aggregation": {
         "totalCost": {
            "name": "Cost",
            "function": "Sum"
         }
      },
      "sorting": [
         {
            "direction": "Ascending",
            "name": "UsageDate"
         }
      ],
      "filter": {
         "Dimensions": {
            "Name": "PublisherType",
            "Operator": "In",
            "Values": [
               "azure"
            ]
         }
      }
   }
}
Response status code is BadRequest and got payload size of 905
Response content: {"error":{"code":"BadRequest","message":"Invalid query 
definition: Invalid dataset grouping: 'BillingPeriod'; valid values: 
'ResourceGroup','ResourceGroupName','ResourceType','ResourceId','ResourceLocatio
n','SubscriptionId','SubscriptionName','MeterCategory','MeterSubcategory','Meter
','ServiceFamily','UnitOfMeasure','PartNumber','BillingAccountName','BillingProf
ileId','BillingProfileName','InvoiceSection','InvoiceSectionId','InvoiceSectionN
ame','Product','ResourceGuid','ChargeType','ServiceName','ProductOrderId','Produ
ctOrderName','PublisherType','ReservationId','ReservationName','Frequency','Invo
iceId','PricingModel','CostAllocationRuleName','MarkupRuleName','BillingMonth','
Provider','BenefitId','BenefitName','CustomerTenantId','CustomerTenantDomainName
','ResellerMPNId','PartnerEarnedCreditApplied','CustomerName','PartnerName',''.\
r\n\r\n (Request ID: cc51eb29-1f2f-4a41-9d2b-514e322d06a4)"}}
Error: Response status code does not indicate success: 400 (Bad Request).

@mivano
Copy link
Owner

mivano commented Apr 15, 2023

Thanks, do you have this on all your subscriptions, or on a specific type? Like EA types?

@FrancescoBonizzi
Copy link

I only have this subscription. What is an EA type?
(Here I'm the owner)

@mivano
Copy link
Owner

mivano commented Apr 15, 2023

An Enterprise Agreement, maybe that does different kind of checks. I assume you can see the cost in the Azure Portal. Can you do me a favor and check in the network traffic of the browser what the request body is for the forecast API call?

Should look like something such as this (Safari on a Mac):
image

@FrancescoBonizzi
Copy link

You are right. I'm under a startup sponsorship and I can't see that forecast. Weird.
I only see this:

image

@mivano
Copy link
Owner

mivano commented Apr 15, 2023

Ah that is interesting. Can you do this command and check the quotaId property?

az account subscription show --subscription-id yourid

If that quota id is not on this list, then it looks like it is not possible to retrieve the data: https://learn.microsoft.com/en-us/azure/cost-management-billing/costs/understand-cost-mgt-data#supported-microsoft-azure-offers

@mivano
Copy link
Owner

mivano commented Apr 15, 2023

@RikGr and @klagan is the subscription you are trying to read a sponsorship one as well? Can you validate it with the az account command?

@redhatstuart
Copy link

Same issue here; I am using a pay as you go subscription:

PayAsYouGo_2014-09-01

@FrancescoBonizzi
Copy link

FrancescoBonizzi commented Apr 16, 2023

Ah that is interesting. Can you do this command and check the quotaId property?

az account subscription show --subscription-id yourid

If that quota id is not on this list, then it looks like it is not possible to retrieve the data: https://learn.microsoft.com/en-us/azure/cost-management-billing/costs/understand-cost-mgt-data#supported-microsoft-azure-offers

The output is just this:

{
  "authorizationSource": "Legacy",
  "displayName": "XXX",
  "id": "/subscriptions/YYY",
  "state": "Enabled",
  "subscriptionId": "YYY",
  "subscriptionPolicies": {
    "locationPlacementId": "Public_2014-09-01",
    "quotaId": "Sponsored_2016-01-01",
    "spendingLimit": "Off"
  }
}

It appears in the list.

@redhatstuart
Copy link

redhatstuart commented Apr 16, 2023

Yes mine is:

PayAsYouGo_2014-09-01

which correlates to:

Pay-As-You-Go | Pay-As-You-Go | PayAsYouGo_2014-09-01 | MS-AZR-0003P | October 2, 2018

{
  "authorizationSource": "RoleBased",
  "displayName": "blah",
  "id": "/subscriptions/X",
  "state": "Enabled",
  "subscriptionId": "X",
  "subscriptionPolicies": {
    "locationPlacementId": "Public_2014-09-01",
    "quotaId": "PayAsYouGo_2014-09-01",
    "spendingLimit": "Off"
  }
}

@klagan
Copy link

klagan commented Apr 16, 2023

@RikGr and @klagan is the subscription you are trying to read a sponsorship one as well? Can you validate it with the az account command?

Thanks, @mivano

I got MSDNDevTest_2014-09-01

Am fully aware Sponsorship account do not play with the billing API very nicely, but I expect a DevTest subscription to be ok

@mivano
Copy link
Owner

mivano commented Apr 16, 2023

I would indeed expect a MSDNDevTest_2014-09-01 to work. @RikGr is yours an Enterprise Agreement as well?

@klagan
Copy link

klagan commented Apr 16, 2023

I would indeed expect a MSDNDevTest_2014-09-01 to work. @RikGr is yours an Enterprise Agreement as well?

I have three different types of subscriptions which I have listed below with the respective results. Hope it helps:

  • EnterpriseAgreement_2014-09-01 (HTTP 400)
    • Response status code is BadRequest and got payload size of 905 Response content: {"error":{"code":"BadRequest","message":"Invalid query definition: Invalid dataset grouping: 'BillingPeriod'; valid values: 'ResourceGroup','ResourceGroupName','ResourceType','ResourceId','ResourceLocation','SubscriptionId','SubscriptionName','MeterCategory','MeterSubcategory','Meter' ,'ServiceFamily','UnitOfMeasure','PartNumber','BillingAccountName','BillingProfileId','BillingProfileName','InvoiceSection','InvoiceSectionId','InvoiceSectionNam e','Product','ResourceGuid','ChargeType','ServiceName','ProductOrderId','ProductOrderName','PublisherType','ReservationId','ReservationName','Frequency','Invoice Id','PricingModel','CostAllocationRuleName','MarkupRuleName','BillingMonth','Provider','BenefitId','BenefitName','CustomerTenantId','CustomerTenantDomainName','R esellerMPNId','PartnerEarnedCreditApplied','CustomerName','PartnerName',''.\r\n\r\n (Request ID: 9de79fdf-b246-47ca-8430-8aded9dcc9b3)"}} Error: Response status code does not indicate success: 400 (Bad Request).
  • MSDNDevTest_2014-09-01 (HTTP 400)
    • Response status code is BadRequest and got payload size of 905 Response content: {"error":{"code":"BadRequest","message":"Invalid query definition: Invalid dataset grouping: 'BillingPeriod'; valid values: 'ResourceGroup','ResourceGroupName','ResourceType','ResourceId','ResourceLocation','SubscriptionId','SubscriptionName','MeterCategory','MeterSubcategory','Meter' ,'ServiceFamily','UnitOfMeasure','PartNumber','BillingAccountName','BillingProfileId','BillingProfileName','InvoiceSection','InvoiceSectionId','InvoiceSectionNam e','Product','ResourceGuid','ChargeType','ServiceName','ProductOrderId','ProductOrderName','PublisherType','ReservationId','ReservationName','Frequency','Invoice Id','PricingModel','CostAllocationRuleName','MarkupRuleName','BillingMonth','Provider','BenefitId','BenefitName','CustomerTenantId','CustomerTenantDomainName','R esellerMPNId','PartnerEarnedCreditApplied','CustomerName','PartnerName',''.\r\n\r\n (Request ID: 538e6485-5928-4ac8-89ae-bc330e1a5423)"}} Error: Response status code does not indicate success: 400 (Bad Request).
  • PayAsYouGo_2014-09-01 (HTTP 424)
    • Response status code is FailedDependency and got payload size of 97 Response content: {"error":{"code":"FailedDependency","message":"Can't do forecast - cost training data is empty"}} Error: Response status code does not indicate success: 424 (Failed Dependency).

@daesk
Copy link

daesk commented Apr 17, 2023

@mivano

I get Bad Request as well. I'm having an EA subscription.

This is payload when browse and look at Cost analysis

https://management.azure.com/subscriptions/000000-0000-0000-0000-XXXXXX/providers/Microsoft.CostManagement/forecast?api-version=2021-10-01&$top=5000

{
   "type":"ActualCost",
   "dataSet":{
      "granularity":"Daily",
      "aggregation":{
         "totalCost":{
            "name":"Cost",
            "function":"Sum"
         }
      },
      "sorting":[
         {
            "direction":"ascending",
            "name":"UsageDate"
         }
      ]
   },
   "timeframe":"Custom",
   "timePeriod":{
      "from":"2023-04-01T00:00:00+00:00",
      "to":"2023-04-30T23:59:59+00:00"
   },
   "includeActualCost":false,
   "includeFreshPartialCost":false
}

@mivano mivano added the bug Something isn't working label Apr 17, 2023
@mivano
Copy link
Owner

mivano commented Apr 17, 2023

Thanks for the details @daesk !

Would you be able to test this with version 0.9 ? I hope I found the issue.

@Ravian18
Copy link

It works for me now

@klagan
Copy link

klagan commented Apr 18, 2023

I would indeed expect a MSDNDevTest_2014-09-01 to work. @RikGr is yours an Enterprise Agreement as well?

I have three different types of subscriptions which I have listed below with the respective results. Hope it helps:

  • EnterpriseAgreement_2014-09-01 (HTTP 400)

    • Response status code is BadRequest and got payload size of 905 Response content: {"error":{"code":"BadRequest","message":"Invalid query definition: Invalid dataset grouping: 'BillingPeriod'; valid values: 'ResourceGroup','ResourceGroupName','ResourceType','ResourceId','ResourceLocation','SubscriptionId','SubscriptionName','MeterCategory','MeterSubcategory','Meter' ,'ServiceFamily','UnitOfMeasure','PartNumber','BillingAccountName','BillingProfileId','BillingProfileName','InvoiceSection','InvoiceSectionId','InvoiceSectionNam e','Product','ResourceGuid','ChargeType','ServiceName','ProductOrderId','ProductOrderName','PublisherType','ReservationId','ReservationName','Frequency','Invoice Id','PricingModel','CostAllocationRuleName','MarkupRuleName','BillingMonth','Provider','BenefitId','BenefitName','CustomerTenantId','CustomerTenantDomainName','R esellerMPNId','PartnerEarnedCreditApplied','CustomerName','PartnerName',''.\r\n\r\n (Request ID: 9de79fdf-b246-47ca-8430-8aded9dcc9b3)"}} Error: Response status code does not indicate success: 400 (Bad Request).
  • MSDNDevTest_2014-09-01 (HTTP 400)

    • Response status code is BadRequest and got payload size of 905 Response content: {"error":{"code":"BadRequest","message":"Invalid query definition: Invalid dataset grouping: 'BillingPeriod'; valid values: 'ResourceGroup','ResourceGroupName','ResourceType','ResourceId','ResourceLocation','SubscriptionId','SubscriptionName','MeterCategory','MeterSubcategory','Meter' ,'ServiceFamily','UnitOfMeasure','PartNumber','BillingAccountName','BillingProfileId','BillingProfileName','InvoiceSection','InvoiceSectionId','InvoiceSectionNam e','Product','ResourceGuid','ChargeType','ServiceName','ProductOrderId','ProductOrderName','PublisherType','ReservationId','ReservationName','Frequency','Invoice Id','PricingModel','CostAllocationRuleName','MarkupRuleName','BillingMonth','Provider','BenefitId','BenefitName','CustomerTenantId','CustomerTenantDomainName','R esellerMPNId','PartnerEarnedCreditApplied','CustomerName','PartnerName',''.\r\n\r\n (Request ID: 538e6485-5928-4ac8-89ae-bc330e1a5423)"}} Error: Response status code does not indicate success: 400 (Bad Request).
  • PayAsYouGo_2014-09-01 (HTTP 424)

    • Response status code is FailedDependency and got payload size of 97 Response content: {"error":{"code":"FailedDependency","message":"Can't do forecast - cost training data is empty"}} Error: Response status code does not indicate success: 424 (Failed Dependency).

@mivano It appears to be working now with v0.9. What did you find was the issue?

@mivano
Copy link
Owner

mivano commented Apr 18, 2023

@mivano It appears to be working now with v0.9. What did you find was the issue?

Great! TimePeriod and a filtering. That is what I changed. It looks like the queries generated in the portal are different based on the subscription type.

@mivano mivano closed this as completed Apr 18, 2023
@RikGr
Copy link
Author

RikGr commented Apr 18, 2023

@mivano Yes it works for me now also. These subscriptions are of type "Azure Plan". They are not EA as far as I know. But to good thing is it working anyway! 👍

@FrancescoBonizzi
Copy link

FrancescoBonizzi commented Apr 18, 2023

To me the error now is 424 Failed dependency

Version: 0.4.0.0
Using token credential: ChainedTokenCredential to fetch a token.
Token retrieved and expires at: 18/04/2023 16:02:25 +00:00
Retrieving data from 
/subscriptions/[subId]/providers/Microsoft.CostManagement/query?api-versio
n=2021-10-01&$top=5000 using the following payload:
{
   "type": "ActualCost",
   "timeframe": "BillingMonthToDate",
   "timePeriod": null,
   "dataSet": {
      "granularity": "Daily",
      "aggregation": {
         "totalCost": {
            "name": "Cost",
            "function": "Sum"
         },
         "totalCostUSD": {
            "name": "CostUSD",
            "function": "Sum"
         }
      },
      "sorting": [
         {
            "direction": "Ascending",
            "name": "UsageDate"
         }
      ]
   }
}
Response status code is OK and got payload size of 455
Retrieving data from 
/subscriptions/[subId]/providers/Microsoft.CostManagement/forecast?api-ver
sion=2021-10-01&$top=5000 using the following payload:
{
   "type": "ActualCost",
   "timeframe": "Custom",
   "timePeriod": {
      "from": "2023-04-18",
      "to": "2023-05-02"
   },
   "dataSet": {
      "granularity": "Daily",
      "aggregation": {
         "totalCost": {
            "name": "Cost",
            "function": "Sum"
         }
      },
      "sorting": [
         {
            "direction": "ascending",
            "name": "UsageDate"
         }
      ]
   }
}
Response status code is FailedDependency and got payload size of 97
Response content: {"error":{"code":"FailedDependency","message":"Can't do forecast - cost training data
is empty"}}

Hi @mivano! I didn't understand if this kind of error is going to be solved or if is it impossible to make ti work with my kind of subscription because of API design. Thanks!

@daesk
Copy link

daesk commented Apr 18, 2023

Thanks for the details @daesk !

Would you be able to test this with version 0.9 ? I hope I found the issue.

Yes now it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants