Skip to content

Commit

Permalink
Merge pull request etcd-io#17614 from ivanvc/address-etcdserver-var-n…
Browse files Browse the repository at this point in the history
…aming-lint-rule

etcdserver: address var naming lint rule
  • Loading branch information
ahrtr authored Mar 19, 2024
2 parents 3191002 + 14523bd commit 97029d7
Show file tree
Hide file tree
Showing 35 changed files with 255 additions and 236 deletions.
2 changes: 1 addition & 1 deletion server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {

e.cfg.logger.Info(
"now serving peer/client/metrics",
zap.String("local-member-id", e.Server.MemberId().String()),
zap.String("local-member-id", e.Server.MemberID().String()),
zap.Strings("initial-advertise-peer-urls", e.cfg.getAdvertisePeerUrls()),
zap.Strings("listen-peer-urls", e.cfg.getListenPeerUrls()),
zap.Strings("advertise-client-urls", e.cfg.getAdvertiseClientUrls()),
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *serverVersionAdapter) GetDowngradeInfo() *serverversion.DowngradeInfo {
}

func (s *serverVersionAdapter) GetMembersVersions() map[string]*version.Versions {
return getMembersVersions(s.lg, s.cluster, s.MemberId(), s.peerRt, s.Cfg.ReqTimeout())
return getMembersVersions(s.lg, s.cluster, s.MemberID(), s.peerRt, s.Cfg.ReqTimeout())
}

func (s *serverVersionAdapter) GetStorageVersion() *semver.Version {
Expand Down
19 changes: 14 additions & 5 deletions server/etcdserver/api/etcdhttp/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ type CheckRegistry struct {
func installLivezEndpoints(lg *zap.Logger, mux *http.ServeMux, server ServerHealth) {
reg := CheckRegistry{checkType: checkTypeLivez, checks: make(map[string]HealthCheck)}
reg.Register("serializable_read", readCheck(server, true /* serializable */))
reg.InstallHttpEndpoints(lg, mux)
reg.InstallHTTPEndpoints(lg, mux)
}

func installReadyzEndpoints(lg *zap.Logger, mux *http.ServeMux, server ServerHealth) {
Expand All @@ -252,7 +252,7 @@ func installReadyzEndpoints(lg *zap.Logger, mux *http.ServeMux, server ServerHea
reg.Register("serializable_read", readCheck(server, true))
// linearizable_read check would be replaced by read_index check in 3.6
reg.Register("linearizable_read", readCheck(server, false))
reg.InstallHttpEndpoints(lg, mux)
reg.InstallHTTPEndpoints(lg, mux)
}

func (reg *CheckRegistry) Register(name string, check HealthCheck) {
Expand All @@ -263,14 +263,23 @@ func (reg *CheckRegistry) RootPath() string {
return "/" + reg.checkType
}

// InstallHttpEndpoints installs the http handlers for the health checks.
// Deprecated: Please use (*CheckRegistry) InstallHTTPEndpoints instead.
//
//revive:disable:var-naming
func (reg *CheckRegistry) InstallHttpEndpoints(lg *zap.Logger, mux *http.ServeMux) {
//revive:enable:var-naming
reg.InstallHTTPEndpoints(lg, mux)
}

func (reg *CheckRegistry) InstallHTTPEndpoints(lg *zap.Logger, mux *http.ServeMux) {
checkNames := make([]string, 0, len(reg.checks))
for k := range reg.checks {
checkNames = append(checkNames, k)
}

// installs the http handler for the root path.
reg.installRootHttpEndpoint(lg, mux, checkNames...)
reg.installRootHTTPEndpoint(lg, mux, checkNames...)
for _, checkName := range checkNames {
// installs the http handler for the individual check sub path.
subpath := path.Join(reg.RootPath(), checkName)
Expand Down Expand Up @@ -302,8 +311,8 @@ func (reg *CheckRegistry) runHealthChecks(ctx context.Context, checkNames ...str
return h
}

// installRootHttpEndpoint installs the http handler for the root path.
func (reg *CheckRegistry) installRootHttpEndpoint(lg *zap.Logger, mux *http.ServeMux, checks ...string) {
// installRootHTTPEndpoint installs the http handler for the root path.
func (reg *CheckRegistry) installRootHTTPEndpoint(lg *zap.Logger, mux *http.ServeMux, checks ...string) {
hfunc := func(r *http.Request) HealthStatus {
// extracts the health check names to be excludeList from the query param
excluded := getQuerySet(r, "exclude")
Expand Down
16 changes: 8 additions & 8 deletions server/etcdserver/api/etcdhttp/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ func TestHealthHandler(t *testing.T) {
})
ts := httptest.NewServer(mux)
defer ts.Close()
checkHttpResponse(t, ts, tt.healthCheckURL, tt.expectStatusCode, nil, nil)
checkHTTPResponse(t, ts, tt.healthCheckURL, tt.expectStatusCode, nil, nil)
})
}
}

func TestHttpSubPath(t *testing.T) {
func TestHTTPSubPath(t *testing.T) {
be, _ := betesting.NewDefaultTmpBackend(t)
defer betesting.Close(t, be)
tests := []healthTestCase{
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestHttpSubPath(t *testing.T) {
HandleHealth(logger, mux, s)
ts := httptest.NewServer(mux)
defer ts.Close()
checkHttpResponse(t, ts, tt.healthCheckURL, tt.expectStatusCode, tt.inResult, tt.notInResult)
checkHTTPResponse(t, ts, tt.healthCheckURL, tt.expectStatusCode, tt.inResult, tt.notInResult)
checkMetrics(t, tt.healthCheckURL, "", tt.expectStatusCode)
})
}
Expand Down Expand Up @@ -253,10 +253,10 @@ func TestDataCorruptionCheck(t *testing.T) {
ts := httptest.NewServer(mux)
defer ts.Close()
// OK before alarms are activated.
checkHttpResponse(t, ts, tt.healthCheckURL, http.StatusOK, nil, nil)
checkHTTPResponse(t, ts, tt.healthCheckURL, http.StatusOK, nil, nil)
// Activate the alarms.
s.alarms = tt.alarms
checkHttpResponse(t, ts, tt.healthCheckURL, tt.expectStatusCode, tt.inResult, tt.notInResult)
checkHTTPResponse(t, ts, tt.healthCheckURL, tt.expectStatusCode, tt.inResult, tt.notInResult)
})
}
}
Expand Down Expand Up @@ -297,7 +297,7 @@ func TestSerializableReadCheck(t *testing.T) {
HandleHealth(logger, mux, s)
ts := httptest.NewServer(mux)
defer ts.Close()
checkHttpResponse(t, ts, tt.healthCheckURL, tt.expectStatusCode, tt.inResult, tt.notInResult)
checkHTTPResponse(t, ts, tt.healthCheckURL, tt.expectStatusCode, tt.inResult, tt.notInResult)
checkMetrics(t, tt.healthCheckURL, "serializable_read", tt.expectStatusCode)
})
}
Expand Down Expand Up @@ -338,13 +338,13 @@ func TestLinearizableReadCheck(t *testing.T) {
HandleHealth(logger, mux, s)
ts := httptest.NewServer(mux)
defer ts.Close()
checkHttpResponse(t, ts, tt.healthCheckURL, tt.expectStatusCode, tt.inResult, tt.notInResult)
checkHTTPResponse(t, ts, tt.healthCheckURL, tt.expectStatusCode, tt.inResult, tt.notInResult)
checkMetrics(t, tt.healthCheckURL, "linearizable_read", tt.expectStatusCode)
})
}
}

