Forráskód Böngészése

Filters v2: Log on default cases in Match()

An unfortunate necessity because its hard to make Go force an exhaustive
pattern match.
Michael Dresser 4 éve
szülő
commit
c28979a954
1 módosított fájl, 4 hozzáadás és 2 törlés
  1. 4 2
      pkg/kubecost/allocationfilter.go

+ 4 - 2
pkg/kubecost/allocationfilter.go

@@ -1,5 +1,7 @@
 package kubecost
 
+import "github.com/kubecost/cost-model/pkg/log"
+
 // FilterCondition is an enum that represents Allocation-specific fields
 // that can be filtered on (namespace, label, etc.)
 type FilterField int
@@ -135,7 +137,7 @@ func (filter AllocationFilterCondition) Matches(a *Allocation) bool {
 			valueToCompare = val
 		}
 	default:
-		// TODO: log an error here? this should never happen
+		log.Errorf("Allocation Filter: Unhandled filter field. This is a filter implementation error and requires immediate patching. Field: %d", filter.Field)
 		return false
 	}
 
@@ -167,7 +169,7 @@ func (filter AllocationFilterCondition) Matches(a *Allocation) bool {
 			return true
 		}
 	default:
-		// TODO: log an error here? this should never happen
+		log.Errorf("Allocation Filter: Unhandled filter op. This is a filter implementation error and requires immediate patching. Op: %d", filter.Op)
 		return false
 	}