Skip to content

Commit

Permalink
fix: correctly flatten nested keys when uploading to usage api (#2912)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim775 committed Mar 1, 2024
1 parent ed0ce13 commit 276bca8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/prices/usages.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@ func UploadCloudResourceIDs(ctx *config.RunContext, project *schema.Project) err
}

func flattenUsageKeys(usageSchema []*schema.UsageItem) []string {
usageKeys := make([]string, len(usageSchema))
for i, usageItem := range usageSchema {
usageKeys := make([]string, 0, len(usageSchema))
for _, usageItem := range usageSchema {
if usageItem.ValueType == schema.SubResourceUsage {
ru := usageItem.DefaultValue.(*usage.ResourceUsage)
// recursively flatten any nested keys, then add them to the current list
for _, nestedKey := range flattenUsageKeys(ru.Items) {
usageKeys[i] = usageItem.Key + "." + nestedKey
usageKeys = append(usageKeys, usageItem.Key+"."+nestedKey)
}
} else {
usageKeys[i] = usageItem.Key
usageKeys = append(usageKeys, usageItem.Key)
}
}

Expand Down

0 comments on commit 276bca8

Please sign in to comment.