From a270787274190328757a7ea2a42a8ed25c20dece Mon Sep 17 00:00:00 2001 From: Michael Flanakin Date: Sun, 15 Dec 2024 03:41:39 -0800 Subject: [PATCH] Update CommitmentDiscountUsage_transform_v1_0() to use parse_resourceid() --- docs/_resources/changelog.md | 1 + .../finops-hub/modules/scripts/IngestionSetup.kql | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/_resources/changelog.md b/docs/_resources/changelog.md index c691d09b9..ce2ddd9cd 100644 --- a/docs/_resources/changelog.md +++ b/docs/_resources/changelog.md @@ -95,6 +95,7 @@ Legend: > ✏️ Changed: > > 1. Update required permissions on hubs page [Required permissions](../docs/_reporting/hubs/README.md). +> 2. Updated `CommitmentDiscountUsage_transform_v1_0()` to use `parse_resourceid()`. 🔍 Optimization engine {: .fs-5 .fw-500 .mt-4 mb-0 } diff --git a/src/templates/finops-hub/modules/scripts/IngestionSetup.kql b/src/templates/finops-hub/modules/scripts/IngestionSetup.kql index 8214d8969..88bc76b7e 100644 --- a/src/templates/finops-hub/modules/scripts/IngestionSetup.kql +++ b/src/templates/finops-hub/modules/scripts/IngestionSetup.kql @@ -1245,12 +1245,10 @@ CommitmentDiscountUsage_transform_v1_0() // // Handle resource columns | extend ResourceId = tolower(InstanceId) - // TODO: Switch to use parse_resourceid() - | parse ResourceId with "/subscriptions/" SubAccountId "/resourcegroups/" x_ResourceGroupName "/providers/" tmp_ResourceProvider "/" tmp_ResourceProviderPath - | extend segments = split(tmp_ResourceProviderPath, '/') - | mv-apply element = segments on (extend index = row_number() | where index % 2 == 0 | summarize ResourceName = strcat_array(make_list(element), '/')) - | mv-apply element = segments on (extend index = row_number() | where index % 2 == 1 | summarize x_ResourceType = strcat_array(make_list(element), '/')) - | extend x_ResourceType = strcat(tmp_ResourceProvider, '/', x_ResourceType) + | extend tmp_ResourceDetails = parse_resourceid(ResourceId) + | extend SubAccountId = tmp_ResourceDetails.SubAccountId + | extend x_ResourceGroupName = tmp_ResourceDetails.x_ResourceGroupName + | extend x_ResourceType = tmp_ResourceDetails.x_ResourceType | lookup kind=leftouter (ResourceTypes | distinct x_ResourceType, ResourceType = SingularDisplayName) on x_ResourceType | lookup kind=leftouter (Services | distinct x_ResourceType, ServiceName, ServiceCategory, x_ServiceModel) on x_ResourceType // @@ -1276,7 +1274,7 @@ CommitmentDiscountUsage_transform_v1_0() x_CommitmentDiscountNormalizedRatio = InstanceFlexibilityRatio, x_CommitmentDiscountQuantity = UsedHours * InstanceFlexibilityRatio, x_IngestionTime = ingestion_time(), // Hubs add-on - x_ResourceGroupName = extract('/resourcegroups/([^/]+)/', 1, ResourceId), + x_ResourceGroupName, x_ResourceType, // x_RowId = hash_sha256(strcat( // // DO NOT CHANGE COLUMNS OR COLUMN ORDER