From f2fbe8aec92a880ba5feb967e5ef6cea2f53b7e1 Mon Sep 17 00:00:00 2001 From: Kyle Havlovitz Date: Tue, 24 May 2022 18:44:54 -0700 Subject: [PATCH] Fix proto lint errors after version bump --- .golangci.yml | 9 +++++++++ agent/structs/structs.go | 15 ++++++--------- agent/xds/clusters.go | 20 ++++++++++---------- agent/xds/config.go | 4 ++-- agent/xds/listeners.go | 3 ++- agent/xds/routes.go | 8 ++++---- agent/xds/routes_test.go | 8 ++++---- agent/xds/xds_protocol_helpers_test.go | 13 +++++++------ 8 files changed, 44 insertions(+), 36 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 40936a6898..5dd9235837 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,6 +26,15 @@ issues: - linters: [staticcheck] text: 'SA1019: Package github.com/golang/protobuf/proto is deprecated' + - linters: [staticcheck] + text: 'SA1019: ptypes.MarshalAny is deprecated' + + - linters: [staticcheck] + text: 'SA1019: ptypes.UnmarshalAny is deprecated' + + - linters: [staticcheck] + text: 'SA1019: package github.com/golang/protobuf/ptypes is deprecated' + # An argument that always receives the same value is often not a problem. - linters: [unparam] text: 'always receives' diff --git a/agent/structs/structs.go b/agent/structs/structs.go index 35d2f57a4a..e1083ba7fc 100644 --- a/agent/structs/structs.go +++ b/agent/structs/structs.go @@ -15,12 +15,13 @@ import ( "time" "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes/duration" "github.com/golang/protobuf/ptypes/timestamp" "github.com/hashicorp/go-multierror" "github.com/hashicorp/serf/coordinate" "github.com/mitchellh/hashstructure" + "google.golang.org/protobuf/types/known/durationpb" + "google.golang.org/protobuf/types/known/timestamppb" "github.com/hashicorp/consul-net-rpc/go-msgpack/codec" @@ -2815,23 +2816,19 @@ func (m MessageType) String() string { } func DurationToProto(d time.Duration) *duration.Duration { - return ptypes.DurationProto(d) + return durationpb.New(d) } func DurationFromProto(d *duration.Duration) time.Duration { - ret, _ := ptypes.Duration(d) - return ret - + return d.AsDuration() } func TimeFromProto(s *timestamp.Timestamp) time.Time { - ret, _ := ptypes.Timestamp(s) - return ret + return s.AsTime() } func TimeToProto(s time.Time) *timestamp.Timestamp { - ret, _ := ptypes.TimestampProto(s) - return ret + return timestamppb.New(s) } // IsZeroProtoTime returns true if the time is the minimum protobuf timestamp diff --git a/agent/xds/clusters.go b/agent/xds/clusters.go index e2df471da5..d5044cb21d 100644 --- a/agent/xds/clusters.go +++ b/agent/xds/clusters.go @@ -16,10 +16,10 @@ import ( "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes/any" "github.com/golang/protobuf/ptypes/wrappers" "google.golang.org/protobuf/types/known/anypb" + "google.golang.org/protobuf/types/known/durationpb" "github.com/hashicorp/consul/agent/connect" "github.com/hashicorp/consul/agent/proxycfg" @@ -169,7 +169,7 @@ func makePassthroughClusters(cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, Type: envoy_cluster_v3.Cluster_ORIGINAL_DST, }, LbPolicy: envoy_cluster_v3.Cluster_CLUSTER_PROVIDED, - ConnectTimeout: ptypes.DurationProto(5 * time.Second), + ConnectTimeout: durationpb.New(5 * time.Second), }) } @@ -196,11 +196,11 @@ func makePassthroughClusters(cfgSnap *proxycfg.ConfigSnapshot) ([]proto.Message, }, LbPolicy: envoy_cluster_v3.Cluster_CLUSTER_PROVIDED, - ConnectTimeout: ptypes.DurationProto(5 * time.Second), + ConnectTimeout: durationpb.New(5 * time.Second), } if discoTarget, ok := chain.Targets[targetID]; ok && discoTarget.ConnectTimeout > 0 { - c.ConnectTimeout = ptypes.DurationProto(discoTarget.ConnectTimeout) + c.ConnectTimeout = durationpb.New(discoTarget.ConnectTimeout) } spiffeID := connect.SpiffeIDService{ @@ -486,7 +486,7 @@ func (s *ResourceGenerator) makeAppCluster(cfgSnap *proxycfg.ConfigSnapshot, nam c = &envoy_cluster_v3.Cluster{ Name: name, - ConnectTimeout: ptypes.DurationProto(time.Duration(cfg.LocalConnectTimeoutMs) * time.Millisecond), + ConnectTimeout: durationpb.New(time.Duration(cfg.LocalConnectTimeoutMs) * time.Millisecond), ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_STATIC}, LoadAssignment: &envoy_endpoint_v3.ClusterLoadAssignment{ ClusterName: name, @@ -550,7 +550,7 @@ func (s *ResourceGenerator) makeUpstreamClusterForPreparedQuery(upstream structs if c == nil { c = &envoy_cluster_v3.Cluster{ Name: sni, - ConnectTimeout: ptypes.DurationProto(time.Duration(cfg.ConnectTimeoutMs) * time.Millisecond), + ConnectTimeout: durationpb.New(time.Duration(cfg.ConnectTimeoutMs) * time.Millisecond), ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_EDS}, EdsClusterConfig: &envoy_cluster_v3.Cluster_EdsClusterConfig{ EdsConfig: &envoy_core_v3.ConfigSource{ @@ -738,7 +738,7 @@ func (s *ResourceGenerator) makeUpstreamClustersForDiscoveryChain( c := &envoy_cluster_v3.Cluster{ Name: clusterName, AltStatName: clusterName, - ConnectTimeout: ptypes.DurationProto(node.Resolver.ConnectTimeout), + ConnectTimeout: durationpb.New(node.Resolver.ConnectTimeout), ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_EDS}, CommonLbConfig: &envoy_cluster_v3.Cluster_CommonLbConfig{ HealthyPanicThreshold: &envoy_type_v3.Percent{ @@ -912,7 +912,7 @@ func (s *ResourceGenerator) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, op cluster := &envoy_cluster_v3.Cluster{ Name: opts.name, - ConnectTimeout: ptypes.DurationProto(opts.connectTimeout), + ConnectTimeout: durationpb.New(opts.connectTimeout), // Having an empty config enables outlier detection with default config. OutlierDetection: &envoy_cluster_v3.OutlierDetection{}, @@ -940,7 +940,7 @@ func (s *ResourceGenerator) makeGatewayCluster(snap *proxycfg.ConfigSnapshot, op // When a service instance is addressed by a hostname we have Envoy do the DNS resolution // by setting a DNS cluster type and passing the hostname endpoints via CDS. rate := 10 * time.Second - cluster.DnsRefreshRate = ptypes.DurationProto(rate) + cluster.DnsRefreshRate = durationpb.New(rate) cluster.DnsLookupFamily = envoy_cluster_v3.Cluster_V4_ONLY discoveryType := envoy_cluster_v3.Cluster_Type{Type: envoy_cluster_v3.Cluster_LOGICAL_DNS} @@ -1099,7 +1099,7 @@ func (s *ResourceGenerator) setHttp2ProtocolOptions(c *envoy_cluster_v3.Cluster) }, }, } - any, err := ptypes.MarshalAny(cfg) + any, err := anypb.New(cfg) if err != nil { return err } diff --git a/agent/xds/config.go b/agent/xds/config.go index 004b94a659..2fdf9d115e 100644 --- a/agent/xds/config.go +++ b/agent/xds/config.go @@ -4,8 +4,8 @@ import ( "strings" envoy_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3" + "google.golang.org/protobuf/types/known/durationpb" - "github.com/golang/protobuf/ptypes" "github.com/golang/protobuf/ptypes/wrappers" "github.com/mitchellh/mapstructure" @@ -163,7 +163,7 @@ func ToOutlierDetection(p *structs.PassiveHealthCheck) *envoy_cluster_v3.Outlier } if p.Interval != 0 { - od.Interval = ptypes.DurationProto(p.Interval) + od.Interval = durationpb.New(p.Interval) } if p.MaxFailures != 0 { od.Consecutive_5Xx = &wrappers.UInt32Value{Value: p.MaxFailures} diff --git a/agent/xds/listeners.go b/agent/xds/listeners.go index c462466d0e..6b03122e8b 100644 --- a/agent/xds/listeners.go +++ b/agent/xds/listeners.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/consul/acl" "github.com/hashicorp/consul/agent/connect/ca" "github.com/hashicorp/consul/types" + "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/wrapperspb" envoy_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" @@ -1519,7 +1520,7 @@ func makeHTTPFilter(opts listenerFilterOpts) (*envoy_listener_v3.Filter, error) if opts.requestTimeoutMs != nil { r := route.GetRoute() - r.Timeout = ptypes.DurationProto(time.Duration(*opts.requestTimeoutMs) * time.Millisecond) + r.Timeout = durationpb.New(time.Duration(*opts.requestTimeoutMs) * time.Millisecond) } // If a path is provided, do not match on a catch-all prefix diff --git a/agent/xds/routes.go b/agent/xds/routes.go index 0a772d3f55..2df52feefa 100644 --- a/agent/xds/routes.go +++ b/agent/xds/routes.go @@ -10,9 +10,9 @@ import ( envoy_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" envoy_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3" envoy_matcher_v3 "github.com/envoyproxy/go-control-plane/envoy/type/matcher/v3" + "google.golang.org/protobuf/types/known/durationpb" "github.com/golang/protobuf/proto" - "github.com/golang/protobuf/ptypes" "github.com/hashicorp/consul/agent/connect" "github.com/hashicorp/consul/agent/proxycfg" @@ -387,7 +387,7 @@ func makeUpstreamRouteForDiscoveryChain( } if destination.RequestTimeout > 0 { - routeAction.Route.Timeout = ptypes.DurationProto(destination.RequestTimeout) + routeAction.Route.Timeout = durationpb.New(destination.RequestTimeout) } if destination.HasRetryFeatures() { @@ -699,12 +699,12 @@ func injectLBToRouteAction(lb *structs.LoadBalancer, action *envoy_route_v3.Rout cookie.Path = policy.CookieConfig.Path if policy.CookieConfig.TTL != 0*time.Second { - cookie.Ttl = ptypes.DurationProto(policy.CookieConfig.TTL) + cookie.Ttl = durationpb.New(policy.CookieConfig.TTL) } // Envoy will generate a session cookie if the ttl is present and zero. if policy.CookieConfig.Session { - cookie.Ttl = ptypes.DurationProto(0 * time.Second) + cookie.Ttl = durationpb.New(0 * time.Second) } } result = append(result, &envoy_route_v3.RouteAction_HashPolicy{ diff --git a/agent/xds/routes_test.go b/agent/xds/routes_test.go index ad033faadb..501d05cb2e 100644 --- a/agent/xds/routes_test.go +++ b/agent/xds/routes_test.go @@ -7,8 +7,8 @@ import ( "time" envoy_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3" + "google.golang.org/protobuf/types/known/durationpb" - "github.com/golang/protobuf/ptypes" testinf "github.com/mitchellh/go-testing-interface" "github.com/stretchr/testify/require" @@ -332,7 +332,7 @@ func TestEnvoyLBConfig_InjectToRouteAction(t *testing.T) { PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Cookie_{ Cookie: &envoy_route_v3.RouteAction_HashPolicy_Cookie{ Name: "oatmeal", - Ttl: ptypes.DurationProto(0 * time.Second), + Ttl: durationpb.New(0 * time.Second), }, }, }, @@ -437,7 +437,7 @@ func TestEnvoyLBConfig_InjectToRouteAction(t *testing.T) { PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Cookie_{ Cookie: &envoy_route_v3.RouteAction_HashPolicy_Cookie{ Name: "oatmeal", - Ttl: ptypes.DurationProto(10 * time.Second), + Ttl: durationpb.New(10 * time.Second), Path: "/oven", }, }, @@ -446,7 +446,7 @@ func TestEnvoyLBConfig_InjectToRouteAction(t *testing.T) { PolicySpecifier: &envoy_route_v3.RouteAction_HashPolicy_Cookie_{ Cookie: &envoy_route_v3.RouteAction_HashPolicy_Cookie{ Name: "chocolate-chip", - Ttl: ptypes.DurationProto(0 * time.Second), + Ttl: durationpb.New(0 * time.Second), Path: "/oven", }, }, diff --git a/agent/xds/xds_protocol_helpers_test.go b/agent/xds/xds_protocol_helpers_test.go index 1863aae0b2..df4c65fb40 100644 --- a/agent/xds/xds_protocol_helpers_test.go +++ b/agent/xds/xds_protocol_helpers_test.go @@ -30,6 +30,7 @@ import ( "github.com/mitchellh/copystructure" "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/anypb" + "google.golang.org/protobuf/types/known/durationpb" "github.com/hashicorp/consul/agent/proxycfg" "github.com/hashicorp/consul/agent/structs" @@ -389,7 +390,7 @@ func makeTestCluster(t *testing.T, snap *proxycfg.ConfigSnapshot, fixtureName st ClusterDiscoveryType: &envoy_cluster_v3.Cluster_Type{ Type: envoy_cluster_v3.Cluster_STATIC, }, - ConnectTimeout: ptypes.DurationProto(5 * time.Second), + ConnectTimeout: durationpb.New(5 * time.Second), LoadAssignment: &envoy_endpoint_v3.ClusterLoadAssignment{ ClusterName: "local_app", Endpoints: []*envoy_endpoint_v3.LocalityLbEndpoints{{ @@ -414,7 +415,7 @@ func makeTestCluster(t *testing.T, snap *proxycfg.ConfigSnapshot, fixtureName st CommonLbConfig: &envoy_cluster_v3.Cluster_CommonLbConfig{ HealthyPanicThreshold: &envoy_type_v3.Percent{Value: 0}, }, - ConnectTimeout: ptypes.DurationProto(5 * time.Second), + ConnectTimeout: durationpb.New(5 * time.Second), TransportSocket: xdsNewUpstreamTransportSocket(t, snap, dbSNI, dbURI), } case "tcp:db:timeout": @@ -432,7 +433,7 @@ func makeTestCluster(t *testing.T, snap *proxycfg.ConfigSnapshot, fixtureName st CommonLbConfig: &envoy_cluster_v3.Cluster_CommonLbConfig{ HealthyPanicThreshold: &envoy_type_v3.Percent{Value: 0}, }, - ConnectTimeout: ptypes.DurationProto(1337 * time.Second), + ConnectTimeout: durationpb.New(1337 * time.Second), TransportSocket: xdsNewUpstreamTransportSocket(t, snap, dbSNI, dbURI), } case "http2:db": @@ -450,7 +451,7 @@ func makeTestCluster(t *testing.T, snap *proxycfg.ConfigSnapshot, fixtureName st CommonLbConfig: &envoy_cluster_v3.Cluster_CommonLbConfig{ HealthyPanicThreshold: &envoy_type_v3.Percent{Value: 0}, }, - ConnectTimeout: ptypes.DurationProto(5 * time.Second), + ConnectTimeout: durationpb.New(5 * time.Second), TransportSocket: xdsNewUpstreamTransportSocket(t, snap, dbSNI, dbURI), } typedExtensionProtocolOptions := &envoy_upstreams_v3.HttpProtocolOptions{ @@ -483,7 +484,7 @@ func makeTestCluster(t *testing.T, snap *proxycfg.ConfigSnapshot, fixtureName st CommonLbConfig: &envoy_cluster_v3.Cluster_CommonLbConfig{ HealthyPanicThreshold: &envoy_type_v3.Percent{Value: 0}, }, - ConnectTimeout: ptypes.DurationProto(5 * time.Second), + ConnectTimeout: durationpb.New(5 * time.Second), TransportSocket: xdsNewUpstreamTransportSocket(t, snap, dbSNI, dbURI), // HttpProtocolOptions: &envoy_core_v3.Http1ProtocolOptions{}, } @@ -498,7 +499,7 @@ func makeTestCluster(t *testing.T, snap *proxycfg.ConfigSnapshot, fixtureName st }, CircuitBreakers: &envoy_cluster_v3.CircuitBreakers{}, OutlierDetection: &envoy_cluster_v3.OutlierDetection{}, - ConnectTimeout: ptypes.DurationProto(5 * time.Second), + ConnectTimeout: durationpb.New(5 * time.Second), TransportSocket: xdsNewUpstreamTransportSocket(t, snap, geocacheSNI, geocacheURIs...), } default: