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

Add table azure_consumption_usage Closes #668 #721

Merged
merged 4 commits into from
Jan 30, 2024
Merged

Conversation

ParthaI
Copy link
Contributor

@ParthaI ParthaI commented Jan 24, 2024

Integration test logs

Logs
N/A

Example query results

Results
> select
  name,
  id,
  metric,
  kind,
  legacy_usage_detail ->> 'BillingAccountID' as billing_account_id,
  legacy_usage_detail ->> 'BillingAccountName' as billing_account_name,
  legacy_usage_detail ->> 'BillingPeriodStartDate' as billing_period_start_date,
  legacy_usage_detail ->> 'BillingPeriodEndDate' as billing_period_end_date,
  legacy_usage_detail ->> 'Cost' as cost,
  legacy_usage_detail ->> 'BillingCurrency' as billing_currency,
  legacy_usage_detail ->> 'ResourceID' as resource_id
from
  azure_consumption_usage
where
  kind = 'legacy'
  and metric = 'actualcost'
  and filter = 'properties/resourceGroup eq ''turbot_rg''';
+--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+--------------------+>
| name                                 | id                                                                                                                                                                                      | metric     | kind   | billing_account_id |>
+--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+--------------------+>
| 8fcb63ea-9679-2346-1d17-a21fd4a5d929 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202306/providers/Microsoft.Consumption/usageDetails/8fcb63ea-9679-2346-1d17-a21fd4a5d929 | actualcost | legacy | <null>             |>
| 8ea76821-b7ed-5ba8-d7eb-da9465585ba1 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202307/providers/Microsoft.Consumption/usageDetails/8ea76821-b7ed-5ba8-d7eb-da9465585ba1 | actualcost | legacy | <null>             |>
| ce00701f-76f0-4ac3-dbc0-cf27308b05f0 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202308/providers/Microsoft.Consumption/usageDetails/ce00701f-76f0-4ac3-dbc0-cf27308b05f0 | actualcost | legacy | <null>             |>
| 1069146f-0197-5c15-9358-ee2c1c2685ec | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202308/providers/Microsoft.Consumption/usageDetails/1069146f-0197-5c15-9358-ee2c1c2685ec | actualcost | legacy | <null>             |>
| 82ceef73-5ade-820f-ac86-d44e5d880880 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202307/providers/Microsoft.Consumption/usageDetails/82ceef73-5ade-820f-ac86-d44e5d880880 | actualcost | legacy | <null>             |>
| 65b971cd-777a-4a44-ffa3-faa9c806efb2 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202303/providers/Microsoft.Consumption/usageDetails/65b971cd-777a-4a44-ffa3-faa9c806efb2 | actualcost | legacy | <null>             |>
| c5836a2c-8d80-e5e1-8b80-8948642e491e | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202303/providers/Microsoft.Consumption/usageDetails/c5836a2c-8d80-e5e1-8b80-8948642e491e | actualcost | legacy | <null>             |>


> select
  name,
  id,
  metric,
  kind,
  legacy_usage_detail ->> 'BillingAccountID' as billing_account_id,
  legacy_usage_detail ->> 'BillingAccountName' as billing_account_name,
  legacy_usage_detail ->> 'BillingPeriodStartDate' as billing_period_start_date,
  legacy_usage_detail ->> 'BillingPeriodEndDate' as billing_period_end_date,
  legacy_usage_detail ->> 'Cost' as cost,
  legacy_usage_detail ->> 'BillingCurrency' as billing_currency
from
  azure_consumption_usage
where
  kind = 'legacy'
and
  metric = 'actualcost'
order by
  cost desc limit 10;
+--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+--------------------+>
| name                                 | id                                                                                                                                                                                      | metric     | kind   | billing_account_id |>
+--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+--------------------+>
| 92e9a512-1299-4154-9522-18d5133f26a5 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202309/providers/Microsoft.Consumption/usageDetails/92e9a512-1299-4154-9522-18d5133f26a5 | actualcost | legacy | <null>             |>
| aaaf6300-790c-f3f2-b4ac-12a3f4edfd7e | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202306/providers/Microsoft.Consumption/usageDetails/aaaf6300-790c-f3f2-b4ac-12a3f4edfd7e | actualcost | legacy | <null>             |>
| e9b6ecd8-4241-fd8c-de73-08fa9e75bdc4 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202306/providers/Microsoft.Consumption/usageDetails/e9b6ecd8-4241-fd8c-de73-08fa9e75bdc4 | actualcost | legacy | <null>             |>
| 20811d99-2e75-598a-0a50-ab9e8590b9a6 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202306/providers/Microsoft.Consumption/usageDetails/20811d99-2e75-598a-0a50-ab9e8590b9a6 | actualcost | legacy | <null>             |>
| 902e258e-9efd-7262-8cdd-88ec23970bd0 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202306/providers/Microsoft.Consumption/usageDetails/902e258e-9efd-7262-8cdd-88ec23970bd0 | actualcost | legacy | <null>             |>
| 67e0fa5d-a9d0-e20f-97cc-9dfcacad7c36 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202303/providers/Microsoft.Consumption/usageDetails/67e0fa5d-a9d0-e20f-97cc-9dfcacad7c36 | actualcost | legacy | <null>             |>
| 5273fe26-057e-32cd-847e-ce374ab33921 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202304/providers/Microsoft.Consumption/usageDetails/5273fe26-057e-32cd-847e-ce374ab33921 | actualcost | legacy | <null>             |>
| 5273fe26-057e-32cd-847e-ce374ab33921 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202304/providers/Microsoft.Consumption/usageDetails/5273fe26-057e-32cd-847e-ce374ab33921 | actualcost | legacy | <null>             |>
| 104b0770-b055-9a1c-db42-781dcd040c33 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202303/providers/Microsoft.Consumption/usageDetails/104b0770-b055-9a1c-db42-781dcd040c33 | actualcost | legacy | <null>             |>
| 104b0770-b055-9a1c-db42-781dcd040c33 | /subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202303/providers/Microsoft.Consumption/usageDetails/104b0770-b055-9a1c-db42-781dcd040c33 | actualcost | legacy | <null>             |>
+--------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------+--------------------+>

