Add revive to the list of linters.
Part of "Enhance the static-analysis workflow" issue. #14164 Signed-off-by: Cenk Alti <cenkalti@gmail.com>
This commit is contained in:
@ -25,6 +25,7 @@ linters:
|
|||||||
- staticcheck
|
- staticcheck
|
||||||
- stylecheck
|
- stylecheck
|
||||||
- unused
|
- unused
|
||||||
|
- revive
|
||||||
|
|
||||||
linters-settings: # please keep this alphabetized
|
linters-settings: # please keep this alphabetized
|
||||||
staticcheck:
|
staticcheck:
|
||||||
|
@ -60,7 +60,7 @@ func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeId, err := strconv.ParseUint(key[1:], 0, 64)
|
nodeID, err := strconv.ParseUint(key[1:], 0, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to convert ID for conf change (%v)\n", err)
|
log.Printf("Failed to convert ID for conf change (%v)\n", err)
|
||||||
http.Error(w, "Failed on POST", http.StatusBadRequest)
|
http.Error(w, "Failed on POST", http.StatusBadRequest)
|
||||||
@ -69,14 +69,14 @@ func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
cc := raftpb.ConfChange{
|
cc := raftpb.ConfChange{
|
||||||
Type: raftpb.ConfChangeAddNode,
|
Type: raftpb.ConfChangeAddNode,
|
||||||
NodeID: nodeId,
|
NodeID: nodeID,
|
||||||
Context: url,
|
Context: url,
|
||||||
}
|
}
|
||||||
h.confChangeC <- cc
|
h.confChangeC <- cc
|
||||||
// As above, optimistic that raft will apply the conf change
|
// As above, optimistic that raft will apply the conf change
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
case http.MethodDelete:
|
case http.MethodDelete:
|
||||||
nodeId, err := strconv.ParseUint(key[1:], 0, 64)
|
nodeID, err := strconv.ParseUint(key[1:], 0, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to convert ID for conf change (%v)\n", err)
|
log.Printf("Failed to convert ID for conf change (%v)\n", err)
|
||||||
http.Error(w, "Failed on DELETE", http.StatusBadRequest)
|
http.Error(w, "Failed on DELETE", http.StatusBadRequest)
|
||||||
@ -85,7 +85,7 @@ func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
cc := raftpb.ConfChange{
|
cc := raftpb.ConfChange{
|
||||||
Type: raftpb.ConfChangeRemoveNode,
|
Type: raftpb.ConfChangeRemoveNode,
|
||||||
NodeID: nodeId,
|
NodeID: nodeID,
|
||||||
}
|
}
|
||||||
h.confChangeC <- cc
|
h.confChangeC <- cc
|
||||||
|
|
||||||
@ -100,8 +100,8 @@ func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// serveHttpKVAPI starts a key-value server with a GET/PUT API and listens.
|
// serveHTTPKVAPI starts a key-value server with a GET/PUT API and listens.
|
||||||
func serveHttpKVAPI(kv *kvstore, port int, confChangeC chan<- raftpb.ConfChange, errorC <-chan error) {
|
func serveHTTPKVAPI(kv *kvstore, port int, confChangeC chan<- raftpb.ConfChange, errorC <-chan error) {
|
||||||
srv := http.Server{
|
srv := http.Server{
|
||||||
Addr: ":" + strconv.Itoa(port),
|
Addr: ":" + strconv.Itoa(port),
|
||||||
Handler: &httpKVAPI{
|
Handler: &httpKVAPI{
|
||||||
|
@ -41,5 +41,5 @@ func main() {
|
|||||||
kvs = newKVStore(<-snapshotterReady, proposeC, commitC, errorC)
|
kvs = newKVStore(<-snapshotterReady, proposeC, commitC, errorC)
|
||||||
|
|
||||||
// the key-value http handler will propose updates to raft
|
// the key-value http handler will propose updates to raft
|
||||||
serveHttpKVAPI(kvs, *kvport, confChangeC, errorC)
|
serveHTTPKVAPI(kvs, *kvport, confChangeC, errorC)
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bgentry/speakeasy"
|
"github.com/bgentry/speakeasy"
|
||||||
"go.etcd.io/etcd/client/v3"
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
"go.etcd.io/etcd/pkg/v3/report"
|
"go.etcd.io/etcd/pkg/v3/report"
|
||||||
"google.golang.org/grpc/grpclog"
|
"google.golang.org/grpc/grpclog"
|
||||||
)
|
)
|
||||||
@ -47,16 +47,16 @@ func mustFindLeaderEndpoints(c *clientv3.Client) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
leaderId := uint64(0)
|
leaderID := uint64(0)
|
||||||
for _, ep := range c.Endpoints() {
|
for _, ep := range c.Endpoints() {
|
||||||
if sresp, serr := c.Status(context.TODO(), ep); serr == nil {
|
if sresp, serr := c.Status(context.TODO(), ep); serr == nil {
|
||||||
leaderId = sresp.Leader
|
leaderID = sresp.Leader
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, m := range resp.Members {
|
for _, m := range resp.Members {
|
||||||
if m.ID == leaderId {
|
if m.ID == leaderID {
|
||||||
leaderEps = m.ClientURLs
|
leaderEps = m.ClientURLs
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,8 @@ func TestEtcdDumpLogEntryType(t *testing.T) {
|
|||||||
t.Skipf("%q does not exist", dumpLogsBinary)
|
t.Skipf("%q does not exist", dumpLogsBinary)
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder_correctoutputformat := filepath.Join(binDir, "/testdecoder/decoder_correctoutputformat.sh")
|
decoderCorrectOutputFormat := filepath.Join(binDir, "/testdecoder/decoder_correctoutputformat.sh")
|
||||||
decoder_wrongoutputformat := filepath.Join(binDir, "/testdecoder/decoder_wrongoutputformat.sh")
|
decoderWrongOutputFormat := filepath.Join(binDir, "/testdecoder/decoder_wrongoutputformat.sh")
|
||||||
|
|
||||||
p := t.TempDir()
|
p := t.TempDir()
|
||||||
|
|
||||||
@ -100,8 +100,8 @@ func TestEtcdDumpLogEntryType(t *testing.T) {
|
|||||||
{"lease grant entry-type", []string{"-entry-type", "IRRLeaseGrant", p}, "expectedoutput/listIRRLeaseGrant.output"},
|
{"lease grant entry-type", []string{"-entry-type", "IRRLeaseGrant", p}, "expectedoutput/listIRRLeaseGrant.output"},
|
||||||
{"lease revoke entry-type", []string{"-entry-type", "IRRLeaseRevoke", p}, "expectedoutput/listIRRLeaseRevoke.output"},
|
{"lease revoke entry-type", []string{"-entry-type", "IRRLeaseRevoke", p}, "expectedoutput/listIRRLeaseRevoke.output"},
|
||||||
{"confchange and txn entry-type", []string{"-entry-type", "ConfigChange,IRRCompaction", p}, "expectedoutput/listConfigChangeIRRCompaction.output"},
|
{"confchange and txn entry-type", []string{"-entry-type", "ConfigChange,IRRCompaction", p}, "expectedoutput/listConfigChangeIRRCompaction.output"},
|
||||||
{"decoder_correctoutputformat", []string{"-stream-decoder", decoder_correctoutputformat, p}, "expectedoutput/decoder_correctoutputformat.output"},
|
{"decoder_correctoutputformat", []string{"-stream-decoder", decoderCorrectOutputFormat, p}, "expectedoutput/decoder_correctoutputformat.output"},
|
||||||
{"decoder_wrongoutputformat", []string{"-stream-decoder", decoder_wrongoutputformat, p}, "expectedoutput/decoder_wrongoutputformat.output"},
|
{"decoder_wrongoutputformat", []string{"-stream-decoder", decoderWrongOutputFormat, p}, "expectedoutput/decoder_wrongoutputformat.output"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, argtest := range argtests {
|
for _, argtest := range argtests {
|
||||||
|
@ -90,12 +90,12 @@ and output a hex encoded line of binary for each input line`)
|
|||||||
case nil:
|
case nil:
|
||||||
walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term
|
walsnap.Index, walsnap.Term = snapshot.Metadata.Index, snapshot.Metadata.Term
|
||||||
nodes := genIDSlice(snapshot.Metadata.ConfState.Voters)
|
nodes := genIDSlice(snapshot.Metadata.ConfState.Voters)
|
||||||
confstateJson, err := json.Marshal(snapshot.Metadata.ConfState)
|
confStateJSON, err := json.Marshal(snapshot.Metadata.ConfState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
confstateJson = []byte(fmt.Sprintf("confstate err: %v", err))
|
confStateJSON = []byte(fmt.Sprintf("confstate err: %v", err))
|
||||||
}
|
}
|
||||||
fmt.Printf("Snapshot:\nterm=%d index=%d nodes=%s confstate=%s\n",
|
fmt.Printf("Snapshot:\nterm=%d index=%d nodes=%s confstate=%s\n",
|
||||||
walsnap.Term, walsnap.Index, nodes, confstateJson)
|
walsnap.Term, walsnap.Index, nodes, confStateJSON)
|
||||||
case snap.ErrNoSnapshot:
|
case snap.ErrNoSnapshot:
|
||||||
fmt.Printf("Snapshot:\nempty\n")
|
fmt.Printf("Snapshot:\nempty\n")
|
||||||
default:
|
default:
|
||||||
@ -372,9 +372,9 @@ func listEntriesType(entrytype string, streamdecoder string, ents []raftpb.Entry
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
decoder_status, decoded_data := parseDecoderOutput(decoderoutput)
|
decoderStatus, decodedData := parseDecoderOutput(decoderoutput)
|
||||||
|
|
||||||
fmt.Printf("\t%s\t%s", decoder_status, decoded_data)
|
fmt.Printf("\t%s\t%s", decoderStatus, decodedData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,19 +393,19 @@ func listEntriesType(entrytype string, streamdecoder string, ents []raftpb.Entry
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseDecoderOutput(decoderoutput string) (string, string) {
|
func parseDecoderOutput(decoderoutput string) (string, string) {
|
||||||
var decoder_status string
|
var decoderStatus string
|
||||||
var decoded_data string
|
var decodedData string
|
||||||
output := strings.Split(decoderoutput, "|")
|
output := strings.Split(decoderoutput, "|")
|
||||||
switch len(output) {
|
switch len(output) {
|
||||||
case 1:
|
case 1:
|
||||||
decoder_status = "decoder output format is not right, print output anyway"
|
decoderStatus = "decoder output format is not right, print output anyway"
|
||||||
decoded_data = decoderoutput
|
decodedData = decoderoutput
|
||||||
case 2:
|
case 2:
|
||||||
decoder_status = output[0]
|
decoderStatus = output[0]
|
||||||
decoded_data = output[1]
|
decodedData = output[1]
|
||||||
default:
|
default:
|
||||||
decoder_status = output[0] + "(*WARNING: data might contain deliminator used by etcd-dump-logs)"
|
decoderStatus = output[0] + "(*WARNING: data might contain deliminator used by etcd-dump-logs)"
|
||||||
decoded_data = strings.Join(output[1:], "")
|
decodedData = strings.Join(output[1:], "")
|
||||||
}
|
}
|
||||||
return decoder_status, decoded_data
|
return decoderStatus, decodedData
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user