66
77 "github.com/Azure/azure-container-networking/common"
88 "github.com/Azure/azure-container-networking/npm/metrics"
9+ "github.com/Azure/azure-container-networking/npm/util"
910 npmerrors "github.com/Azure/azure-container-networking/npm/util/errors"
1011 "k8s.io/klog"
1112)
@@ -52,6 +53,7 @@ func (iMgr *IPSetManager) ResetIPSets() error {
5253 defer iMgr .Unlock ()
5354 err := iMgr .resetIPSets ()
5455 if err != nil {
56+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to reset ipsetmanager: %s" , err .Error ())
5557 return fmt .Errorf ("error while resetting ipsetmanager: %w" , err )
5658 }
5759 // TODO update prometheus metrics here instead of in OS-specific functions (done in Linux right now)
@@ -122,12 +124,16 @@ func (iMgr *IPSetManager) AddReference(setName, referenceName string, referenceT
122124 if referenceType == NetPolType {
123125 npmErrorString = npmerrors .AddNetPolReference
124126 }
125- return npmerrors .Errorf (npmErrorString , false , fmt .Sprintf ("ipset %s does not exist" , setName ))
127+ msg := fmt .Sprintf ("ipset %s does not exist" , setName )
128+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to add reference: %s" , msg )
129+ return npmerrors .Errorf (npmErrorString , false , msg )
126130 }
127131
128132 set := iMgr .setMap [setName ]
129133 if referenceType == SelectorType && ! set .canSetBeSelectorIPSet () {
130- return npmerrors .Errorf (npmerrors .AddSelectorReference , false , fmt .Sprintf ("ipset %s is not a selector ipset it is of type %s" , setName , set .Type .String ()))
134+ msg := fmt .Sprintf ("ipset %s is not a selector ipset it is of type %s" , setName , set .Type .String ())
135+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to add reference: %s" , msg )
136+ return npmerrors .Errorf (npmerrors .AddSelectorReference , false , msg )
131137 }
132138 wasInKernel := iMgr .shouldBeInKernel (set )
133139 set .addReference (referenceName , referenceType )
@@ -152,7 +158,9 @@ func (iMgr *IPSetManager) DeleteReference(setName, referenceName string, referen
152158 if referenceType == NetPolType {
153159 npmErrorString = npmerrors .DeleteNetPolReference
154160 }
155- return npmerrors .Errorf (npmErrorString , false , fmt .Sprintf ("ipset %s does not exist" , setName ))
161+ msg := fmt .Sprintf ("ipset %s does not exist" , setName )
162+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to delete reference: %s" , msg )
163+ return npmerrors .Errorf (npmErrorString , false , msg )
156164 }
157165
158166 set := iMgr .setMap [setName ]
@@ -188,7 +196,9 @@ func (iMgr *IPSetManager) AddToSets(addToSets []*IPSetMetadata, ip, podKey strin
188196 set = iMgr .setMap [prefixedName ]
189197 }
190198 if set .Kind != HashSet {
191- return npmerrors .Errorf (npmerrors .AppendIPSet , false , fmt .Sprintf ("ipset %s is not a hash set" , prefixedName ))
199+ msg := fmt .Sprintf ("ipset %s is not a hash set" , prefixedName )
200+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to add to sets: %s" , msg )
201+ return npmerrors .Errorf (npmerrors .AppendIPSet , false , msg )
192202 }
193203
194204 // 2. add ip to the set, and update the pod key
@@ -219,7 +229,9 @@ func (iMgr *IPSetManager) RemoveFromSets(removeFromSets []*IPSetMetadata, ip, po
219229 continue
220230 }
221231 if set .Kind != HashSet {
222- return npmerrors .Errorf (npmerrors .DeleteIPSet , false , fmt .Sprintf ("ipset %s is not a hash set" , prefixedName ))
232+ msg := fmt .Sprintf ("ipset %s is not a hash set" , prefixedName )
233+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to remove from sets: %s" , msg )
234+ return npmerrors .Errorf (npmerrors .DeleteIPSet , false , msg )
223235 }
224236
225237 // 2. remove ip from the set
@@ -264,7 +276,9 @@ func (iMgr *IPSetManager) AddToLists(listMetadatas, setMetadatas []*IPSetMetadat
264276 // Nested IPSets are only supported for windows
265277 // Check if we want to actually use that support
266278 if set .Kind != HashSet {
267- return npmerrors .Errorf (npmerrors .AppendIPSet , false , fmt .Sprintf ("ipset %s is not a hash set and nested list sets are not supported" , setName ))
279+ msg := fmt .Sprintf ("ipset %s is not a hash set and nested list sets are not supported" , setName )
280+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to add to lists: %s" , msg )
281+ return npmerrors .Errorf (npmerrors .AppendIPSet , false , msg )
268282 }
269283 }
270284
@@ -279,7 +293,9 @@ func (iMgr *IPSetManager) AddToLists(listMetadatas, setMetadatas []*IPSetMetadat
279293 }
280294
281295 if list .Kind != ListSet {
282- return npmerrors .Errorf (npmerrors .AppendIPSet , false , fmt .Sprintf ("ipset %s is not a list set" , listName ))
296+ msg := fmt .Sprintf ("ipset %s is not a list set" , listName )
297+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to add to lists: %s" , msg )
298+ return npmerrors .Errorf (npmerrors .AppendIPSet , false , msg )
283299 }
284300
285301 modified := false
@@ -323,7 +339,9 @@ func (iMgr *IPSetManager) RemoveFromList(listMetadata *IPSetMetadata, setMetadat
323339 }
324340
325341 if list .Kind != ListSet {
326- return npmerrors .Errorf (npmerrors .DeleteIPSet , false , fmt .Sprintf ("ipset %s is not a list set" , listName ))
342+ msg := fmt .Sprintf ("ipset %s is not a list set" , listName )
343+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to remove from list: %s" , msg )
344+ return npmerrors .Errorf (npmerrors .DeleteIPSet , false , msg )
327345 }
328346
329347 modified := false
@@ -340,7 +358,9 @@ func (iMgr *IPSetManager) RemoveFromList(listMetadata *IPSetMetadata, setMetadat
340358 if modified {
341359 iMgr .modifyCacheForKernelMemberUpdate (list )
342360 }
343- return npmerrors .Errorf (npmerrors .DeleteIPSet , false , fmt .Sprintf ("ipset %s is not a hash set and nested list sets are not supported" , memberName ))
361+ msg := fmt .Sprintf ("ipset %s is not a hash set and nested list sets are not supported" , memberName )
362+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to remove from list: %s" , msg )
363+ return npmerrors .Errorf (npmerrors .DeleteIPSet , false , msg )
344364 }
345365
346366 // 2. remove member from the list
@@ -382,6 +402,7 @@ func (iMgr *IPSetManager) ApplyIPSets() error {
382402 // Call the appropriate apply ipsets
383403 err := iMgr .applyIPSets ()
384404 if err != nil {
405+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: failed to apply ipsets: %s" , err .Error ())
385406 return err
386407 }
387408
@@ -494,12 +515,17 @@ func (iMgr *IPSetManager) modifyCacheForKernelMemberUpdate(set *IPSet) {
494515// sanitizeDirtyCache will check if any set marked as delete is in toAddUpdate
495516// if so will not delete it
496517func (iMgr * IPSetManager ) sanitizeDirtyCache () {
518+ anyProblems := false
497519 for setName := range iMgr .toDeleteCache {
498520 _ , ok := iMgr .toAddOrUpdateCache [setName ]
499521 if ok {
500- klog .Errorf ("[IPSetManager] Unexpected state in dirty cache %s set is part of both update and delete caches \n " , setName )
522+ klog .Errorf ("[IPSetManager] Unexpected state in dirty cache %s set is part of both update and delete caches" , setName )
523+ anyProblems = true
501524 }
502525 }
526+ if anyProblems {
527+ metrics .SendErrorLogAndMetric (util .IpsmID , "error: some dirty cache sets are part of both update and delete caches" )
528+ }
503529}
504530
505531func (iMgr * IPSetManager ) clearDirtyCache () {
0 commit comments