diff --git a/cmd/whereabouts.go b/cmd/whereabouts.go index 0e84ee91c..4e4b8c6cd 100644 --- a/cmd/whereabouts.go +++ b/cmd/whereabouts.go @@ -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) + }() return cmdDel(args, ipam) }, cniversion.All, diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go index 5d1b59305..a321f7862 100644 --- a/pkg/logging/logging.go +++ b/pkg/logging/logging.go @@ -40,7 +40,7 @@ var loggingStderr bool var loggingFp *os.File var loggingLevel Level -const defaultTimestampFormat = time.RFC3339 +const defaultTimestampFormat = time.RFC3339Nano func (l Level) String() string { switch l {