Skip to content

Commit

Permalink
fix: enable int-conversion rule of perfsprint
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Nov 9, 2024
1 parent 0f9c128 commit adae3ec
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 51 deletions.
4 changes: 2 additions & 2 deletions client/pkg/fileutil/fileutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
package fileutil

import (
"fmt"
"io"
"math/rand"
"os"
"os/user"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestCreateDirAll(t *testing.T) {
}

func TestExist(t *testing.T) {
fdir := filepath.Join(os.TempDir(), fmt.Sprint(time.Now().UnixNano()+rand.Int63n(1000)))
fdir := filepath.Join(os.TempDir(), strconv.FormatInt(time.Now().UnixNano()+rand.Int63n(1000), 10))
os.RemoveAll(fdir)
if err := os.Mkdir(fdir, 0o666); err != nil {
t.Skip(err)
Expand Down
7 changes: 4 additions & 3 deletions client/pkg/srv/srv.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"net"
"net/url"
"strconv"
"strings"

"go.etcd.io/etcd/client/pkg/v3/types"
Expand Down Expand Up @@ -54,7 +55,7 @@ func GetCluster(serviceScheme, service, name, dns string, apurls types.URLs) ([]
return err
}
for _, srv := range addrs {
port := fmt.Sprintf("%d", srv.Port)
port := strconv.FormatUint(uint64(srv.Port), 10)
host := net.JoinHostPort(srv.Target, port)
tcpAddr, terr := resolveTCPAddr("tcp", host)
if terr != nil {
Expand All @@ -67,7 +68,7 @@ func GetCluster(serviceScheme, service, name, dns string, apurls types.URLs) ([]
n = name
}
if n == "" {
n = fmt.Sprintf("%d", tempName)
n = strconv.Itoa(tempName)
tempName++
}
// SRV records have a trailing dot but URL shouldn't.
Expand Down Expand Up @@ -112,7 +113,7 @@ func GetClient(service, domain string, serviceName string) (*SRVClients, error)
for _, srv := range addrs {
urls = append(urls, &url.URL{
Scheme: scheme,
Host: net.JoinHostPort(srv.Target, fmt.Sprintf("%d", srv.Port)),
Host: net.JoinHostPort(srv.Target, strconv.FormatUint(uint64(srv.Port), 10)),
})
}
srvs = append(srvs, addrs...)
Expand Down
23 changes: 12 additions & 11 deletions etcdctl/ctlv3/command/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package command
import (
"errors"
"fmt"
"strconv"
"strings"

"github.com/dustin/go-humanize"
Expand Down Expand Up @@ -193,7 +194,7 @@ func makeMemberListTable(r v3.MemberListResponse) (hdr []string, rows [][]string
isLearner = "true"
}
rows = append(rows, []string{
fmt.Sprintf("%x", m.ID),
strconv.FormatUint(m.ID, 16),
status,
m.Name,
strings.Join(m.PeerURLs, ","),
Expand All @@ -209,7 +210,7 @@ func makeEndpointHealthTable(healthList []epHealth) (hdr []string, rows [][]stri
for _, h := range healthList {
rows = append(rows, []string{
h.Ep,
fmt.Sprintf("%v", h.Health),
strconv.FormatBool(h.Health),
h.Took,
h.Error,
})
Expand All @@ -225,19 +226,19 @@ func makeEndpointStatusTable(statusList []epStatus) (hdr []string, rows [][]stri
for _, status := range statusList {
rows = append(rows, []string{
status.Ep,
fmt.Sprintf("%x", status.Resp.Header.MemberId),
strconv.FormatUint(status.Resp.Header.MemberId, 16),
status.Resp.Version,
status.Resp.StorageVersion,
humanize.Bytes(uint64(status.Resp.DbSize)),
humanize.Bytes(uint64(status.Resp.DbSizeInUse)),
fmt.Sprintf("%d%%", int(float64(100-(status.Resp.DbSizeInUse*100/status.Resp.DbSize)))),
humanize.Bytes(uint64(status.Resp.DbSizeQuota)),
fmt.Sprint(status.Resp.Leader == status.Resp.Header.MemberId),
fmt.Sprint(status.Resp.IsLearner),
fmt.Sprint(status.Resp.RaftTerm),
fmt.Sprint(status.Resp.RaftIndex),
fmt.Sprint(status.Resp.RaftAppliedIndex),
fmt.Sprint(strings.Join(status.Resp.Errors, ", ")),
strconv.FormatBool(status.Resp.Leader == status.Resp.Header.MemberId),
strconv.FormatBool(status.Resp.IsLearner),
strconv.FormatUint(status.Resp.RaftTerm, 10),
strconv.FormatUint(status.Resp.RaftIndex, 10),
strconv.FormatUint(status.Resp.RaftAppliedIndex, 10),
strings.Join(status.Resp.Errors, ", "),
})
}
return hdr, rows
Expand All @@ -248,8 +249,8 @@ func makeEndpointHashKVTable(hashList []epHashKV) (hdr []string, rows [][]string
for _, h := range hashList {
rows = append(rows, []string{
h.Ep,
fmt.Sprint(h.Resp.Hash),
fmt.Sprint(h.Resp.HashRevision),
strconv.FormatUint(uint64(h.Resp.Hash), 10),
strconv.FormatInt(h.Resp.HashRevision, 10),
})
}
return hdr, rows
Expand Down
14 changes: 7 additions & 7 deletions etcdutl/etcdutl/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package etcdutl

import (
"errors"
"fmt"
"strconv"

"github.com/dustin/go-humanize"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -68,9 +68,9 @@ func (p *printerUnsupported) DBHashKV(HashKV) { p.p(nil) }
func makeDBStatusTable(ds snapshot.Status) (hdr []string, rows [][]string) {
hdr = []string{"hash", "revision", "total keys", "total size", "version"}
rows = append(rows, []string{
fmt.Sprintf("%x", ds.Hash),
fmt.Sprint(ds.Revision),
fmt.Sprint(ds.TotalKey),
strconv.FormatUint(uint64(ds.Hash), 16),
strconv.FormatInt(ds.Revision, 10),
strconv.Itoa(ds.TotalKey),
humanize.Bytes(uint64(ds.TotalSize)),
ds.Version,
})
Expand All @@ -80,9 +80,9 @@ func makeDBStatusTable(ds snapshot.Status) (hdr []string, rows [][]string) {
func makeDBHashKVTable(ds HashKV) (hdr []string, rows [][]string) {
hdr = []string{"hash", "hash revision", "compact revision"}
rows = append(rows, []string{
fmt.Sprint(ds.Hash),
fmt.Sprint(ds.HashRevision),
fmt.Sprint(ds.CompactRevision),
strconv.FormatUint(uint64(ds.Hash), 10),
strconv.FormatInt(ds.HashRevision, 10),
strconv.FormatInt(ds.CompactRevision, 10),
})
return hdr, rows
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/report/timeseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"log"
"math"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -127,11 +128,11 @@ func (t TimeSeries) String() string {
var rows [][]string
for i := range t {
row := []string{
fmt.Sprintf("%d", t[i].Timestamp),
strconv.FormatInt(t[i].Timestamp, 10),
t[i].MinLatency.String(),
t[i].AvgLatency.String(),
t[i].MaxLatency.String(),
fmt.Sprintf("%d", t[i].ThroughPut),
strconv.FormatInt(t[i].ThroughPut, 10),
}
rows = append(rows, row)
}
Expand Down
3 changes: 2 additions & 1 deletion server/etcdmain/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"net"
"net/url"
"os"
"strconv"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -145,7 +146,7 @@ func startGateway(cmd *cobra.Command, args []string) {
fmt.Println("failed to resolve endpoint host:", srv.Target)
os.Exit(1)
}
if fmt.Sprintf("%d", srv.Port) != lport {
if strconv.FormatUint(uint64(srv.Port), 10) != lport {
continue
}

Expand Down
5 changes: 2 additions & 3 deletions server/etcdmain/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package etcdmain

import (
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -231,8 +230,8 @@ Security:
Auth:
--auth-token 'simple'
Specify a v3 authentication token type and its options ('simple' or 'jwt').
--bcrypt-cost ` + fmt.Sprintf("%d", bcrypt.DefaultCost) + `
Specify the cost / strength of the bcrypt algorithm for hashing auth passwords. Valid values are between ` + fmt.Sprintf("%d", bcrypt.MinCost) + ` and ` + fmt.Sprintf("%d", bcrypt.MaxCost) + `.
--bcrypt-cost ` + strconv.Itoa(bcrypt.DefaultCost) + `
Specify the cost / strength of the bcrypt algorithm for hashing auth passwords. Valid values are between ` + strconv.Itoa(bcrypt.MinCost) + ` and ` + strconv.Itoa(bcrypt.MaxCost) + `.
--auth-token-ttl 300
Time (in seconds) of the auth-token-ttl.
Expand Down
4 changes: 2 additions & 2 deletions server/etcdserver/api/membership/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package membership
import (
"crypto/sha1"
"encoding/binary"
"fmt"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -68,7 +68,7 @@ func computeMemberID(peerURLs types.URLs, clusterName string, now *time.Time) ty

b = append(b, []byte(clusterName)...)
if now != nil {
b = append(b, []byte(fmt.Sprintf("%d", now.Unix()))...)
b = append(b, []byte(strconv.FormatInt(now.Unix(), 10))...)
}

hash := sha1.Sum(b)
Expand Down
4 changes: 2 additions & 2 deletions server/etcdserver/api/rafthttp/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ package rafthttp
import (
"bytes"
"errors"
"fmt"
"io"
"net/http"
"net/http/httptest"
"net/url"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -280,7 +280,7 @@ func TestServeRaftStreamPrefixBad(t *testing.T) {
// removed peer
{
"GET",
RaftStreamPrefix + "/message/" + fmt.Sprint(removedID),
RaftStreamPrefix + "/message/" + strconv.FormatUint(removedID, 10),
"1",
"1",
http.StatusGone,
Expand Down
4 changes: 2 additions & 2 deletions server/etcdserver/api/v2error/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package v2error

import (
"encoding/json"
"fmt"
"net/http"
"strconv"
)

var errors = map[int]string{
Expand Down Expand Up @@ -153,7 +153,7 @@ func (e Error) StatusCode() int {
}

func (e Error) WriteTo(w http.ResponseWriter) error {
w.Header().Add("X-Etcd-Index", fmt.Sprint(e.Index))
w.Header().Add("X-Etcd-Index", strconv.FormatUint(e.Index, 10))
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(e.StatusCode())
_, err := w.Write([]byte(e.toJSONString() + "\n"))
Expand Down
6 changes: 3 additions & 3 deletions server/etcdserver/api/v2store/heap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package v2store

import (
"fmt"
"strconv"
"testing"
"time"
)
Expand All @@ -26,7 +26,7 @@ func TestHeapPushPop(t *testing.T) {
// add from older expire time to earlier expire time
// the path is equal to ttl from now
for i := 0; i < 10; i++ {
path := fmt.Sprintf("%v", 10-i)
path := strconv.Itoa(10 - i)
m := time.Duration(10 - i)
n := newKV(nil, path, path, 0, nil, time.Now().Add(time.Second*m))
h.push(n)
Expand All @@ -51,7 +51,7 @@ func TestHeapUpdate(t *testing.T) {
// add from older expire time to earlier expire time
// the path is equal to ttl from now
for i := range kvs {
path := fmt.Sprintf("%v", 10-i)
path := strconv.Itoa(10 - i)
m := time.Duration(10 - i)
n := newKV(nil, path, path, 0, nil, time.Now().Add(time.Second*m))
kvs[i] = n
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func promoteMemberHTTP(ctx context.Context, url string, id uint64, peerRt http.R
}
// TODO: refactor member http handler code
// cannot import etcdhttp, so manually construct url
requestURL := url + "/members/promote/" + fmt.Sprintf("%d", id)
requestURL := url + "/members/promote/" + strconv.FormatUint(id, 10)
req, err := http.NewRequest(http.MethodPost, requestURL, nil)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions server/etcdserver/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package etcdserver

import (
"expvar"
"fmt"
"log"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -386,7 +386,7 @@ func (r *raftNode) processMessages(ms []raftpb.Message) []raftpb.Message {
// TODO: limit request rate.
r.lg.Warn(
"leader failed to send out heartbeat on time; took too long, leader is overloaded likely from slow disk",
zap.String("to", fmt.Sprintf("%x", ms[i].To)),
zap.String("to", strconv.FormatUint(ms[i].To, 16)),
zap.Duration("heartbeat-interval", r.heartbeat),
zap.Duration("expected-duration", 2*r.heartbeat),
zap.Duration("exceeded-duration", exceed),
Expand Down
3 changes: 2 additions & 1 deletion server/etcdserver/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math/rand"
"strconv"
"testing"

"github.com/coreos/go-semver/semver"
Expand Down Expand Up @@ -174,7 +175,7 @@ func (c *clusterMock) MembersVersions() map[string]*version.Versions {
result := map[string]*version.Versions{}
for i, m := range c.members {
if m.isRunning {
result[fmt.Sprintf("%d", i)] = &version.Versions{
result[strconv.Itoa(i)] = &version.Versions{
Server: m.serverVersion.String(),
Cluster: c.clusterVersion.String(),
}
Expand Down
3 changes: 2 additions & 1 deletion server/proxy/tcpproxy/userspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io"
"math/rand"
"net"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -75,7 +76,7 @@ func (tp *TCPProxy) Run() error {
tp.MonitorInterval = 5 * time.Minute
}
for _, srv := range tp.Endpoints {
addr := net.JoinHostPort(srv.Target, fmt.Sprintf("%d", srv.Port))
addr := net.JoinHostPort(srv.Target, strconv.FormatUint(uint64(srv.Port), 10))
tp.remotes = append(tp.remotes, &remote{srv: srv, addr: addr})
}

Expand Down
4 changes: 2 additions & 2 deletions server/storage/mvcc/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package mvcc

import (
"context"
"fmt"
"strconv"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestHashByRevValueLastRevision(t *testing.T) {

func putKVs(s *store, rev, count int64) {
for i := rev; i <= rev+count; i++ {
s.Put([]byte(testutil.PickKey(i)), []byte(fmt.Sprint(i)), 0)
s.Put([]byte(testutil.PickKey(i)), []byte(strconv.FormatInt(i, 10)), 0)
}
}

Expand Down
Loading

0 comments on commit adae3ec

Please sign in to comment.