MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / resolveUsageQty

Function resolveUsageQty

internal/estimate/estimator.go:642–691  ·  view source on GitHub ↗

resolveUsageQty returns the monthly quantity to use for a resource. Priority: usageMap (user-supplied) > rawType key > service/subLabel key > service key > global default. All keys are looked up in serviceUsageDefaults — rawType (e.g. "aws:cloudwatch/metricAlarm:MetricAlarm"), "Service/SubLabel", an

(resourceName, service, subLabel, rawType string, usageMap map[string]float64)

Source from the content-addressed store, hash-verified

640// All keys are looked up in serviceUsageDefaults — rawType (e.g. "aws:cloudwatch/metricAlarm:MetricAlarm"),
641// "Service/SubLabel", and bare "Service" are all valid keys in that map.
642func resolveUsageQty(resourceName, service, subLabel, rawType string, usageMap map[string]float64) (qty float64, isDefault bool) {
643 // 1. User-supplied value takes highest priority.
644 if usageMap != nil {
645 // 1a. Exact name/SubLabel match — most specific, for 1:N resources
646 // e.g. --usage my-lambda/Requests=5000000
647 if subLabel != "" {
648 if v, ok := usageMap[resourceName+"/"+subLabel]; ok && v > 0 {
649 return v, false
650 }
651 }
652 // 1b. Bare name match — applies to all sub-labels of this resource
653 // e.g. --usage my-lambda=5000000
654 if v, ok := usageMap[resourceName]; ok && v > 0 {
655 return v, false
656 }
657 }
658 // 2. rawType exact match (e.g. "aws:cloudwatch/metricAlarm:MetricAlarm" → 1).
659 if rawType != "" {
660 if v, ok := serviceUsageDefaults[rawType]; ok {
661 return v, true
662 }
663 }
664 // 3. Per-service/subLabel default — try exact then case-insensitive.
665 if subLabel != "" {
666 key := service + "/" + subLabel
667 if v, ok := serviceUsageDefaults[key]; ok {
668 return v, true
669 }
670 keyLower := strings.ToLower(key)
671 for k, v := range serviceUsageDefaults {
672 if strings.ToLower(k) == keyLower {
673 return v, true
674 }
675 }
676 }
677 // 4. Per-service default — try exact then case-insensitive.
678 if service != "" {
679 if v, ok := serviceUsageDefaults[service]; ok {
680 return v, true
681 }
682 serviceLower := strings.ToLower(service)
683 for k, v := range serviceUsageDefaults {
684 if strings.ToLower(k) == serviceLower {
685 return v, true
686 }
687 }
688 }
689 // 5. Global fallback.
690 return defaultUsageQty, true
691}
692
693// calcUsageMonthlyCost computes the monthly cost for a usage-based resource
694// given a monthly quantity. It uses the OnDemand entry's tiers when available,

Calls

no outgoing calls