Skip to content

Commit

Permalink
Fix some lint issues
Browse files Browse the repository at this point in the history
Summary:
grpc deprecated `WithInsecure` and the linter complains about it
So switch to the new way of doing things.

Test Plan: arc lint and run all tests.

Reviewers: michelle, zasgar

Reviewed By: michelle

Signed-off-by: Vihang Mehta <vihang@pixielabs.ai>

Differential Revision: https://phab.corp.pixielabs.ai/D11535

GitOrigin-RevId: 0eb1937
  • Loading branch information
vihangm authored and copybaranaut committed Jun 7, 2022
1 parent d520d22 commit cd7cc7f
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test-tsan: ## Run all the tests, with thread sanitizer.

.PHONY: go-mod-tidy
go-mod-tidy: ## Ensure that go are cleaned up.
go mod tidy -compat=1.17
go mod tidy -compat=1.18

.PHONY: go-mod-ensure
go-mod-ensure: ## Ensure that go dependencies exist.
Expand Down
2 changes: 1 addition & 1 deletion go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1481,10 +1481,10 @@ def pl_go_dependencies():
)
go_repository(
name = "com_github_gogo_protobuf",
build_file_proto_mode = "disable",
importpath = "github.com/gogo/protobuf",
sum = "h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=",
version = "v1.3.2",
build_file_proto_mode = "disable",
)

go_repository(
Expand Down
1 change: 1 addition & 0 deletions src/cloud/api/ptproxy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ go_test(
"@com_github_stretchr_testify//require",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//credentials/insecure",
"@org_golang_google_grpc//metadata",
"@org_golang_google_grpc//status",
"@org_golang_google_grpc//test/bufconn",
Expand Down
3 changes: 2 additions & 1 deletion src/cloud/api/ptproxy/vizier_pt_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/grpc/test/bufconn"
Expand Down Expand Up @@ -78,7 +79,7 @@ func createTestState(t *testing.T) (*testState, func(t *testing.T)) {
eg.Go(func() error { return s.Serve(lis) })

ctx := context.Background()
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithInsecure())
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial bufnet: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions src/cloud/vzconn/bridge/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ go_test(
"@com_github_stretchr_testify//require",
"@go_googleapis//google/rpc:code_go_proto",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials/insecure",
"@org_golang_google_grpc//metadata",
"@org_golang_google_grpc//status",
"@org_golang_google_grpc//test/bufconn",
Expand Down
7 changes: 4 additions & 3 deletions src/cloud/vzconn/bridge/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"golang.org/x/sync/errgroup"
"google.golang.org/genproto/googleapis/rpc/code"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/grpc/test/bufconn"
Expand Down Expand Up @@ -82,7 +83,7 @@ func createTestState(t *testing.T, ctrl *gomock.Controller) (*testState, func(t
eg.Go(func() error { return s.Serve(lis) })

ctx := context.Background()
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithInsecure())
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial bufnet: %v", err)
}
Expand Down Expand Up @@ -144,11 +145,11 @@ func grpcReader(stream vzconnpb.VZConnService_NATSBridgeClient) chan readMsgWrap
}

func convertToAny(msg proto.Message) *types.Any {
any, err := types.MarshalAny(msg)
anyMsg, err := types.MarshalAny(msg)
if err != nil {
panic(err)
}
return any
return anyMsg
}

func TestNATSGRPCBridgeHandshakeTest_CorrectRegistration(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions src/shared/services/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ go_library(
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//credentials",
"@org_golang_google_grpc//credentials/insecure",
"@org_golang_google_grpc//encoding/gzip",
"@org_golang_google_grpc//status",
],
Expand Down
1 change: 1 addition & 0 deletions src/shared/services/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ go_test(
"@com_github_stretchr_testify//require",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//credentials/insecure",
"@org_golang_google_grpc//metadata",
"@org_golang_google_grpc//status",
"@org_golang_google_grpc//test/bufconn",
Expand Down
7 changes: 4 additions & 3 deletions src/shared/services/server/grpc_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/grpc/test/bufconn"
Expand Down Expand Up @@ -110,7 +111,7 @@ func createDialer(lis *bufconn.Listener) func(ctx context.Context, url string) (

func makeTestRequest(ctx context.Context, t *testing.T, lis *bufconn.Listener) (*ping.PingReply, error) {
grpc.WithContextDialer(createDialer(lis))
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithInsecure())
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("did not connect: %v", err)
}
Expand All @@ -120,7 +121,7 @@ func makeTestRequest(ctx context.Context, t *testing.T, lis *bufconn.Listener) (
}

func makeTestClientStreamRequest(ctx context.Context, t *testing.T, lis *bufconn.Listener) (*ping.PingReply, error) {
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithInsecure())
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("did not connect: %v", err)
}
Expand All @@ -141,7 +142,7 @@ func makeTestClientStreamRequest(ctx context.Context, t *testing.T, lis *bufconn
}

func makeTestServerStreamRequest(ctx context.Context, t *testing.T, lis *bufconn.Listener) (*ping.PingReply, error) {
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithInsecure())
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("did not connect: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions src/shared/services/service_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/encoding/gzip"

version "px.dev/pixie/src/shared/goversion"
Expand Down Expand Up @@ -144,7 +145,7 @@ func GetGRPCClientDialOpts() ([]grpc.DialOption, error) {
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name)))

if viper.GetBool("disable_ssl") {
dialOpts = append(dialOpts, grpc.WithInsecure())
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
return dialOpts, nil
}

Expand Down Expand Up @@ -193,7 +194,7 @@ func GetGRPCClientDialOptsServerSideTLS(isInternal bool) ([]grpc.DialOption, err
dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name)))

