From 3ffb98b2c93a9a633f7415893c40946e2a6a6e89 Mon Sep 17 00:00:00 2001 From: janardhanvissa <47281167+janardhanvissa@users.noreply.github.com> Date: Sat, 7 Sep 2024 20:06:51 +0000 Subject: [PATCH] .*: fix revive lints `redefines-builtin-id` (#7552) * Fix revive identified linter issues: redefines-builtin-id --------- Co-authored-by: Vissa Janardhan Krishna Sai Co-authored-by: Purnesh Dixit Co-authored-by: Arvind Bright --- balancer_wrapper.go | 4 ++-- internal/status/status.go | 4 ++-- internal/xds/rbac/converter.go | 4 ++-- orca/producer.go | 4 ++-- stats/opentelemetry/server_metrics.go | 4 ++-- status/status_test.go | 4 ++-- xds/internal/clusterspecifier/rls/rls.go | 4 ++-- xds/internal/httpfilter/fault/fault.go | 4 ++-- xds/internal/httpfilter/rbac/rbac.go | 8 ++++---- xds/internal/httpfilter/router/router.go | 4 ++-- xds/internal/resolver/xds_resolver.go | 4 ++-- xds/internal/xdsclient/loadreport_test.go | 4 ++-- xds/internal/xdsclient/xdsresource/filter_chain.go | 8 ++++---- xds/internal/xdsclient/xdsresource/unmarshal_cds.go | 8 ++++---- 14 files changed, 34 insertions(+), 34 deletions(-) diff --git a/balancer_wrapper.go b/balancer_wrapper.go index 5342511fe722..8ad6ce2f0950 100644 --- a/balancer_wrapper.go +++ b/balancer_wrapper.go @@ -342,8 +342,8 @@ func (acbw *acBalancerWrapper) GetOrBuildProducer(pb balancer.ProducerBuilder) ( pData := acbw.producers[pb] if pData == nil { // Not found; create a new one and add it to the producers map. - p, close := pb.Build(acbw) - pData = &refCountedProducer{producer: p, close: close} + p, closeFn := pb.Build(acbw) + pData = &refCountedProducer{producer: p, close: closeFn} acbw.producers[pb] = pData } // Account for this new reference. diff --git a/internal/status/status.go b/internal/status/status.go index c7dbc8205952..757925381fe7 100644 --- a/internal/status/status.go +++ b/internal/status/status.go @@ -138,11 +138,11 @@ func (s *Status) WithDetails(details ...protoadapt.MessageV1) (*Status, error) { // s.Code() != OK implies that s.Proto() != nil. p := s.Proto() for _, detail := range details { - any, err := anypb.New(protoadapt.MessageV2Of(detail)) + m, err := anypb.New(protoadapt.MessageV2Of(detail)) if err != nil { return nil, err } - p.Details = append(p.Details, any) + p.Details = append(p.Details, m) } return &Status{s: p}, nil } diff --git a/internal/xds/rbac/converter.go b/internal/xds/rbac/converter.go index 713e39cf31cb..fb599954a6c1 100644 --- a/internal/xds/rbac/converter.go +++ b/internal/xds/rbac/converter.go @@ -59,11 +59,11 @@ func buildLogger(loggerConfig *v3rbacpb.RBAC_AuditLoggingOptions_AuditLoggerConf } func getCustomConfig(config *anypb.Any) (json.RawMessage, string, error) { - any, err := config.UnmarshalNew() + c, err := config.UnmarshalNew() if err != nil { return nil, "", err } - switch m := any.(type) { + switch m := c.(type) { case *v1xdsudpatypepb.TypedStruct: return convertCustomConfig(m.TypeUrl, m.Value) case *v3xdsxdstypepb.TypedStruct: diff --git a/orca/producer.go b/orca/producer.go index 04edae6de66f..6e7c4c9f301a 100644 --- a/orca/producer.go +++ b/orca/producer.go @@ -72,7 +72,7 @@ type OOBListenerOptions struct { // returned stop function must be called when no longer needed. Do not // register a single OOBListener more than once per SubConn. func RegisterOOBListener(sc balancer.SubConn, l OOBListener, opts OOBListenerOptions) (stop func()) { - pr, close := sc.GetOrBuildProducer(producerBuilderSingleton) + pr, closeFn := sc.GetOrBuildProducer(producerBuilderSingleton) p := pr.(*producer) p.registerListener(l, opts.ReportInterval) @@ -84,7 +84,7 @@ func RegisterOOBListener(sc balancer.SubConn, l OOBListener, opts OOBListenerOpt // subsequent calls. return grpcsync.OnceFunc(func() { p.unregisterListener(l, opts.ReportInterval) - close() + closeFn() }) } diff --git a/stats/opentelemetry/server_metrics.go b/stats/opentelemetry/server_metrics.go index 75c7c43b69a4..eaea559b2c10 100644 --- a/stats/opentelemetry/server_metrics.go +++ b/stats/opentelemetry/server_metrics.go @@ -104,7 +104,7 @@ func (h *serverStatsHandler) unaryInterceptor(ctx context.Context, req any, _ *g } ctx = grpc.NewContextWithServerTransportStream(ctx, alts) - any, err := handler(ctx, req) + res, err := handler(ctx, req) if err != nil { // maybe trailers-only if headers haven't already been sent if !alts.attachedLabels.Swap(true) { alts.SetTrailer(alts.metadataExchangeLabels) @@ -115,7 +115,7 @@ func (h *serverStatsHandler) unaryInterceptor(ctx context.Context, req any, _ *g } } - return any, err + return res, err } // attachLabelsStream embeds a grpc.ServerStream, and intercepts the diff --git a/status/status_test.go b/status/status_test.go index 1db5d98b7835..03085d97d646 100644 --- a/status/status_test.go +++ b/status/status_test.go @@ -451,11 +451,11 @@ func str(s *Status) string { // mustMarshalAny converts a protobuf message to an any. func mustMarshalAny(msg proto.Message) *anypb.Any { - any, err := anypb.New(msg) + m, err := anypb.New(msg) if err != nil { panic(fmt.Sprintf("anypb.New(%+v) failed: %v", msg, err)) } - return any + return m } func (s) TestFromContextError(t *testing.T) { diff --git a/xds/internal/clusterspecifier/rls/rls.go b/xds/internal/clusterspecifier/rls/rls.go index 74abfec1fa88..89837605c1d1 100644 --- a/xds/internal/clusterspecifier/rls/rls.go +++ b/xds/internal/clusterspecifier/rls/rls.go @@ -65,13 +65,13 @@ func (rls) ParseClusterSpecifierConfig(cfg proto.Message) (clusterspecifier.Bala if cfg == nil { return nil, fmt.Errorf("rls_csp: nil configuration message provided") } - any, ok := cfg.(*anypb.Any) + m, ok := cfg.(*anypb.Any) if !ok { return nil, fmt.Errorf("rls_csp: error parsing config %v: unknown type %T", cfg, cfg) } rlcs := new(rlspb.RouteLookupClusterSpecifier) - if err := any.UnmarshalTo(rlcs); err != nil { + if err := m.UnmarshalTo(rlcs); err != nil { return nil, fmt.Errorf("rls_csp: error parsing config %v: %v", cfg, err) } rlcJSON, err := protojson.Marshal(rlcs.GetRouteLookupConfig()) diff --git a/xds/internal/httpfilter/fault/fault.go b/xds/internal/httpfilter/fault/fault.go index ada2ab8c12f0..5a82490598a3 100644 --- a/xds/internal/httpfilter/fault/fault.go +++ b/xds/internal/httpfilter/fault/fault.go @@ -81,12 +81,12 @@ func parseConfig(cfg proto.Message) (httpfilter.FilterConfig, error) { if cfg == nil { return nil, fmt.Errorf("fault: nil configuration message provided") } - any, ok := cfg.(*anypb.Any) + m, ok := cfg.(*anypb.Any) if !ok { return nil, fmt.Errorf("fault: error parsing config %v: unknown type %T", cfg, cfg) } msg := new(fpb.HTTPFault) - if err := any.UnmarshalTo(msg); err != nil { + if err := m.UnmarshalTo(msg); err != nil { return nil, fmt.Errorf("fault: error parsing config %v: %v", cfg, err) } return config{config: msg}, nil diff --git a/xds/internal/httpfilter/rbac/rbac.go b/xds/internal/httpfilter/rbac/rbac.go index f17977e6d084..bcda2ab05fc8 100644 --- a/xds/internal/httpfilter/rbac/rbac.go +++ b/xds/internal/httpfilter/rbac/rbac.go @@ -141,12 +141,12 @@ func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, er if cfg == nil { return nil, fmt.Errorf("rbac: nil configuration message provided") } - any, ok := cfg.(*anypb.Any) + m, ok := cfg.(*anypb.Any) if !ok { return nil, fmt.Errorf("rbac: error parsing config %v: unknown type %T", cfg, cfg) } msg := new(rpb.RBAC) - if err := any.UnmarshalTo(msg); err != nil { + if err := m.UnmarshalTo(msg); err != nil { return nil, fmt.Errorf("rbac: error parsing config %v: %v", cfg, err) } return parseConfig(msg) @@ -156,12 +156,12 @@ func (builder) ParseFilterConfigOverride(override proto.Message) (httpfilter.Fil if override == nil { return nil, fmt.Errorf("rbac: nil configuration message provided") } - any, ok := override.(*anypb.Any) + m, ok := override.(*anypb.Any) if !ok { return nil, fmt.Errorf("rbac: error parsing override config %v: unknown type %T", override, override) } msg := new(rpb.RBACPerRoute) - if err := any.UnmarshalTo(msg); err != nil { + if err := m.UnmarshalTo(msg); err != nil { return nil, fmt.Errorf("rbac: error parsing override config %v: %v", override, err) } return parseConfig(msg.Rbac) diff --git a/xds/internal/httpfilter/router/router.go b/xds/internal/httpfilter/router/router.go index 1675ec86ec11..a781523d371e 100644 --- a/xds/internal/httpfilter/router/router.go +++ b/xds/internal/httpfilter/router/router.go @@ -54,12 +54,12 @@ func (builder) ParseFilterConfig(cfg proto.Message) (httpfilter.FilterConfig, er if cfg == nil { return nil, fmt.Errorf("router: nil configuration message provided") } - any, ok := cfg.(*anypb.Any) + m, ok := cfg.(*anypb.Any) if !ok { return nil, fmt.Errorf("router: error parsing config %v: unknown type %T", cfg, cfg) } msg := new(pb.Router) - if err := any.UnmarshalTo(msg); err != nil { + if err := m.UnmarshalTo(msg); err != nil { return nil, fmt.Errorf("router: error parsing config %v: %v", cfg, err) } return config{}, nil diff --git a/xds/internal/resolver/xds_resolver.go b/xds/internal/resolver/xds_resolver.go index bc3525176da0..b5d24e4bf214 100644 --- a/xds/internal/resolver/xds_resolver.go +++ b/xds/internal/resolver/xds_resolver.go @@ -101,12 +101,12 @@ func (b *xdsResolverBuilder) Build(target resolver.Target, cc resolver.ClientCon if b.newXDSClient != nil { newXDSClient = b.newXDSClient } - client, close, err := newXDSClient(target.String()) + client, closeFn, err := newXDSClient(target.String()) if err != nil { return nil, fmt.Errorf("xds: failed to create xds-client: %v", err) } r.xdsClient = client - r.xdsClientClose = close + r.xdsClientClose = closeFn // Determine the listener resource name and start a watcher for it. template, err := r.sanityChecksOnBootstrapConfig(target, opts, r.xdsClient) diff --git a/xds/internal/xdsclient/loadreport_test.go b/xds/internal/xdsclient/loadreport_test.go index afdb7c607485..4731d0c744d7 100644 --- a/xds/internal/xdsclient/loadreport_test.go +++ b/xds/internal/xdsclient/loadreport_test.go @@ -49,7 +49,7 @@ func (s) TestLRSClient(t *testing.T) { t.Fatalf("Failed to create server config for testing: %v", err) } bc := e2e.DefaultBootstrapContents(t, nodeID, fs1.Address) - xdsC, close, err := NewForTesting(OptionsForTesting{ + xdsC, closeFn, err := NewForTesting(OptionsForTesting{ Name: t.Name(), Contents: bc, WatchExpiryTimeout: defaultTestWatchExpiryTimeout, @@ -57,7 +57,7 @@ func (s) TestLRSClient(t *testing.T) { if err != nil { t.Fatalf("Failed to create an xDS client: %v", err) } - defer close() + defer closeFn() // Report to the same address should not create new ClientConn. store1, lrsCancel1 := xdsC.ReportLoad(serverCfg1) diff --git a/xds/internal/xdsclient/xdsresource/filter_chain.go b/xds/internal/xdsclient/xdsresource/filter_chain.go index bef1277d220c..196bb9f873f2 100644 --- a/xds/internal/xdsclient/xdsresource/filter_chain.go +++ b/xds/internal/xdsclient/xdsresource/filter_chain.go @@ -536,12 +536,12 @@ func (fcm *FilterChainManager) filterChainFromProto(fc *v3listenerpb.FilterChain if name := ts.GetName(); name != transportSocketName { return nil, fmt.Errorf("transport_socket field has unexpected name: %s", name) } - any := ts.GetTypedConfig() - if any == nil || any.TypeUrl != version.V3DownstreamTLSContextURL { - return nil, fmt.Errorf("transport_socket field has unexpected typeURL: %s", any.TypeUrl) + tc := ts.GetTypedConfig() + if tc == nil || tc.TypeUrl != version.V3DownstreamTLSContextURL { + return nil, fmt.Errorf("transport_socket field has unexpected typeURL: %s", tc.TypeUrl) } downstreamCtx := &v3tlspb.DownstreamTlsContext{} - if err := proto.Unmarshal(any.GetValue(), downstreamCtx); err != nil { + if err := proto.Unmarshal(tc.GetValue(), downstreamCtx); err != nil { return nil, fmt.Errorf("failed to unmarshal DownstreamTlsContext in LDS response: %v", err) } if downstreamCtx.GetRequireSni().GetValue() { diff --git a/xds/internal/xdsclient/xdsresource/unmarshal_cds.go b/xds/internal/xdsclient/xdsresource/unmarshal_cds.go index 1d649ac55180..ab024b57c460 100644 --- a/xds/internal/xdsclient/xdsresource/unmarshal_cds.go +++ b/xds/internal/xdsclient/xdsresource/unmarshal_cds.go @@ -290,12 +290,12 @@ func securityConfigFromCluster(cluster *v3clusterpb.Cluster) (*SecurityConfig, e if name := ts.GetName(); name != transportSocketName { return nil, fmt.Errorf("transport_socket field has unexpected name: %s", name) } - any := ts.GetTypedConfig() - if any == nil || any.TypeUrl != version.V3UpstreamTLSContextURL { - return nil, fmt.Errorf("transport_socket field has unexpected typeURL: %s", any.TypeUrl) + tc := ts.GetTypedConfig() + if tc == nil || tc.TypeUrl != version.V3UpstreamTLSContextURL { + return nil, fmt.Errorf("transport_socket field has unexpected typeURL: %s", tc.TypeUrl) } upstreamCtx := &v3tlspb.UpstreamTlsContext{} - if err := proto.Unmarshal(any.GetValue(), upstreamCtx); err != nil { + if err := proto.Unmarshal(tc.GetValue(), upstreamCtx); err != nil { return nil, fmt.Errorf("failed to unmarshal UpstreamTlsContext in CDS response: %v", err) } // The following fields from `UpstreamTlsContext` are ignored: