From eccabd237beb0c40dd38b1fb0645bf0aa7060b7e Mon Sep 17 00:00:00 2001 From: qsyqian Date: Fri, 5 Nov 2021 15:53:58 +0800 Subject: [PATCH] etcdctl/ctlv3/command: add use time for defrag command --- etcdctl/ctlv3/command/defrag_command.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/etcdctl/ctlv3/command/defrag_command.go b/etcdctl/ctlv3/command/defrag_command.go index cd0d8a94a..9b4f29a6a 100644 --- a/etcdctl/ctlv3/command/defrag_command.go +++ b/etcdctl/ctlv3/command/defrag_command.go @@ -17,6 +17,7 @@ package command import ( "fmt" "os" + "time" "github.com/spf13/cobra" "go.etcd.io/etcd/etcdutl/v3/etcdutl" @@ -53,13 +54,15 @@ func defragCommandFunc(cmd *cobra.Command, args []string) { c := mustClientFromCmd(cmd) for _, ep := range endpointsFromCluster(cmd) { ctx, cancel := commandCtx(cmd) + start := time.Now() _, err := c.Defragment(ctx, ep) + d := time.Now().Sub(start) cancel() if err != nil { - fmt.Fprintf(os.Stderr, "Failed to defragment etcd member[%s] (%v)\n", ep, err) + fmt.Fprintf(os.Stderr, "Failed to defragment etcd member[%s]. took %s. (%v)\n", ep, d.String(), err) failures++ } else { - fmt.Printf("Finished defragmenting etcd member[%s]\n", ep) + fmt.Printf("Finished defragmenting etcd member[%s]. took %s\n", ep, d.String()) } }