Skip to content

Commit 0835cae

Browse files
authored
Change AI log and metrics sending function name in NPM. (#737)
1 parent 8ae7b8a commit 0835cae

File tree

4 files changed

+53
-53
lines changed

4 files changed

+53
-53
lines changed

npm/ipsm/ipsm.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
161161
func (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.
225225
func (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

npm/iptm/iptm.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"syscall"
1212
"time"
1313

14-
"golang.org/x/sys/unix"
1514
"github.com/Azure/azure-container-networking/log"
1615
"github.com/Azure/azure-container-networking/npm/metrics"
1716
"github.com/Azure/azure-container-networking/npm/util"
17+
"golang.org/x/sys/unix"
1818
"k8s.io/apimachinery/pkg/util/wait"
1919
// utiliptables "k8s.io/kubernetes/pkg/util/iptables"
2020
)
@@ -88,7 +88,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
8888
iptMgr.OperationFlag = util.IptablesInsertionFlag
8989
entry.Specs = append([]string{index}, entry.Specs...)
9090
if _, err = iptMgr.Run(entry); err != nil {
91-
metrics.SendErrorMetric(util.IptmID, "Error: failed to add AZURE-NPM chain to FORWARD chain.")
91+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add AZURE-NPM chain to FORWARD chain.")
9292
return err
9393
}
9494
}
@@ -109,7 +109,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
109109
if !exists {
110110
iptMgr.OperationFlag = util.IptablesAppendFlag
111111
if _, err := iptMgr.Run(entry); err != nil {
112-
metrics.SendErrorMetric(util.IptmID, "Error: failed to add AZURE-NPM-INGRESS-PORT chain to AZURE-NPM chain.")
112+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add AZURE-NPM-INGRESS-PORT chain to AZURE-NPM chain.")
113113
return err
114114
}
115115
}
@@ -135,7 +135,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
135135
if !exists {
136136
iptMgr.OperationFlag = util.IptablesAppendFlag
137137
if _, err := iptMgr.Run(entry); err != nil {
138-
metrics.SendErrorMetric(util.IptmID, "Error: failed to add AZURE-NPM-INGRESS-PORT chain to AZURE-NPM chain.")
138+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add AZURE-NPM-INGRESS-PORT chain to AZURE-NPM chain.")
139139
return err
140140
}
141141
}
@@ -161,7 +161,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
161161
if !exists {
162162
iptMgr.OperationFlag = util.IptablesAppendFlag
163163
if _, err := iptMgr.Run(entry); err != nil {
164-
metrics.SendErrorMetric(util.IptmID, "Error: failed to add AZURE-NPM-TARGET-SETS chain to AZURE-NPM chain.")
164+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add AZURE-NPM-TARGET-SETS chain to AZURE-NPM chain.")
165165
return err
166166
}
167167
}
@@ -184,7 +184,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
184184
if !exists {
185185
iptMgr.OperationFlag = util.IptablesAppendFlag
186186
if _, err = iptMgr.Run(entry); err != nil {
187-
metrics.SendErrorMetric(util.IptmID, "Error: failed to add default allow CONNECTED/RELATED rule to AZURE-NPM chain.")
187+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add default allow CONNECTED/RELATED rule to AZURE-NPM chain.")
188188
return err
189189
}
190190
}
@@ -214,7 +214,7 @@ func (iptMgr *IptablesManager) UninitNpmChains() error {
214214
iptMgr.OperationFlag = util.IptablesDeletionFlag
215215
errCode, err := iptMgr.Run(entry)
216216
if errCode != iptablesErrDoesNotExist && err != nil {
217-
metrics.SendErrorMetric(util.IptmID, "Error: failed to add default allow CONNECTED/RELATED rule to AZURE-NPM chain.")
217+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add default allow CONNECTED/RELATED rule to AZURE-NPM chain.")
218218
return err
219219
}
220220

@@ -225,7 +225,7 @@ func (iptMgr *IptablesManager) UninitNpmChains() error {
225225
}
226226
errCode, err := iptMgr.Run(entry)
227227
if errCode != iptablesErrDoesNotExist && err != nil {
228-
metrics.SendErrorMetric(util.IptmID, "Error: failed to flush iptables chain %s.", chain)
228+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to flush iptables chain %s.", chain)
229229
}
230230
}
231231

@@ -266,7 +266,7 @@ func (iptMgr *IptablesManager) AddChain(chain string) error {
266266
return nil
267267
}
268268

269-
metrics.SendErrorMetric(util.IptmID, "Error: failed to create iptables chain %s.", entry.Chain)
269+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to create iptables chain %s.", entry.Chain)
270270
return err
271271
}
272272

@@ -286,7 +286,7 @@ func (iptMgr *IptablesManager) DeleteChain(chain string) error {
286286
return nil
287287
}
288288

289-
metrics.SendErrorMetric(util.IptmID, "Error: failed to delete iptables chain %s.", entry.Chain)
289+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to delete iptables chain %s.", entry.Chain)
290290
return err
291291
}
292292