if viper.GetBool("disable_ssl") {
dialOpts = append(dialOpts, grpc.WithInsecure())
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
return dialOpts, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/encoding/gzip"

// ___module___ will get replaced by the module name for the current binary and
Expand All @@ -47,7 +48,7 @@ func getDialOpts(compression, https bool) []grpc.DialOption {
creds := credentials.NewTLS(tlsConfig)
dialOpts = append(dialOpts, grpc.WithTransportCredentials(creds))
} else {
dialOpts = append(dialOpts, grpc.WithInsecure())
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

return dialOpts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ go_library(
"//src/stirling/testing/demo_apps/hipster_shop/proto:demo_pl_go_proto",
"@com_github_sirupsen_logrus//:logrus",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials/insecure",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import (

log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

pb "px.dev/pixie/src/stirling/testing/demo_apps/hipster_shop/proto"
)

func main() {
ctx := context.Background()
addr := "localhost:3550"
conn, err := grpc.Dial(addr, grpc.WithInsecure())
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return
}
Expand Down
1 change: 1 addition & 0 deletions src/vizier/services/cloud_connector/bridge/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ go_test(
"@com_github_stretchr_testify//require",
"@io_k8s_api//batch/v1:batch",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials/insecure",
"@org_golang_google_grpc//test/bufconn",
"@org_golang_x_sync//errgroup",
],
Expand Down
3 changes: 2 additions & 1 deletion src/vizier/services/cloud_connector/bridge/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/test/bufconn"
batchv1 "k8s.io/api/batch/v1"

Expand Down Expand Up @@ -266,7 +267,7 @@ func makeTestState(t *testing.T) (*testState, func(t *testing.T)) {
eg.Go(func() error { return s.Serve(lis) })

ctx := context.Background()
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithInsecure())
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Got an error during GRPC setup: %+v", err)
}
Expand Down
1 change: 1 addition & 0 deletions src/vizier/services/metadata/controllers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ go_test(
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//credentials/insecure",
"@org_golang_google_grpc//metadata",
"@org_golang_google_grpc//test/bufconn",
"@org_golang_x_sync//errgroup",
Expand Down
3 changes: 2 additions & 1 deletion src/vizier/services/metadata/controllers/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
grpc_metadata "google.golang.org/grpc/metadata"
"google.golang.org/grpc/test/bufconn"

Expand Down Expand Up @@ -920,7 +921,7 @@ func TestGetAgentUpdates(t *testing.T) {
}()

ctx := context.Background()
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithInsecure())
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("Failed to dial bufnet: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions src/vizier/services/query_broker/ptproxy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ go_test(
"@com_github_stretchr_testify//require",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//credentials/insecure",
"@org_golang_google_grpc//test/bufconn",
"@org_golang_x_sync//errgroup",
],
Expand Down
3 changes: 2 additions & 1 deletion src/vizier/services/query_broker/ptproxy/pt_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/test/bufconn"

"px.dev/pixie/src/api/proto/vizierpb"
Expand Down Expand Up @@ -110,7 +111,7 @@ func createTestState(t *testing.T) (*testState, func(t *testing.T)) {
eg.Go(func() error { return s.Serve(lis) })

ctx := context.Background()
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithInsecure())
conn, err := grpc.DialContext(ctx, "bufnet", grpc.WithContextDialer(createDialer(lis)), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
natsCleanup()
t.Fatalf("Failed to dial bufnet: %v", err)
Expand Down

0 comments on commit cd7cc7f

Please sign in to comment.