-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logging: better timestamp precision / log when CNI request finishes processing #381
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"context" | ||
"fmt" | ||
"net" | ||
"time" | ||
|
||
"github.com/containernetworking/cni/pkg/skel" | ||
cnitypes "github.com/containernetworking/cni/pkg/types" | ||
|
@@ -18,18 +19,24 @@ import ( | |
) | ||
|
||
func main() { | ||
var startTime time.Time | ||
skel.PluginMain(func(args *skel.CmdArgs) error { | ||
ipamConf, confVersion, err := config.LoadIPAMConfig(args.StdinData, args.Args) | ||
if err != nil { | ||
logging.Errorf("IPAM configuration load failed: %s", err) | ||
return err | ||
} | ||
logging.Debugf("ADD - IPAM configuration successfully read: %+v", *ipamConf) | ||
|
||
startTime = time.Now() | ||
logging.Debugf("ADD - IPAM plugin start. Config: %+v", *ipamConf) | ||
ipam, err := kubernetes.NewKubernetesIPAM(args.ContainerID, *ipamConf) | ||
if err != nil { | ||
return logging.Errorf("failed to create Kubernetes IPAM manager: %v", err) | ||
} | ||
defer func() { safeCloseKubernetesBackendConnection(ipam) }() | ||
defer func() { | ||
safeCloseKubernetesBackendConnection(ipam) | ||
logging.Debugf("ADD - IPAM plugin finished. Took: %q Config: %+v", time.Since(startTime).String(), *ipamConf) | ||
}() | ||
return cmdAdd(args, ipam, confVersion) | ||
}, | ||
cmdCheck, | ||
|
@@ -39,13 +46,17 @@ func main() { | |
logging.Errorf("IPAM configuration load failed: %s", err) | ||
return err | ||
} | ||
logging.Debugf("DEL - IPAM configuration successfully read: %+v", *ipamConf) | ||
|
||
startTime = time.Now() | ||
logging.Debugf("DEL - IPAM plugin start. Config: %+v", *ipamConf) | ||
ipam, err := kubernetes.NewKubernetesIPAM(args.ContainerID, *ipamConf) | ||
if err != nil { | ||
return logging.Errorf("IPAM client initialization error: %v", err) | ||
} | ||
defer func() { safeCloseKubernetesBackendConnection(ipam) }() | ||
defer func() { | ||
safeCloseKubernetesBackendConnection(ipam) | ||
logging.Debugf("DEL - IPAM plugin finished. Took: %q Config: %+v", time.Since(startTime).String(), *ipamConf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe in case of a failure better to change to if it is - then also on ADD please There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, there's no point bench marking failed results. BUT it makes sense to log the result (or a simplified version of it). I'll act on this. |
||
}() | ||
return cmdDel(args, ipam) | ||
}, | ||
cniversion.All, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider using a function that gets a string, startTime and is reused in both places
as beside ADD / DEL string it is the same