Skip to content

Commit

Permalink
lint for CI (#480)
Browse files Browse the repository at this point in the history
Signed-off-by: Alec Holmes <[email protected]>
  • Loading branch information
alecholmez authored Oct 26, 2021
1 parent e7fb5d0 commit 996a28b
Show file tree
Hide file tree
Showing 19 changed files with 149 additions and 132 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: golangci-lint

on: [push, pull_request]

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
only-new-issues: true

# Optional: golangci-lint command line arguments.
args: --timeout=10m0s
13 changes: 1 addition & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ linters:
- bodyclose
- gofmt
- goimports
- golint
- gosec
- misspell
- revive
Expand All @@ -24,14 +23,4 @@ linters-settings:
local-prefixes: github.com/envoyproxy/go-control-plane

issues:
exclude:
exclude-rules:
- text: "SA1019: package github.com/golang/protobuf/jsonpb is deprecated"
linters:
- staticcheck
- text: "SA1019: package github.com/golang/protobuf/proto is deprecated"
linters:
- staticcheck
- text: "SA1019: proto.MessageName is deprecated"
linters:
- staticcheck
fix: true
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ require (
github.com/census-instrumentation/opencensus-proto v0.2.1
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe
github.com/envoyproxy/protoc-gen-validate v0.1.0
github.com/golang/protobuf v1.4.3
github.com/google/go-cmp v0.5.0
github.com/golang/protobuf v1.5.0
github.com/google/go-cmp v0.5.5
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/proto/otlp v0.7.0
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.36.0
google.golang.org/protobuf v1.25.0
google.golang.org/protobuf v1.27.1
)
10 changes: 7 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -112,8 +114,10 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
7 changes: 4 additions & 3 deletions internal/example/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ package example
import (
"time"

"github.com/golang/protobuf/ptypes"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/durationpb"

cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
Expand All @@ -42,7 +43,7 @@ const (
func makeCluster(clusterName string) *cluster.Cluster {
return &cluster.Cluster{
Name: clusterName,
ConnectTimeout: ptypes.DurationProto(5 * time.Second),
ConnectTimeout: durationpb.New(5 * time.Second),
ClusterDiscoveryType: &cluster.Cluster_Type{Type: cluster.Cluster_LOGICAL_DNS},
LbPolicy: cluster.Cluster_ROUND_ROBIN,
LoadAssignment: makeEndpoint(clusterName),
Expand Down Expand Up @@ -117,7 +118,7 @@ func makeHTTPListener(listenerName string, route string) *listener.Listener {
Name: wellknown.Router,
}},
}
pbst, err := ptypes.MarshalAny(manager)
pbst, err := anypb.New(manager)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cache/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import (
"time"

"github.com/golang/protobuf/proto"
"google.golang.org/protobuf/proto"
)

// Resource is the base interface for the xDS payload.
Expand Down
25 changes: 11 additions & 14 deletions pkg/cache/v3/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ import (
"fmt"
"sync/atomic"

discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"

"github.com/golang/protobuf/proto"

"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
"google.golang.org/protobuf/types/known/durationpb"

"github.com/envoyproxy/go-control-plane/pkg/cache/types"
"github.com/envoyproxy/go-control-plane/pkg/server/stream/v3"

discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
)

// Request is an alias for the discovery request type.
Expand Down Expand Up @@ -196,12 +195,10 @@ var _ DeltaResponse = &DeltaPassthroughResponse{}
// This is necessary because the marshaled response does not change across the calls.
// This caching behavior is important in high throughput scenarios because grpc marshaling has a cost and it drives the cpu utilization under load.
func (r *RawResponse) GetDiscoveryResponse() (*discovery.DiscoveryResponse, error) {

marshaledResponse := r.marshaledResponse.Load()

if marshaledResponse == nil {

marshaledResources := make([]*any.Any, len(r.Resources))
marshaledResources := make([]*anypb.Any, len(r.Resources))

for i, resource := range r.Resources {
maybeTtldResource, resourceType, err := r.maybeCreateTTLResource(resource)
Expand All @@ -212,7 +209,7 @@ func (r *RawResponse) GetDiscoveryResponse() (*discovery.DiscoveryResponse, erro
if err != nil {
return nil, err
}
marshaledResources[i] = &any.Any{
marshaledResources[i] = &anypb.Any{
TypeUrl: resourceType,
Value: marshaledResource,
}
Expand Down Expand Up @@ -251,7 +248,7 @@ func (r *RawDeltaResponse) GetDeltaDiscoveryResponse() (*discovery.DeltaDiscover
}
marshaledResources[i] = &discovery.Resource{
Name: name,
Resource: &any.Any{
Resource: &anypb.Any{
TypeUrl: r.DeltaRequest.TypeUrl,
Value: marshaledResource,
},
Expand Down Expand Up @@ -304,17 +301,17 @@ func (r *RawDeltaResponse) GetContext() context.Context {
return r.Ctx
}

var deltaResourceTypeURL = "type.googleapis.com/" + proto.MessageName(&discovery.Resource{})
var deltaResourceTypeURL = "type.googleapis.com/" + string(proto.MessageName(&discovery.Resource{}))

func (r *RawResponse) maybeCreateTTLResource(resource types.ResourceWithTTL) (types.Resource, string, error) {
if resource.TTL != nil {
wrappedResource := &discovery.Resource{
Name: GetResourceName(resource.Resource),
Ttl: ptypes.DurationProto(*resource.TTL),
Ttl: durationpb.New(*resource.TTL),
}

if !r.Heartbeat {
any, err := ptypes.MarshalAny(resource.Resource)
any, err := anypb.New(resource.Resource)
if err != nil {
return nil, "", err
}
Expand Down
19 changes: 10 additions & 9 deletions pkg/cache/v3/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package cache_test
import (
"testing"

"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"

route "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
Expand Down Expand Up @@ -36,18 +37,18 @@ func TestResponseGetDiscoveryResponse(t *testing.T) {
assert.Same(t, discoveryResponse, cachedResponse)

r := &route.RouteConfiguration{}
err = ptypes.UnmarshalAny(discoveryResponse.Resources[0], r)
err = anypb.UnmarshalTo(discoveryResponse.Resources[0], r, proto.UnmarshalOptions{})
assert.Nil(t, err)
assert.Equal(t, r.Name, resourceName)
}

func TestPassthroughResponseGetDiscoveryResponse(t *testing.T) {
routes := []types.Resource{&route.RouteConfiguration{Name: resourceName}}
rsrc, err := ptypes.MarshalAny(routes[0])
rsrc, err := anypb.New(routes[0])
assert.Nil(t, err)
dr := &discovery.DiscoveryResponse{
TypeUrl: resource.RouteType,
Resources: []*any.Any{rsrc},
Resources: []*anypb.Any{rsrc},
VersionInfo: "v",
}
resp := cache.PassthroughResponse{
Expand All @@ -61,7 +62,7 @@ func TestPassthroughResponseGetDiscoveryResponse(t *testing.T) {
assert.Equal(t, len(discoveryResponse.Resources), 1)

r := &route.RouteConfiguration{}
err = ptypes.UnmarshalAny(discoveryResponse.Resources[0], r)
err = anypb.UnmarshalTo(discoveryResponse.Resources[0], r, proto.UnmarshalOptions{})
assert.Nil(t, err)
assert.Equal(t, r.Name, resourceName)
assert.Equal(t, discoveryResponse, dr)
Expand All @@ -87,14 +88,14 @@ func TestHeartbeatResponseGetDiscoveryResponse(t *testing.T) {
assert.Same(t, discoveryResponse, cachedResponse)

r := &route.RouteConfiguration{}
err = ptypes.UnmarshalAny(discoveryResponse.Resources[0], r)
err = anypb.UnmarshalTo(discoveryResponse.Resources[0], r, proto.UnmarshalOptions{})
assert.Nil(t, err)
assert.Equal(t, r.Name, resourceName)
}

func isTTLResource(resource *any.Any) bool {
func isTTLResource(resource *anypb.Any) bool {
wrappedResource := &discovery.Resource{}
err := ptypes.UnmarshalAny(resource, wrappedResource)
err := protojson.Unmarshal(resource.Value, wrappedResource)
if err != nil {
return false
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/cache/v3/linear.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type LinearCache struct {
// together with its current version
// version and versionPrefix fields are ignored for delta watches, because we always generate the resource version.
deltaWatches map[int64]DeltaResponseWatch
// Continously incremented counter used to index delta watches.
// Continuously incremented counter used to index delta watches.
deltaWatchCount int64
// versionMap holds the current hash map of all resources in the cache.
// versionMap is only to be used with delta xDS.
Expand Down Expand Up @@ -154,7 +154,10 @@ func (cache *LinearCache) notifyAll(modified map[string]struct{}) {
}
cache.watchAll = make(watches)

cache.updateVersionMap(modified)
err := cache.updateVersionMap(modified)
if err != nil {
cache.log.Errorf("failed to update version map: %v", err)
}

for id, watch := range cache.deltaWatches {
res := cache.respondDelta(watch.Request, watch.Response, watch.StreamState)
Expand Down Expand Up @@ -362,7 +365,7 @@ func (cache *LinearCache) updateVersionMap(modified map[string]struct{}) error {
if _, ok := modified[name]; !ok {
continue
}
// hash our verison in here and build the version map
// hash our version in here and build the version map
marshaledResource, err := MarshalResource(r)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 996a28b

Please sign in to comment.