> select * from azure_consumption_usage where expand = 'properties/additionalInfo1' limit 5
[
 {
  "_ctx": {
   "connection_name": "azure",
   "steampipe": {
    "sdk_version": "5.8.0"
   }
  },
  "akas": [
   "azure:///subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202311/providers/Microsoft.Consumption/usageDetails/00f527fe-d79d-0ca8-2960-fdec1e27efbf",
   "azure:///subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/microsoft.billing/billingperiods/202311/providers/microsoft.consumption/usagedetails/00f527fe-d79d-0ca8-2960-fdec1e27efbf"
  ],
  "cloud_environment": "AzurePublicCloud",
  "etag": null,
  "expand": "properties/additionalInfo1",
  "filter": null,
  "id": "/subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/providers/Microsoft.Billing/billingPeriods/202311/providers/Microsoft.Consumption/usageDetails/00f527fe-d79d-0ca8-2960-fdec1e27efbf",
  "kind": "legacy",
  "legacy_usage_detail": {
   "AccountName": null,
   "AccountOwnerID": null,
   "AdditionalInfo": null,
   "BillingAccountID": null,
   "BillingAccountName": null,
   "BillingCurrency": "USD",
   "BillingPeriodEndDate": "2023-11-11T00:00:00Z",
   "BillingPeriodStartDate": "2023-10-12T00:00:00Z",
   "BillingProfileID": "/subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1",
   "BillingProfileName": "newwarriors AAA",
   "ChargeType": "Usage",
   "ConsumedService": "Microsoft.Storage",
   "Cost": "0.000005338078292",
   "CostCenter": null,
   "Date": "2023-10-16T00:00:00Z",
   "EffectivePrice": "0.00355871886121",
   "Frequency": "UsageBased",
   "InvoiceSection": null,
   "IsAzureCreditEligible": false,
   "MeterDetails": null,
   "MeterID": "0b248445-aa24-4fe8-a794-a174929327bd",
   "OfferID": "MS-AZR-0003P",
   "PartNumber": null,
   "PlanName": null,
   "Product": "Tiered Block Blob - All Other Operations - US East",
   "ProductOrderID": null,
   "ProductOrderName": null,
   "PublisherName": null,
   "PublisherType": "Azure",
   "Quantity": "0.0015",
   "ReservationID": null,
   "ReservationName": null,
   "ResourceGroup": "nist-test_group",
   "ResourceID": "/subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/resourceGroups/nist-test_group/providers/Microsoft.Storage/storageAccounts/testimmutablecontainer",
   "ResourceLocation": "US East",
   "ResourceName": "testimmutablecontainer",
   "ServiceInfo1": null,
   "ServiceInfo2": null,
   "SubscriptionID": "3510ae4d-530b-497d-8f30-53b9616fc6c1",
   "SubscriptionName": "newwarriors AAA",
   "Term": null,
   "UnitPrice": "0"
  },
  "metric": null,
  "modern_usage_detail": null,
  "name": "00f527fe-d79d-0ca8-2960-fdec1e27efbf",
  "scope": "/subscriptions/3510ae4d-530b-497d-8f30-53b9616fc6c1/",
  "subscription_id": "3510ae4d-530b-497d-8f30-53b9616fc6c1",
  "tags": {
   "foo": "bar"
  },
  "title": "00f527fe-d79d-0ca8-2960-fdec1e27efbf",
  "type": "Microsoft.Consumption/usageDetails"
 },

@ParthaI ParthaI requested a review from bigdatasourav January 24, 2024 13:55
@ParthaI ParthaI self-assigned this Jan 24, 2024
@ParthaI ParthaI linked an issue Jan 24, 2024 that may be closed by this pull request
func tableAzureConsuptionUsage(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "azure_consumption_usage",
Description: "Azure Consuption Usage",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Description: "Azure Consuption Usage",
Description: "Azure Consumption Usage",


//// LIST FUNCTION

func listConsuptionUsage(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename the function name from listConsuptionUsage to listConsumptionUsage

description: "Allows users to query Azure Cost Management usage details for the defined scope."
---

# Table: azure_consumption_usage - Query Azure Container Groups using SQL
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Table: azure_consumption_usage - Query Azure Container Groups using SQL
# Table: azure_consumption_usage - Query Azure Consumption Usage SQL

legacy_usage_detail ->> 'IsAzureCreditEligible' as is_azure_credit_eligible,
legacy_usage_detail ->> 'ResourceID' as resource_id
from
azure_consumption_usage;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
azure_consumption_usage;
azure_consumption_usage

Comment on lines 128 to 129
from azure_consumption_usage
where
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from azure_consumption_usage
where
from
azure_consumption_usage
where

@bigdatasourav bigdatasourav merged commit 7761a57 into main Jan 30, 2024
1 check passed
@bigdatasourav bigdatasourav deleted the issue-668 branch January 30, 2024 07:14
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

Successfully merging this pull request may close these issues.

Add table azure_consumption_usage
3 participants