@@ -305,7 +305,7 @@ func (iptMgr *IptablesManager) Add(entry *IptEntry) error {
305305
iptMgr.OperationFlag = util.IptablesInsertionFlag
306306
}
307307
if _, err := iptMgr.Run(entry); err != nil {
308-
metrics.SendErrorMetric(util.IptmID, "Error: failed to create iptables rules.")
308+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to create iptables rules.")
309309
return err
310310
}
311311

@@ -330,7 +330,7 @@ func (iptMgr *IptablesManager) Delete(entry *IptEntry) error {
330330

331331
iptMgr.OperationFlag = util.IptablesDeletionFlag
332332
if _, err := iptMgr.Run(entry); err != nil {
333-
metrics.SendErrorMetric(util.IptmID, "Error: failed to delete iptables rules.")
333+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to delete iptables rules.")
334334
return err
335335
}
336336

@@ -360,7 +360,7 @@ func (iptMgr *IptablesManager) Run(entry *IptEntry) (int, error) {
360360
if msg, failed := err.(*exec.ExitError); failed {
361361
errCode := msg.Sys().(syscall.WaitStatus).ExitStatus()
362362
if errCode > 0 && iptMgr.OperationFlag != util.IptablesCheckFlag {
363-
metrics.SendErrorMetric(util.IptmID, "Error: There was an error running command: [%s %v] Stderr: [%v, %s]", cmdName, strings.Join(cmdArgs, " "), err, strings.TrimSuffix(string(msg.Stderr), "\n"))
363+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: There was an error running command: [%s %v] Stderr: [%v, %s]", cmdName, strings.Join(cmdArgs, " "), err, strings.TrimSuffix(string(msg.Stderr), "\n"))
364364
}
365365

366366
return errCode, err
@@ -389,15 +389,15 @@ func (iptMgr *IptablesManager) Save(configFile string) error {
389389
// create the config file for writing
390390
f, err := os.Create(configFile)
391391
if err != nil {
392-
metrics.SendErrorMetric(util.IptmID, "Error: failed to open file: %s.", configFile)
392+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to open file: %s.", configFile)
393393
return err
394394
}
395395
defer f.Close()
396396

397397
cmd := exec.Command(util.IptablesSave)
398398
cmd.Stdout = f
399399
if err := cmd.Start(); err != nil {
400-
metrics.SendErrorMetric(util.IptmID, "Error: failed to run iptables-save.")
400+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to run iptables-save.")
401401
return err
402402
}
403403
cmd.Wait()
@@ -425,15 +425,15 @@ func (iptMgr *IptablesManager) Restore(configFile string) error {
425425
// open the config file for reading
426426
f, err := os.Open(configFile)
427427
if err != nil {
428-
metrics.SendErrorMetric(util.IptmID, "Error: failed to open file: %s.", configFile)
428+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to open file: %s.", configFile)
429429
return err
430430
}
431431
defer f.Close()
432432

433433
cmd := exec.Command(util.IptablesRestore)
434434
cmd.Stdin = f
435435
if err := cmd.Start(); err != nil {
436-
metrics.SendErrorMetric(util.IptmID, "Error: failed to run iptables-restore.")
436+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to run iptables-restore.")
437437
return err
438438
}
439439
cmd.Wait()
@@ -456,7 +456,7 @@ func grabIptablesLocks() (*os.File, error) {
456456
// Grab 1.6.x style lock.
457457
l, err := os.OpenFile(util.IptablesLockFile, os.O_CREATE, 0600)
458458
if err != nil {
459-
metrics.SendErrorMetric(util.IptmID, "Error: failed to open iptables lock file %s.", util.IptablesLockFile)
459+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to open iptables lock file %s.", util.IptablesLockFile)
460460
return nil, err
461461
}
462462

@@ -467,7 +467,7 @@ func grabIptablesLocks() (*os.File, error) {
467467

468468
return true, nil
469469
}); err != nil {
470-
metrics.SendErrorMetric(util.IptmID, "Error: failed to acquire new iptables lock: %v.", err)
470+
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to acquire new iptables lock: %v.", err)
471471
return nil, err
472472
}
473473

@@ -503,4 +503,4 @@ func grabIptablesFileLock(f *os.File) error {
503503
// // Write table headers.
504504
// writeLine(filterChains, "*filter")
505505

506-
// }
506+
// }

npm/metrics/ai-utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func CreateTelemetryHandle(version, aiMetadata string) error {
5050
return nil
5151
}
5252

53-
// SendErrorMetric is responsible for sending error metrics trhough AI telemetry
54-
func SendErrorMetric(operationID int, format string, args ...interface{}) {
53+
// SendErrorLogAndMetric is responsible for sending log and error metrics through AI telemetry
54+
func SendErrorLogAndMetric(operationID int, format string, args ...interface{}) {
5555
// Send error metrics
5656
customDimensions := map[string]string{
5757
util.ErrorCode: strconv.Itoa(operationID),

0 commit comments

Comments
 (0)