Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions npm/ipsm/ipsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (ipsMgr *IpsetManager) CreateList(listName string) error {
}
log.Logf("Creating List: %+v", entry)
if errCode, err := ipsMgr.Run(entry); err != nil && errCode != 1 {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to create ipset list %s.", listName)
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to create ipset list %s.", listName)
return err
}

Expand All @@ -118,7 +118,7 @@ func (ipsMgr *IpsetManager) DeleteList(listName string) error {
return nil
}

metrics.SendErrorMetric(util.IpsmID, "Error: failed to delete ipset %s %+v", listName, entry)
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to delete ipset %s %+v", listName, entry)
return err
}

Expand Down Expand Up @@ -148,7 +148,7 @@ func (ipsMgr *IpsetManager) AddToList(listName string, setName string) error {
}

if errCode, err := ipsMgr.Run(entry); err != nil && errCode != 1 {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to create ipset rules. rule: %+v", entry)
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to create ipset rules. rule: %+v", entry)
return err
}

Expand All @@ -160,7 +160,7 @@ func (ipsMgr *IpsetManager) AddToList(listName string, setName string) error {
// DeleteFromList removes an ipset to an ipset list.
func (ipsMgr *IpsetManager) DeleteFromList(listName string, setName string) error {
if _, exists := ipsMgr.listMap[listName]; !exists {
metrics.SendErrorMetric(util.IpsmID, "ipset list with name %s not found", listName)
metrics.SendErrorLogAndMetric(util.IpsmID, "ipset list with name %s not found", listName)
return nil
}

Expand All @@ -172,7 +172,7 @@ func (ipsMgr *IpsetManager) DeleteFromList(listName string, setName string) erro
}

if _, err := ipsMgr.Run(entry); err != nil {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to delete ipset entry. %+v", entry)
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to delete ipset entry. %+v", entry)
return err
}

Expand All @@ -183,7 +183,7 @@ func (ipsMgr *IpsetManager) DeleteFromList(listName string, setName string) erro

if len(ipsMgr.listMap[listName].elements) == 0 {
if err := ipsMgr.DeleteList(listName); err != nil {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to delete ipset list %s.", listName)
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to delete ipset list %s.", listName)
return err
}
}
Expand All @@ -208,7 +208,7 @@ func (ipsMgr *IpsetManager) CreateSet(setName string, spec []string) error {
}
log.Logf("Creating Set: %+v", entry)
if errCode, err := ipsMgr.Run(entry); err != nil && errCode != 1 {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to create ipset.")
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to create ipset.")
return err
}

Expand All @@ -224,7 +224,7 @@ func (ipsMgr *IpsetManager) CreateSet(setName string, spec []string) error {
// DeleteSet removes a set from ipset.
func (ipsMgr *IpsetManager) DeleteSet(setName string) error {
if _, exists := ipsMgr.setMap[setName]; !exists {
metrics.SendErrorMetric(util.IpsmID, "ipset with name %s not found", setName)
metrics.SendErrorLogAndMetric(util.IpsmID, "ipset with name %s not found", setName)
return nil
}

Expand All @@ -238,7 +238,7 @@ func (ipsMgr *IpsetManager) DeleteSet(setName string) error {
return nil
}

metrics.SendErrorMetric(util.IpsmID, "Error: failed to delete ipset %s. Entry: %+v", setName, entry)
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to delete ipset %s. Entry: %+v", setName, entry)
return err
}

Expand Down Expand Up @@ -287,7 +287,7 @@ func (ipsMgr *IpsetManager) AddToSet(setName, ip, spec, podUid string) error {
}

if errCode, err := ipsMgr.Run(entry); err != nil && errCode != 1 {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to create ipset rules. %+v", entry)
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to create ipset rules. %+v", entry)
return err
}

Expand Down Expand Up @@ -331,7 +331,7 @@ func (ipsMgr *IpsetManager) DeleteFromSet(setName, ip, podUid string) error {
return nil
}

metrics.SendErrorMetric(util.IpsmID, "Error: failed to delete ipset entry. Entry: %+v", entry)
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to delete ipset entry. Entry: %+v", entry)
return err
}

Expand All @@ -356,7 +356,7 @@ func (ipsMgr *IpsetManager) Clean() error {
}

if err := ipsMgr.DeleteSet(setName); err != nil {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to clean ipset")
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to clean ipset")
return err
}
}
Expand All @@ -367,7 +367,7 @@ func (ipsMgr *IpsetManager) Clean() error {
}

if err := ipsMgr.DeleteList(listName); err != nil {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to clean ipset list")
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to clean ipset list")
return err
}
}
Expand All @@ -381,13 +381,13 @@ func (ipsMgr *IpsetManager) Destroy() error {
operationFlag: util.IpsetFlushFlag,
}
if _, err := ipsMgr.Run(entry); err != nil {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to flush ipset")
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to flush ipset")
return err
}

