Przeglądaj źródła

Added CostSource to CustomCost responses, aggregations, and filtering.

Signed-off-by: Nik Willwerth <nwillwerth@kubecost.com>
Nik Willwerth 2 lat temu
rodzic
commit
5f47a294ae

+ 2 - 0
pkg/customcost/matcher.go

@@ -48,6 +48,8 @@ func customCostFieldMap(cc *CustomCost, identifier ast.Identifier) (string, erro
 		return cc.UsageUnit, nil
 	case CustomCostDomainProp:
 		return cc.Domain, nil
+	case CustomCostCostSourceProp:
+		return cc.CostSource, nil
 	}
 
 	return "", fmt.Errorf("failed to find string identifier on CustomCost: %s", identifier.Field.Name)

+ 1 - 0
pkg/customcost/parser.go

@@ -14,6 +14,7 @@ var customCostFilterFields = []*ast.Field{
 	ast.NewField(CustomCostProviderIdProp),
 	ast.NewField(CustomCostUsageUnitProp),
 	ast.NewField(CustomCostDomainProp),
+	ast.NewField(CustomCostCostSourceProp),
 }
 
 // NewCustomCostFilterParser creates a new `ast.FilterParser` implementation

+ 3 - 0
pkg/customcost/props.go

@@ -17,6 +17,7 @@ const (
 	CustomCostProviderIdProp                        = "providerId"
 	CustomCostUsageUnitProp                         = "usageUnit"
 	CustomCostDomainProp                            = "domain"
+	CustomCostCostSourceProp                        = "costSource"
 )
 
 func ParseCustomCostProperties(props []string) ([]CustomCostProperty, error) {
@@ -58,6 +59,8 @@ func ParseCustomCostProperty(text string) (CustomCostProperty, error) {
 		return CustomCostUsageUnitProp, nil
 	case strings.TrimSpace(strings.ToLower(CustomCostDomainProp)):
 		return CustomCostDomainProp, nil
+	case strings.TrimSpace(strings.ToLower(CustomCostCostSourceProp)):
+		return CustomCostCostSourceProp, nil
 	}
 
 	return "", fmt.Errorf("invalid custom cost property: %s", text)

+ 8 - 0
pkg/customcost/types.go

@@ -48,6 +48,7 @@ type CustomCost struct {
 	UsageQuantity  float32 `json:"usage_quantity"`
 	UsageUnit      string  `json:"usage_unit"`
 	Domain         string  `json:"domain"`
+	CostSource     string  `json:"cost_source"`
 	Aggregate      string  `json:"aggregate"`
 }
 
@@ -91,6 +92,7 @@ func ParseCustomCostResponse(ccResponse *pb.CustomCostResponse) []*CustomCost {
 			UsageQuantity:  cost.GetUsageQuantity(),
 			UsageUnit:      cost.GetUsageUnit(),
 			Domain:         ccResponse.GetDomain(),
+			CostSource:     ccResponse.GetCostSource(),
 		}
 	}
 
@@ -145,6 +147,10 @@ func (cc *CustomCost) Add(other *CustomCost) {
 		cc.Domain = ""
 	}
 
+	if cc.CostSource != other.CostSource {
+		cc.CostSource = ""
+	}
+
 	if cc.Aggregate != other.Aggregate {
 		cc.Aggregate = ""
 	}
@@ -219,6 +225,8 @@ func generateAggKey(cc *CustomCost, aggregateBy []CustomCostProperty) (string, e
 			aggKey = cc.UsageUnit
 		} else if agg == CustomCostDomainProp {
 			aggKey = cc.Domain
+		} else if agg == CustomCostCostSourceProp {
+			aggKey = cc.CostSource
 		} else {
 			return "", fmt.Errorf("unsupported aggregation type: %s", agg)
 		}