Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint: fix some unused parameter issues #4956

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions authz/rbac_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,21 @@ func parsePrincipalNames(principalNames []string) []*v3rbacpb.Principal {
return ps
}

func parsePeer(source peer) (*v3rbacpb.Principal, error) {
func parsePeer(source peer) *v3rbacpb.Principal {
if source.Principals == nil {
return &v3rbacpb.Principal{
Identifier: &v3rbacpb.Principal_Any{
Any: true,
},
}, nil
}
}
if len(source.Principals) == 0 {
return &v3rbacpb.Principal{
Identifier: &v3rbacpb.Principal_Authenticated_{
Authenticated: &v3rbacpb.Principal_Authenticated{},
}}, nil
}}
}
return principalOr(parsePrincipalNames(source.Principals)), nil
return principalOr(parsePrincipalNames(source.Principals))
}

func parsePaths(paths []string) []*v3rbacpb.Permission {
Expand Down Expand Up @@ -257,17 +257,13 @@ func parseRules(rules []rule, prefixName string) (map[string]*v3rbacpb.Policy, e
if rule.Name == "" {
return policies, fmt.Errorf(`%d: "name" is not present`, i)
}
principal, err := parsePeer(rule.Source)
if err != nil {
return nil, fmt.Errorf("%d: %v", i, err)
}
permission, err := parseRequest(rule.Request)
if err != nil {
return nil, fmt.Errorf("%d: %v", i, err)
}
policyName := prefixName + "_" + rule.Name
policies[policyName] = &v3rbacpb.Policy{
Principals: []*v3rbacpb.Principal{principal},
Principals: []*v3rbacpb.Principal{parsePeer(rule.Source)},
Permissions: []*v3rbacpb.Permission{permission},
}
}
Expand Down
2 changes: 1 addition & 1 deletion balancer/rls/internal/adaptive/adaptive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestShouldThrottleOptions(t *testing.T) {
for _, test := range testcases {
t.Run(test.desc, func(t *testing.T) {
m.SetNanos(0)
th := newWithArgs(time.Duration(time.Nanosecond), 1, test.ratioForAccepts, test.requestsPadding)
th := newWithArgs(time.Nanosecond, 1, test.ratioForAccepts, test.requestsPadding)
for i, response := range responses {
if response != E {
th.RegisterBackendResponse(response == T)
Expand Down
2 changes: 1 addition & 1 deletion balancer/rls/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type lookupCallback func(targets []string, headerData string, err error)

// lookup starts a RouteLookup RPC in a separate goroutine and returns the
// results (and error, if any) in the provided callback.
func (c *rlsClient) lookup(path string, keyMap map[string]string, cb lookupCallback) {
func (c *rlsClient) lookup(keyMap map[string]string, cb lookupCallback) {
go func() {
ctx, cancel := context.WithTimeout(context.Background(), c.rpcTimeout)
resp, err := c.stub.RouteLookup(ctx, &rlspb.RouteLookupRequest{
Expand Down
11 changes: 4 additions & 7 deletions balancer/rls/internal/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s) TestLookupFailure(t *testing.T) {
rlsClient := newRLSClient(cc, defaultDialTarget, defaultRPCTimeout)

errCh := testutils.NewChannel()
rlsClient.lookup("", nil, func(targets []string, headerData string, err error) {
rlsClient.lookup(nil, func(targets []string, headerData string, err error) {
if err == nil {
errCh.Send(errors.New("rlsClient.lookup() succeeded, should have failed"))
return
Expand Down Expand Up @@ -101,7 +101,7 @@ func (s) TestLookupDeadlineExceeded(t *testing.T) {
rlsClient := newRLSClient(cc, defaultDialTarget, 100*time.Millisecond)

errCh := testutils.NewChannel()
rlsClient.lookup("", nil, func(_ []string, _ string, err error) {
rlsClient.lookup(nil, func(_ []string, _ string, err error) {
if st, ok := status.FromError(err); !ok || st.Code() != codes.DeadlineExceeded {
errCh.Send(fmt.Errorf("rlsClient.lookup() returned error: %v, want %v", err, codes.DeadlineExceeded))
return
Expand All @@ -121,10 +121,7 @@ func (s) TestLookupSuccess(t *testing.T) {
server, cc, cleanup := setup(t)
defer cleanup()

const (
rlsReqPath = "/service/method"
wantHeaderData = "headerData"
)
const wantHeaderData = "headerData"

rlsReqKeyMap := map[string]string{
"k1": "v1",
Expand All @@ -141,7 +138,7 @@ func (s) TestLookupSuccess(t *testing.T) {
rlsClient := newRLSClient(cc, defaultDialTarget, defaultRPCTimeout)

errCh := testutils.NewChannel()
rlsClient.lookup(rlsReqPath, rlsReqKeyMap, func(targets []string, hd string, err error) {
rlsClient.lookup(rlsReqKeyMap, func(targets []string, hd string, err error) {
if err != nil {
errCh.Send(fmt.Errorf("rlsClient.Lookup() failed: %v", err))
return
Expand Down
4 changes: 2 additions & 2 deletions benchmark/benchmain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func streamBenchmark(start startFunc, stop stopFunc, bf stats.Features, s *stats
runBenchmark(caller, start, stop, bf, s, workloadsStreaming)
}

func unconstrainedStreamBenchmark(start startFunc, stop ucStopFunc, bf stats.Features, s *stats.Stats) {
func unconstrainedStreamBenchmark(start startFunc, stop ucStopFunc, bf stats.Features) {
var sender rpcSendFunc
var recver rpcRecvFunc
var cleanup rpcCleanupFunc
Expand Down Expand Up @@ -771,7 +771,7 @@ func main() {
streamBenchmark(start, stop, bf, s)
}
if opts.rModes.unconstrained {
unconstrainedStreamBenchmark(start, ucStop, bf, s)
unconstrainedStreamBenchmark(start, ucStop, bf)
}
}
after(opts, s.GetResults())
Expand Down
2 changes: 1 addition & 1 deletion benchmark/latency/latency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (s) TestConn(t *testing.T) {
wantSleeps(latency) // Connection creation delay.

// 1 kbps = 128 Bps. Divides evenly by 1 second using nanos.
byteLatency := time.Duration(time.Second / 128)
byteLatency := time.Second / 128

write := func(b []byte) {
n, err := c.Write(b)
Expand Down
13 changes: 5 additions & 8 deletions binarylog/binarylog_end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,10 @@ func (te *test) tearDown() {
te.srv.Stop()
}

type testConfig struct {
}

// newTest returns a new test using the provided testing.T and
// environment. It is returned with default values. Tests should
// modify it before calling its startServer and clientConn methods.
func newTest(t *testing.T, tc *testConfig) *test {
func newTest(t *testing.T) *test {
te := &test{
t: t,
}
Expand Down Expand Up @@ -794,8 +791,8 @@ func (ed *expectedData) toServerLogEntries() []*pb.GrpcLogEntry {
return ret
}

func runRPCs(t *testing.T, tc *testConfig, cc *rpcConfig) *expectedData {
te := newTest(t, tc)
func runRPCs(t *testing.T, cc *rpcConfig) *expectedData {
te := newTest(t)
te.startServer(&testServer{te: te})
defer te.tearDown()

Expand Down Expand Up @@ -869,7 +866,7 @@ func equalLogEntry(entries ...*pb.GrpcLogEntry) (equal bool) {

func testClientBinaryLog(t *testing.T, c *rpcConfig) error {
defer testSink.clear()
expect := runRPCs(t, &testConfig{}, c)
expect := runRPCs(t, c)
want := expect.toClientLogEntries()
var got []*pb.GrpcLogEntry
// In racy cases, some entries are not logged when the RPC is finished (e.g.
Expand Down Expand Up @@ -969,7 +966,7 @@ func (s) TestClientBinaryLogCancel(t *testing.T) {

func testServerBinaryLog(t *testing.T, c *rpcConfig) error {
defer testSink.clear()
expect := runRPCs(t, &testConfig{}, c)
expect := runRPCs(t, c)
want := expect.toServerLogEntries()
var got []*pb.GrpcLogEntry
// In racy cases, some entries are not logged when the RPC is finished (e.g.
Expand Down
20 changes: 10 additions & 10 deletions internal/channelz/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ func RegisterChannel(c Channel, pid int64, ref string) int64 {
trace: &channelTrace{createdTime: time.Now(), events: make([]*TraceEvent, 0, getMaxTraceEntry())},
}
if pid == 0 {
db.get().addChannel(id, cn, true, pid, ref)
db.get().addChannel(id, cn, true, pid)
} else {
db.get().addChannel(id, cn, false, pid, ref)
db.get().addChannel(id, cn, false, pid)
}
return id
}
Expand All @@ -228,7 +228,7 @@ func RegisterSubChannel(c Channel, pid int64, ref string) int64 {
pid: pid,
trace: &channelTrace{createdTime: time.Now(), events: make([]*TraceEvent, 0, getMaxTraceEntry())},
}
db.get().addSubChannel(id, sc, pid, ref)
db.get().addSubChannel(id, sc, pid)
return id
}

Expand Down Expand Up @@ -258,7 +258,7 @@ func RegisterListenSocket(s Socket, pid int64, ref string) int64 {
}
id := idGen.genID()
ls := &listenSocket{refName: ref, s: s, id: id, pid: pid}
db.get().addListenSocket(id, ls, pid, ref)
db.get().addListenSocket(id, ls, pid)
return id
}

Expand All @@ -273,11 +273,11 @@ func RegisterNormalSocket(s Socket, pid int64, ref string) int64 {
}
id := idGen.genID()
ns := &normalSocket{refName: ref, s: s, id: id, pid: pid}
db.get().addNormalSocket(id, ns, pid, ref)
db.get().addNormalSocket(id, ns, pid)
return id
}

// RemoveEntry removes an entry with unique channelz trakcing id to be id from
// RemoveEntry removes an entry with unique channelz tracking id to be id from
// channelz database.
func RemoveEntry(id int64) {
db.get().removeEntry(id)
Expand Down Expand Up @@ -333,7 +333,7 @@ func (c *channelMap) addServer(id int64, s *server) {
c.mu.Unlock()
}

func (c *channelMap) addChannel(id int64, cn *channel, isTopChannel bool, pid int64, ref string) {
func (c *channelMap) addChannel(id int64, cn *channel, isTopChannel bool, pid int64) {
c.mu.Lock()
cn.cm = c
cn.trace.cm = c
Expand All @@ -346,7 +346,7 @@ func (c *channelMap) addChannel(id int64, cn *channel, isTopChannel bool, pid in
c.mu.Unlock()
}

func (c *channelMap) addSubChannel(id int64, sc *subChannel, pid int64, ref string) {
func (c *channelMap) addSubChannel(id int64, sc *subChannel, pid int64) {
c.mu.Lock()
sc.cm = c
sc.trace.cm = c
Expand All @@ -355,15 +355,15 @@ func (c *channelMap) addSubChannel(id int64, sc *subChannel, pid int64, ref stri
c.mu.Unlock()
}

func (c *channelMap) addListenSocket(id int64, ls *listenSocket, pid int64, ref string) {
func (c *channelMap) addListenSocket(id int64, ls *listenSocket, pid int64) {
c.mu.Lock()
ls.cm = c
c.listenSockets[id] = ls
c.findEntry(pid).addChild(id, ls)
c.mu.Unlock()
}

func (c *channelMap) addNormalSocket(id int64, ns *normalSocket, pid int64, ref string) {
func (c *channelMap) addNormalSocket(id int64, ns *normalSocket, pid int64) {
c.mu.Lock()
ns.cm = c
c.normalSockets[id] = ns
Expand Down
2 changes: 1 addition & 1 deletion internal/profiling/buffer/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (cb *CircularBuffer) Drain() []interface{} {
}

var wg sync.WaitGroup
wg.Add(int(len(qs)))
wg.Add(len(qs))
for i := 0; i < len(qs); i++ {
go func(qi int) {
qs[qi].drainWait()
Expand Down
6 changes: 3 additions & 3 deletions internal/serviceconfig/serviceconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ func TestBalancerConfigMarshalJSON(t *testing.T) {
Name: testBalancerBuilderName,
Config: testBalancerConfig,
},
wantJSON: fmt.Sprintf(`[{"test-bb": {"check":true}}]`),
wantJSON: `[{"test-bb": {"check":true}}]`,
},
{
name: "OK config is nil",
bc: BalancerConfig{
Name: testBalancerBuilderNotParserName,
Config: nil, // nil should be marshalled to an empty config "{}".
},
wantJSON: fmt.Sprintf(`[{"test-bb-not-parser": {}}]`),
wantJSON: `[{"test-bb-not-parser": {}}]`,
},
}
for _, tt := range tests {
Expand All @@ -172,7 +172,7 @@ func TestBalancerConfigMarshalJSON(t *testing.T) {

var bc BalancerConfig
if err := bc.UnmarshalJSON(b); err != nil {
t.Errorf("failed to mnmarshal: %v", err)
t.Errorf("failed to unmarshal: %v", err)
}
if !cmp.Equal(bc, tt.bc) {
t.Errorf("diff: %v", cmp.Diff(bc, tt.bc))
Expand Down
4 changes: 1 addition & 3 deletions internal/transport/flowcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,10 @@ type inFlow struct {

// newLimit updates the inflow window to a new value n.
// It assumes that n is always greater than the old limit.
func (f *inFlow) newLimit(n uint32) uint32 {
func (f *inFlow) newLimit(n uint32) {
f.mu.Lock()
d := n - f.limit
f.limit = n
f.mu.Unlock()
return d
}

func (f *inFlow) maybeAdjust(n uint32) uint32 {
Expand Down
2 changes: 1 addition & 1 deletion internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ func minTime(a, b time.Duration) time.Duration {
return b
}

// keepalive running in a separate goroutune makes sure the connection is alive by sending pings.
// keepalive running in a separate goroutine makes sure the connection is alive by sending pings.
func (t *http2Client) keepalive() {
p := &ping{data: [8]byte{}}
// True iff a ping has been sent, and no data has been received since then.
Expand Down
4 changes: 2 additions & 2 deletions internal/transport/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var (
httpProxyFromEnvironment = http.ProxyFromEnvironment
)

func mapAddress(ctx context.Context, address string) (*url.URL, error) {
func mapAddress(address string) (*url.URL, error) {
req := &http.Request{
URL: &url.URL{
Scheme: "https",
Expand Down Expand Up @@ -114,7 +114,7 @@ func doHTTPConnectHandshake(ctx context.Context, conn net.Conn, backendAddr stri
// connection.
func proxyDial(ctx context.Context, addr string, grpcUA string) (conn net.Conn, err error) {
newAddr := addr
proxyURL, err := mapAddress(ctx, addr)
proxyURL, err := mapAddress(addr)
if err != nil {
return nil, err
}
Expand Down
5 changes: 1 addition & 4 deletions internal/transport/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,8 @@ func (s) TestMapAddressEnv(t *testing.T) {
}
defer overwrite(hpfe)()

ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
defer cancel()

// envTestAddr should be handled by ProxyFromEnvironment.
got, err := mapAddress(ctx, envTestAddr)
got, err := mapAddress(envTestAddr)
if err != nil {
t.Error(err)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ func (h *testStreamHandler) handleStreamMisbehave(t *testing.T, s *Stream) {
}
}

func (h *testStreamHandler) handleStreamEncodingRequiredStatus(t *testing.T, s *Stream) {
func (h *testStreamHandler) handleStreamEncodingRequiredStatus(s *Stream) {
// raw newline is not accepted by http2 framer so it must be encoded.
h.t.WriteStatus(s, encodingTestStatus)
}

func (h *testStreamHandler) handleStreamInvalidHeaderField(t *testing.T, s *Stream) {
func (h *testStreamHandler) handleStreamInvalidHeaderField(s *Stream) {
headerFields := []hpack.HeaderField{}
headerFields = append(headerFields, hpack.HeaderField{Name: "content-type", Value: expectedInvalidHeaderField})
h.t.controlBuf.put(&headerFrame{
Expand Down Expand Up @@ -356,13 +356,13 @@ func (s *server) start(t *testing.T, port int, serverConfig *ServerConfig, ht hT
})
case encodingRequiredStatus:
go transport.HandleStreams(func(s *Stream) {
go h.handleStreamEncodingRequiredStatus(t, s)
go h.handleStreamEncodingRequiredStatus(s)
}, func(ctx context.Context, method string) context.Context {
return ctx
})
case invalidHeaderField:
go transport.HandleStreams(func(s *Stream) {
go h.handleStreamInvalidHeaderField(t, s)
go h.handleStreamInvalidHeaderField(s)
}, func(ctx context.Context, method string) context.Context {
return ctx
})
Expand Down
Loading