entry.operationFlag = util.IpsetDestroyFlag
if _, err := ipsMgr.Run(entry); err != nil {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to destroy ipset")
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to destroy ipset")
return err
}

Expand All @@ -407,7 +407,7 @@ func (ipsMgr *IpsetManager) Run(entry *ipsEntry) (int, error) {
if msg, failed := err.(*exec.ExitError); failed {
errCode := msg.Sys().(syscall.WaitStatus).ExitStatus()
if errCode > 0 {
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"))
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"))
}

return errCode, err
Expand All @@ -424,7 +424,7 @@ func (ipsMgr *IpsetManager) Save(configFile string) error {

cmd := exec.Command(util.Ipset, util.IpsetSaveFlag, util.IpsetFileFlag, configFile)
if err := cmd.Start(); err != nil {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to save ipset to file.")
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to save ipset to file.")
return err
}
cmd.Wait()
Expand All @@ -440,7 +440,7 @@ func (ipsMgr *IpsetManager) Restore(configFile string) error {

f, err := os.Stat(configFile)
if err != nil {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to get file %s stat from ipsm.Restore", configFile)
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to get file %s stat from ipsm.Restore", configFile)
return err
}

Expand All @@ -452,7 +452,7 @@ func (ipsMgr *IpsetManager) Restore(configFile string) error {

cmd := exec.Command(util.Ipset, util.IpsetRestoreFlag, util.IpsetFileFlag, configFile)
if err := cmd.Start(); err != nil {
metrics.SendErrorMetric(util.IpsmID, "Error: failed to to restore ipset from file.")
metrics.SendErrorLogAndMetric(util.IpsmID, "Error: failed to to restore ipset from file.")
return err
}
cmd.Wait()
Expand All @@ -472,13 +472,13 @@ func (ipsMgr *IpsetManager) DestroyNpmIpsets() error {
if msg, failed := err.(*exec.ExitError); failed {
errCode := msg.Sys().(syscall.WaitStatus).ExitStatus()
if errCode > 0 {
metrics.SendErrorMetric(util.IpsmID, "{DestroyNpmIpsets} Error: There was an error running command: [%s] Stderr: [%v, %s]", cmdName, err, strings.TrimSuffix(string(msg.Stderr), "\n"))
metrics.SendErrorLogAndMetric(util.IpsmID, "{DestroyNpmIpsets} Error: There was an error running command: [%s] Stderr: [%v, %s]", cmdName, err, strings.TrimSuffix(string(msg.Stderr), "\n"))
}

return err
}
if reply == nil {
metrics.SendErrorMetric(util.IpsmID, "{DestroyNpmIpsets} Received empty string from ipset list while destroying azure-npm ipsets")
metrics.SendErrorLogAndMetric(util.IpsmID, "{DestroyNpmIpsets} Received empty string from ipset list while destroying azure-npm ipsets")
return nil
}

Expand Down Expand Up @@ -516,15 +516,15 @@ func (ipsMgr *IpsetManager) DestroyNpmIpsets() error {
}

if _, err := ipsMgr.Run(entry); err != nil {
metrics.SendErrorMetric(util.IpsmID, "{DestroyNpmIpsets} Error: failed to flush ipset %s", ipsetName)
metrics.SendErrorLogAndMetric(util.IpsmID, "{DestroyNpmIpsets} Error: failed to flush ipset %s", ipsetName)
}
}

for _, ipsetName := range ipsetLists {
entry.operationFlag = util.IpsetDestroyFlag
entry.set = ipsetName
if _, err := ipsMgr.Run(entry); err != nil {
metrics.SendErrorMetric(util.IpsmID, "{DestroyNpmIpsets} Error: failed to destroy ipset %s", ipsetName)
metrics.SendErrorLogAndMetric(util.IpsmID, "{DestroyNpmIpsets} Error: failed to destroy ipset %s", ipsetName)
}
}

Expand Down
40 changes: 20 additions & 20 deletions npm/iptm/iptm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"syscall"
"time"

"golang.org/x/sys/unix"
"github.com/Azure/azure-container-networking/log"
"github.com/Azure/azure-container-networking/npm/metrics"
"github.com/Azure/azure-container-networking/npm/util"
"golang.org/x/sys/unix"
"k8s.io/apimachinery/pkg/util/wait"
// utiliptables "k8s.io/kubernetes/pkg/util/iptables"
)
Expand Down Expand Up @@ -88,7 +88,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
iptMgr.OperationFlag = util.IptablesInsertionFlag
entry.Specs = append([]string{index}, entry.Specs...)
if _, err = iptMgr.Run(entry); err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to add AZURE-NPM chain to FORWARD chain.")
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add AZURE-NPM chain to FORWARD chain.")
return err
}
}
Expand All @@ -109,7 +109,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
if !exists {
iptMgr.OperationFlag = util.IptablesAppendFlag
if _, err := iptMgr.Run(entry); err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to add AZURE-NPM-INGRESS-PORT chain to AZURE-NPM chain.")
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add AZURE-NPM-INGRESS-PORT chain to AZURE-NPM chain.")
return err
}
}
Expand All @@ -135,7 +135,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
if !exists {
iptMgr.OperationFlag = util.IptablesAppendFlag
if _, err := iptMgr.Run(entry); err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to add AZURE-NPM-INGRESS-PORT chain to AZURE-NPM chain.")
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add AZURE-NPM-INGRESS-PORT chain to AZURE-NPM chain.")
return err
}
}
Expand All @@ -161,7 +161,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
if !exists {
iptMgr.OperationFlag = util.IptablesAppendFlag
if _, err := iptMgr.Run(entry); err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to add AZURE-NPM-TARGET-SETS chain to AZURE-NPM chain.")
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add AZURE-NPM-TARGET-SETS chain to AZURE-NPM chain.")
return err
}
}
Expand All @@ -184,7 +184,7 @@ func (iptMgr *IptablesManager) InitNpmChains() error {
if !exists {
iptMgr.OperationFlag = util.IptablesAppendFlag
if _, err = iptMgr.Run(entry); err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to add default allow CONNECTED/RELATED rule to AZURE-NPM chain.")
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add default allow CONNECTED/RELATED rule to AZURE-NPM chain.")
return err
}
}
Expand Down Expand Up @@ -214,7 +214,7 @@ func (iptMgr *IptablesManager) UninitNpmChains() error {
iptMgr.OperationFlag = util.IptablesDeletionFlag
errCode, err := iptMgr.Run(entry)
if errCode != iptablesErrDoesNotExist && err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to add default allow CONNECTED/RELATED rule to AZURE-NPM chain.")
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to add default allow CONNECTED/RELATED rule to AZURE-NPM chain.")
return err
}

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

