Merge pull request #13461 from qsyqian/etcdctl-command-defrag

etcdctl/ctlv3/command: add use time for defrag command
dependabot/go_modules/go.uber.org/atomic-1.10.0
Sahdev Zala 2021-11-17 13:36:23 -05:00 committed by GitHub
commit 7e0248b367
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -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())
}
}