func checkHttpResponse(t *testing.T, ts *httptest.Server, url string, expectStatusCode int, inResult []string, notInResult []string) {
func checkHTTPResponse(t *testing.T, ts *httptest.Server, url string, expectStatusCode int, inResult []string, notInResult []string) {
res, err := ts.Client().Do(&http.Request{Method: http.MethodGet, URL: testutil.MustNewURL(t, ts.URL+url)})

if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions server/etcdserver/api/membership/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ type Member struct {
// NewMember creates a Member without an ID and generates one based on the
// cluster name, peer URLs, and time. This is used for bootstrapping/adding new member.
func NewMember(name string, peerURLs types.URLs, clusterName string, now *time.Time) *Member {
memberId := computeMemberId(peerURLs, clusterName, now)
return newMember(name, peerURLs, memberId, false)
memberID := computeMemberID(peerURLs, clusterName, now)
return newMember(name, peerURLs, memberID, false)
}

// NewMemberAsLearner creates a learner Member without an ID and generates one based on the
// cluster name, peer URLs, and time. This is used for adding new learner member.
func NewMemberAsLearner(name string, peerURLs types.URLs, clusterName string, now *time.Time) *Member {
memberId := computeMemberId(peerURLs, clusterName, now)
return newMember(name, peerURLs, memberId, true)
memberID := computeMemberID(peerURLs, clusterName, now)
return newMember(name, peerURLs, memberID, true)
}

func computeMemberId(peerURLs types.URLs, clusterName string, now *time.Time) types.ID {
func computeMemberID(peerURLs types.URLs, clusterName string, now *time.Time) types.ID {
peerURLstrs := peerURLs.StringSlice()
sort.Strings(peerURLstrs)
joinedPeerUrls := strings.Join(peerURLstrs, "")
Expand All @@ -75,14 +75,14 @@ func computeMemberId(peerURLs types.URLs, clusterName string, now *time.Time) ty
return types.ID(binary.BigEndian.Uint64(hash[:8]))
}

func newMember(name string, peerURLs types.URLs, memberId types.ID, isLearner bool) *Member {
func newMember(name string, peerURLs types.URLs, memberID types.ID, isLearner bool) *Member {
m := &Member{
RaftAttributes: RaftAttributes{
PeerURLs: peerURLs.StringSlice(),
IsLearner: isLearner,
},
Attributes: Attributes{Name: name},
ID: memberId,
ID: memberID,
}
return m
}
Expand Down
12 changes: 6 additions & 6 deletions server/etcdserver/api/snap/snapshotter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestLoadNewestSnap(t *testing.T) {

cases := []struct {
name string
availableWalSnaps []walpb.Snapshot
availableWALSnaps []walpb.Snapshot
expected *raftpb.Snapshot
}{
{
Expand All @@ -179,26 +179,26 @@ func TestLoadNewestSnap(t *testing.T) {
},
{
name: "loadnewestavailable-newest",
availableWalSnaps: []walpb.Snapshot{{Index: 0, Term: 0}, {Index: 1, Term: 1}, {Index: 5, Term: 1}},
availableWALSnaps: []walpb.Snapshot{{Index: 0, Term: 0}, {Index: 1, Term: 1}, {Index: 5, Term: 1}},
expected: &newSnap,
},
{
name: "loadnewestavailable-newest-unsorted",
availableWalSnaps: []walpb.Snapshot{{Index: 5, Term: 1}, {Index: 1, Term: 1}, {Index: 0, Term: 0}},
availableWALSnaps: []walpb.Snapshot{{Index: 5, Term: 1}, {Index: 1, Term: 1}, {Index: 0, Term: 0}},
expected: &newSnap,
},
{
name: "loadnewestavailable-previous",
availableWalSnaps: []walpb.Snapshot{{Index: 0, Term: 0}, {Index: 1, Term: 1}},
availableWALSnaps: []walpb.Snapshot{{Index: 0, Term: 0}, {Index: 1, Term: 1}},
expected: testSnap,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var err error
var g *raftpb.Snapshot
if tc.availableWalSnaps != nil {
g, err = ss.LoadNewestAvailable(tc.availableWalSnaps)
if tc.availableWALSnaps != nil {
g, err = ss.LoadNewestAvailable(tc.availableWALSnaps)
} else {
g, err = ss.Load()
}
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 @@ -139,7 +139,7 @@ func (e Error) Error() string {
return e.Message + " (" + e.Cause + ")"
}

func (e Error) toJsonString() string {
func (e Error) toJSONString() string {
b, _ := json.Marshal(e)
return string(b)
}
Expand All @@ -156,6 +156,6 @@ func (e Error) WriteTo(w http.ResponseWriter) error {
w.Header().Add("X-Etcd-Index", fmt.Sprint(e.Index))
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(e.StatusCode())
_, err := w.Write([]byte(e.toJsonString() + "\n"))
_, err := w.Write([]byte(e.toJSONString() + "\n"))
return err
}
4 changes: 2 additions & 2 deletions server/etcdserver/api/v2error/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func TestErrorWriteTo(t *testing.T) {
}

gbody := strings.TrimSuffix(rr.Body.String(), "\n")
if err.toJsonString() != gbody {
t.Errorf("HTTP body %q, want %q", gbody, err.toJsonString())
if err.toJSONString() != gbody {
t.Errorf("HTTP body %q, want %q", gbody, err.toJSONString())
}

wheader := http.Header(map[string][]string{
Expand Down
4 changes: 2 additions & 2 deletions server/etcdserver/api/v2store/heap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

func TestHeapPushPop(t *testing.T) {
h := newTtlKeyHeap()
h := newTTLKeyHeap()

// add from older expire time to earlier expire time
// the path is equal to ttl from now
Expand All @@ -45,7 +45,7 @@ func TestHeapPushPop(t *testing.T) {
}

func TestHeapUpdate(t *testing.T) {
h := newTtlKeyHeap()
h := newTTLKeyHeap()

kvs := make([]*node, 10)

Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/api/v2store/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (s *Stats) clone() *Stats {
}
}

func (s *Stats) toJson() []byte {
func (s *Stats) toJSON() []byte {
b, _ := json.Marshal(s)
return b
}
Expand Down
8 changes: 5 additions & 3 deletions server/etcdserver/api/v2store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func newStore(namespaces ...string) *store {
}
s.Stats = newStats()
s.WatcherHub = newWatchHub(1000)
s.ttlKeyHeap = newTtlKeyHeap()
s.ttlKeyHeap = newTTLKeyHeap()
s.readonlySet = types.NewUnsafeSet(append(namespaces, "/")...)
return s
}
Expand Down Expand Up @@ -781,15 +781,17 @@ func (s *store) Recovery(state []byte) error {
return err
}

s.ttlKeyHeap = newTtlKeyHeap()
s.ttlKeyHeap = newTTLKeyHeap()

s.Root.recoverAndclean()
return nil
}

//revive:disable:var-naming
func (s *store) JsonStats() []byte {
//revive:enable:var-naming
s.Stats.Watchers = uint64(s.WatcherHub.count)
return s.Stats.toJson()
return s.Stats.toJSON()
}

func (s *store) HasTTLKeys() bool {
Expand Down
2 changes: 1 addition & 1 deletion server/etcdserver/api/v2store/ttl_key_heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ttlKeyHeap struct {
keyMap map[*node]int
}

func newTtlKeyHeap() *ttlKeyHeap {
func newTTLKeyHeap() *ttlKeyHeap {
h := &ttlKeyHeap{keyMap: make(map[*node]int)}
heap.Init(h)
return h
Expand Down
18 changes: 9 additions & 9 deletions server/etcdserver/api/v3discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type DiscoveryConfig struct {
type memberInfo struct {
// peerRegKey is the key used by the member when registering in the
// discovery service.
// Format: "/_etcd/registry/<ClusterToken>/members/<memberId>".
// Format: "/_etcd/registry/<ClusterToken>/members/<memberID>".
peerRegKey string
// peerURLsMap format: "peerName=peerURLs", i.e., "member1=http://127.0.0.1:2380".
peerURLsMap string
Expand Down Expand Up @@ -88,9 +88,9 @@ func getMemberKeyPrefix(clusterToken string) string {
return path.Join(getClusterKeyPrefix(clusterToken), "members")
}

// key format for each member: "/_etcd/registry/<ClusterToken>/members/<memberId>".
func getMemberKey(cluster, memberId string) string {
return path.Join(getMemberKeyPrefix(cluster), memberId)
// key format for each member: "/_etcd/registry/<ClusterToken>/members/<memberID>".
func getMemberKey(cluster, memberID string) string {
return path.Join(getMemberKeyPrefix(cluster), memberID)
}

// GetCluster will connect to the discovery service at the given endpoints and
Expand Down Expand Up @@ -155,7 +155,7 @@ func JoinCluster(lg *zap.Logger, cfg *DiscoveryConfig, id types.ID, config strin
type discovery struct {
lg *zap.Logger
clusterToken string
memberId types.ID
memberID types.ID
c *clientv3.Client
retries uint

Expand All @@ -182,7 +182,7 @@ func newDiscovery(lg *zap.Logger, dcfg *DiscoveryConfig, id types.ID) (*discover
return &discovery{
lg: lg,
clusterToken: dcfg.Token,
memberId: id,
memberID: id,
c: c,
cfg: dcfg,
clock: clockwork.NewRealClock(),
Expand Down Expand Up @@ -317,10 +317,10 @@ func (d *discovery) checkCluster() (*clusterInfo, int, int64, error) {
d.retries = 0

// find self position
memberSelfId := getMemberKey(d.clusterToken, d.memberId.String())
memberSelfID := getMemberKey(d.clusterToken, d.memberID.String())
idx := 0
for _, m := range cls.members {
if m.peerRegKey == memberSelfId {
if m.peerRegKey == memberSelfID {
break
}
if idx >= clusterSize-1 {
Expand All @@ -341,7 +341,7 @@ func (d *discovery) registerSelfRetry(contents string) error {

func (d *discovery) registerSelf(contents string) error {
ctx, cancel := context.WithTimeout(context.Background(), d.cfg.RequestTimeout)
memberKey := getMemberKey(d.clusterToken, d.memberId.String())
memberKey := getMemberKey(d.clusterToken, d.memberID.String())
_, err := d.c.Put(ctx, memberKey, contents)
cancel()

Expand Down
Loading

0 comments on commit 97029d7

Please sign in to comment.