Expand Down Expand Up @@ -266,7 +266,7 @@ func (iptMgr *IptablesManager) AddChain(chain string) error {
return nil
}

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

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

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

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

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

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

Expand Down Expand Up @@ -360,7 +360,7 @@ func (iptMgr *IptablesManager) Run(entry *IptEntry) (int, error) {
if msg, failed := err.(*exec.ExitError); failed {
errCode := msg.Sys().(syscall.WaitStatus).ExitStatus()
if errCode > 0 && iptMgr.OperationFlag != util.IptablesCheckFlag {
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"))
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"))
}

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

cmd := exec.Command(util.IptablesSave)
cmd.Stdout = f
if err := cmd.Start(); err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to run iptables-save.")
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to run iptables-save.")
return err
}
cmd.Wait()
Expand Down Expand Up @@ -425,15 +425,15 @@ func (iptMgr *IptablesManager) Restore(configFile string) error {
// open the config file for reading
f, err := os.Open(configFile)
if err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to open file: %s.", configFile)
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to open file: %s.", configFile)
return err
}
defer f.Close()

cmd := exec.Command(util.IptablesRestore)
cmd.Stdin = f
if err := cmd.Start(); err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to run iptables-restore.")
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to run iptables-restore.")
return err
}
cmd.Wait()
Expand All @@ -456,7 +456,7 @@ func grabIptablesLocks() (*os.File, error) {
// Grab 1.6.x style lock.
l, err := os.OpenFile(util.IptablesLockFile, os.O_CREATE, 0600)
if err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to open iptables lock file %s.", util.IptablesLockFile)
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to open iptables lock file %s.", util.IptablesLockFile)
return nil, err
}

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

return true, nil
}); err != nil {
metrics.SendErrorMetric(util.IptmID, "Error: failed to acquire new iptables lock: %v.", err)
metrics.SendErrorLogAndMetric(util.IptmID, "Error: failed to acquire new iptables lock: %v.", err)
return nil, err
}

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

// }
// }
4 changes: 2 additions & 2 deletions npm/metrics/ai-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func CreateTelemetryHandle(version, aiMetadata string) error {
return nil
}

// SendErrorMetric is responsible for sending error metrics trhough AI telemetry
func SendErrorMetric(operationID int, format string, args ...interface{}) {
// SendErrorLogAndMetric is responsible for sending log and error metrics through AI telemetry
func SendErrorLogAndMetric(operationID int, format string, args ...interface{}) {
// Send error metrics
customDimensions := map[string]string{
util.ErrorCode: strconv.Itoa(operationID),
Expand Down
Loading