@@ -97,7 +97,7 @@ func (ipsMgr *IpsetManager) CreateList(listName string) error {
9797 }
9898 log .Logf ("Creating List: %+v" , entry )
9999 if errCode , err := ipsMgr .Run (entry ); err != nil && errCode != 1 {
100- metrics .SendErrorMetric (util .IpsmID , "Error: failed to create ipset list %s." , listName )
100+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to create ipset list %s." , listName )
101101 return err
102102 }
103103
@@ -118,7 +118,7 @@ func (ipsMgr *IpsetManager) DeleteList(listName string) error {
118118 return nil
119119 }
120120
121- metrics .SendErrorMetric (util .IpsmID , "Error: failed to delete ipset %s %+v" , listName , entry )
121+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to delete ipset %s %+v" , listName , entry )
122122 return err
123123 }
124124
@@ -148,7 +148,7 @@ func (ipsMgr *IpsetManager) AddToList(listName string, setName string) error {
148148 }
149149
150150 if errCode , err := ipsMgr .Run (entry ); err != nil && errCode != 1 {
151- metrics .SendErrorMetric (util .IpsmID , "Error: failed to create ipset rules. rule: %+v" , entry )
151+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to create ipset rules. rule: %+v" , entry )
152152 return err
153153 }
154154
@@ -160,7 +160,7 @@ func (ipsMgr *IpsetManager) AddToList(listName string, setName string) error {
160160// DeleteFromList removes an ipset to an ipset list.
161161func (ipsMgr * IpsetManager ) DeleteFromList (listName string , setName string ) error {
162162 if _ , exists := ipsMgr .listMap [listName ]; ! exists {
163- metrics .SendErrorMetric (util .IpsmID , "ipset list with name %s not found" , listName )
163+ metrics .SendErrorLogAndMetric (util .IpsmID , "ipset list with name %s not found" , listName )
164164 return nil
165165 }
166166
@@ -172,7 +172,7 @@ func (ipsMgr *IpsetManager) DeleteFromList(listName string, setName string) erro
172172 }
173173
174174 if _ , err := ipsMgr .Run (entry ); err != nil {
175- metrics .SendErrorMetric (util .IpsmID , "Error: failed to delete ipset entry. %+v" , entry )
175+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to delete ipset entry. %+v" , entry )
176176 return err
177177 }
178178
@@ -183,7 +183,7 @@ func (ipsMgr *IpsetManager) DeleteFromList(listName string, setName string) erro
183183
184184 if len (ipsMgr .listMap [listName ].elements ) == 0 {
185185 if err := ipsMgr .DeleteList (listName ); err != nil {
186- metrics .SendErrorMetric (util .IpsmID , "Error: failed to delete ipset list %s." , listName )
186+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to delete ipset list %s." , listName )
187187 return err
188188 }
189189 }
@@ -208,7 +208,7 @@ func (ipsMgr *IpsetManager) CreateSet(setName string, spec []string) error {
208208 }
209209 log .Logf ("Creating Set: %+v" , entry )
210210 if errCode , err := ipsMgr .Run (entry ); err != nil && errCode != 1 {
211- metrics .SendErrorMetric (util .IpsmID , "Error: failed to create ipset." )
211+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to create ipset." )
212212 return err
213213 }
214214
@@ -224,7 +224,7 @@ func (ipsMgr *IpsetManager) CreateSet(setName string, spec []string) error {
224224// DeleteSet removes a set from ipset.
225225func (ipsMgr * IpsetManager ) DeleteSet (setName string ) error {
226226 if _ , exists := ipsMgr .setMap [setName ]; ! exists {
227- metrics .SendErrorMetric (util .IpsmID , "ipset with name %s not found" , setName )
227+ metrics .SendErrorLogAndMetric (util .IpsmID , "ipset with name %s not found" , setName )
228228 return nil
229229 }
230230
@@ -238,7 +238,7 @@ func (ipsMgr *IpsetManager) DeleteSet(setName string) error {
238238 return nil
239239 }
240240
241- metrics .SendErrorMetric (util .IpsmID , "Error: failed to delete ipset %s. Entry: %+v" , setName , entry )
241+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to delete ipset %s. Entry: %+v" , setName , entry )
242242 return err
243243 }
244244
@@ -287,7 +287,7 @@ func (ipsMgr *IpsetManager) AddToSet(setName, ip, spec, podUid string) error {
287287 }
288288
289289 if errCode , err := ipsMgr .Run (entry ); err != nil && errCode != 1 {
290- metrics .SendErrorMetric (util .IpsmID , "Error: failed to create ipset rules. %+v" , entry )
290+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to create ipset rules. %+v" , entry )
291291 return err
292292 }
293293
@@ -331,7 +331,7 @@ func (ipsMgr *IpsetManager) DeleteFromSet(setName, ip, podUid string) error {
331331 return nil
332332 }
333333
334- metrics .SendErrorMetric (util .IpsmID , "Error: failed to delete ipset entry. Entry: %+v" , entry )
334+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to delete ipset entry. Entry: %+v" , entry )
335335 return err
336336 }
337337
@@ -356,7 +356,7 @@ func (ipsMgr *IpsetManager) Clean() error {
356356 }
357357
358358 if err := ipsMgr .DeleteSet (setName ); err != nil {
359- metrics .SendErrorMetric (util .IpsmID , "Error: failed to clean ipset" )
359+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to clean ipset" )
360360 return err
361361 }
362362 }
@@ -367,7 +367,7 @@ func (ipsMgr *IpsetManager) Clean() error {
367367 }
368368
369369 if err := ipsMgr .DeleteList (listName ); err != nil {
370- metrics .SendErrorMetric (util .IpsmID , "Error: failed to clean ipset list" )
370+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to clean ipset list" )
371371 return err
372372 }
373373 }
@@ -381,13 +381,13 @@ func (ipsMgr *IpsetManager) Destroy() error {
381381 operationFlag : util .IpsetFlushFlag ,
382382 }
383383 if _ , err := ipsMgr .Run (entry ); err != nil {
384- metrics .SendErrorMetric (util .IpsmID , "Error: failed to flush ipset" )
384+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to flush ipset" )
385385 return err
386386 }
387387
388388 entry .operationFlag = util .IpsetDestroyFlag
389389 if _ , err := ipsMgr .Run (entry ); err != nil {
390- metrics .SendErrorMetric (util .IpsmID , "Error: failed to destroy ipset" )
390+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to destroy ipset" )
391391 return err
392392 }
393393
@@ -407,7 +407,7 @@ func (ipsMgr *IpsetManager) Run(entry *ipsEntry) (int, error) {
407407 if msg , failed := err .(* exec.ExitError ); failed {
408408 errCode := msg .Sys ().(syscall.WaitStatus ).ExitStatus ()
409409 if errCode > 0 {
410- metrics .SendErrorMetric (util .IpsmID , "Error: There was an error running command: [%s %v] Stderr: [%v, %s]" , cmdName , strings .Join (cmdArgs , " " ), err , strings .TrimSuffix (string (msg .Stderr ), "\n " ))
410+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: There was an error running command: [%s %v] Stderr: [%v, %s]" , cmdName , strings .Join (cmdArgs , " " ), err , strings .TrimSuffix (string (msg .Stderr ), "\n " ))
411411 }
412412
413413 return errCode , err
@@ -424,7 +424,7 @@ func (ipsMgr *IpsetManager) Save(configFile string) error {
424424
425425 cmd := exec .Command (util .Ipset , util .IpsetSaveFlag , util .IpsetFileFlag , configFile )
426426 if err := cmd .Start (); err != nil {
427- metrics .SendErrorMetric (util .IpsmID , "Error: failed to save ipset to file." )
427+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to save ipset to file." )
428428 return err
429429 }
430430 cmd .Wait ()
@@ -440,7 +440,7 @@ func (ipsMgr *IpsetManager) Restore(configFile string) error {
440440
441441 f , err := os .Stat (configFile )
442442 if err != nil {
443- metrics .SendErrorMetric (util .IpsmID , "Error: failed to get file %s stat from ipsm.Restore" , configFile )
443+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to get file %s stat from ipsm.Restore" , configFile )
444444 return err
445445 }
446446
@@ -452,7 +452,7 @@ func (ipsMgr *IpsetManager) Restore(configFile string) error {
452452
453453 cmd := exec .Command (util .Ipset , util .IpsetRestoreFlag , util .IpsetFileFlag , configFile )
454454 if err := cmd .Start (); err != nil {
455- metrics .SendErrorMetric (util .IpsmID , "Error: failed to to restore ipset from file." )
455+ metrics .SendErrorLogAndMetric (util .IpsmID , "Error: failed to to restore ipset from file." )
456456 return err
457457 }
458458 cmd .Wait ()
@@ -472,13 +472,13 @@ func (ipsMgr *IpsetManager) DestroyNpmIpsets() error {
472472 if msg , failed := err .(* exec.ExitError ); failed {
473473 errCode := msg .Sys ().(syscall.WaitStatus ).ExitStatus ()
474474 if errCode > 0 {
475- metrics .SendErrorMetric (util .IpsmID , "{DestroyNpmIpsets} Error: There was an error running command: [%s] Stderr: [%v, %s]" , cmdName , err , strings .TrimSuffix (string (msg .Stderr ), "\n " ))
475+ metrics .SendErrorLogAndMetric (util .IpsmID , "{DestroyNpmIpsets} Error: There was an error running command: [%s] Stderr: [%v, %s]" , cmdName , err , strings .TrimSuffix (string (msg .Stderr ), "\n " ))
476476 }
477477
478478 return err
479479 }
480480 if reply == nil {
481- metrics .SendErrorMetric (util .IpsmID , "{DestroyNpmIpsets} Received empty string from ipset list while destroying azure-npm ipsets" )
481+ metrics .SendErrorLogAndMetric (util .IpsmID , "{DestroyNpmIpsets} Received empty string from ipset list while destroying azure-npm ipsets" )
482482 return nil
483483 }
484484
@@ -516,15 +516,15 @@ func (ipsMgr *IpsetManager) DestroyNpmIpsets() error {
516516 }
517517
518518 if _ , err := ipsMgr .Run (entry ); err != nil {
519- metrics .SendErrorMetric (util .IpsmID , "{DestroyNpmIpsets} Error: failed to flush ipset %s" , ipsetName )
519+ metrics .SendErrorLogAndMetric (util .IpsmID , "{DestroyNpmIpsets} Error: failed to flush ipset %s" , ipsetName )
520520 }
521521 }
522522
523523 for _ , ipsetName := range ipsetLists {
524524 entry .operationFlag = util .IpsetDestroyFlag
525525 entry .set = ipsetName
526526 if _ , err := ipsMgr .Run (entry ); err != nil {
527- metrics .SendErrorMetric (util .IpsmID , "{DestroyNpmIpsets} Error: failed to destroy ipset %s" , ipsetName )
527+ metrics .SendErrorLogAndMetric (util .IpsmID , "{DestroyNpmIpsets} Error: failed to destroy ipset %s" , ipsetName )
528528 }
529529 }
530530
0 commit comments