Ver Fonte

Add additional comments

Signed-off-by: Sean Holcomb <seanholcomb@gmail.com>
Sean Holcomb há 2 anos atrás
pai
commit
d92bc0e10d
2 ficheiros alterados com 6 adições e 2 exclusões
  1. 1 0
      core/pkg/opencost/cloudcost.go
  2. 5 2
      core/pkg/opencost/cloudcostprops.go

+ 1 - 0
core/pkg/opencost/cloudcost.go

@@ -345,6 +345,7 @@ func (ccs *CloudCostSet) Insert(cc *CloudCost) error {
 		ccs.CloudCosts = map[string]*CloudCost{}
 	}
 
+	// If the Aggregation properties is not set the returned key will be a hash of the properties values
 	ccKey := cc.Properties.GenerateKey(ccs.AggregationProperties)
 
 	// Add the given CloudCost to the existing entry, if there is one;

+ 5 - 2
core/pkg/opencost/cloudcostprops.go

@@ -290,7 +290,9 @@ func (ccp *CloudCostProperties) GenerateKey(props []string) string {
 }
 
 // HashKey creates a key on the entire property set including labels of a uniform length.
-// This key is meant to be used when constructing unaggregated CloudCostSet for storage
+// This key is meant to be used when constructing unaggregated CloudCostSet for storage.
+// Including labels prevents CloudCosts that are missing providerIDs from having their labels
+// erased as they are saved to cloud cost set.
 func (ccp *CloudCostProperties) hashKey() string {
 	builder := strings.Builder{}
 	builder.WriteString(ccp.ProviderID)
@@ -300,7 +302,8 @@ func (ccp *CloudCostProperties) hashKey() string {
 	builder.WriteString(ccp.Service)
 	builder.WriteString(ccp.Category)
 
-	// Sort label keys before adding key/value pairs to the hash string
+	// Sort label keys before adding key/value pairs to the hash string to ensure label set is
+	// always returns the same key
 	labelKeys := maps.Keys(ccp.Labels)
 	sort.Strings(labelKeys)
 	for _, k := range labelKeys {