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

Add golangci-lint linters to the executor #3453

Merged
merged 4 commits into from
Aug 3, 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
2 changes: 2 additions & 0 deletions executor/.errcheck_excludes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fmt.Fprintln
fmt.Fprint
52 changes: 52 additions & 0 deletions executor/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# options for analysis running
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 5m

# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs: vendor

# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
format: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true

# print linter name in the end of issue text, default is true
print-linter-name: true

linters:
disable-all: true
enable:
# Sorted alphabetically.
- errcheck
- exportloopref
- goimports
- gosimple
- govet
- misspell
- staticcheck
- structcheck
- typecheck
- varcheck

linters-settings:
errcheck:
exclude: ./.errcheck_excludes.txt
goconst:
min-occurrences: 5

issues:
exclude-rules:
- linters:
- staticcheck
text: "SA1019:" # Delete this exclusion once https://github.com/SeldonIO/seldon-core/issues/3452 is fixed.
3 changes: 2 additions & 1 deletion executor/api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package client
import (
"context"
"fmt"
"io"

"github.com/seldonio/seldon-core/executor/api/payload"
"golang.org/x/xerrors"
"io"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions executor/api/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package grpc

import (
"context"
"strconv"
"time"

"github.com/go-logr/logr"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
Expand All @@ -11,8 +14,6 @@ import (
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"strconv"
"time"
)

func AddMetadataToOutgoingGrpcContext(ctx context.Context, meta map[string][]string) context.Context {
Expand Down
7 changes: 4 additions & 3 deletions executor/api/grpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package grpc

import (
"context"
"reflect"
"testing"

"github.com/golang/protobuf/jsonpb"
proto2 "github.com/golang/protobuf/proto"
. "github.com/onsi/gomega"
"github.com/seldonio/seldon-core/executor/api/grpc/seldon/proto"
"github.com/seldonio/seldon-core/executor/api/payload"
"google.golang.org/grpc/metadata"
"reflect"
"testing"
)

func TestAddPuidToCtx(t *testing.T) {
Expand All @@ -29,7 +30,7 @@ func TestAddPuidToCtx(t *testing.T) {
func getProto(messageType string, messageBytes []byte) proto2.Message {
pbtype := proto2.MessageType(messageType)
msg := reflect.New(pbtype.Elem()).Interface().(proto2.Message)
proto2.Unmarshal(messageBytes, msg)
_ = proto2.Unmarshal(messageBytes, msg)
return msg
}

Expand Down
7 changes: 4 additions & 3 deletions executor/api/grpc/kfserving/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package kfserving
import (
"context"
"fmt"
"io"
"math"

"github.com/go-logr/logr"
"github.com/pkg/errors"
"github.com/seldonio/seldon-core/executor/api/client"
Expand All @@ -11,9 +14,7 @@ import (
"github.com/seldonio/seldon-core/executor/api/payload"
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1"
"google.golang.org/grpc"
"io"
"math"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

type KFServingGrpcClient struct {
Expand Down
17 changes: 9 additions & 8 deletions executor/api/grpc/kfserving/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package kfserving

import (
"context"
"net/url"

"github.com/go-logr/logr"
"github.com/seldonio/seldon-core/executor/api/client"
"github.com/seldonio/seldon-core/executor/api/grpc"
Expand All @@ -11,8 +13,7 @@ import (
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1"
protoGrpc "google.golang.org/grpc"
protoGrpcMetadata "google.golang.org/grpc/metadata"
"net/url"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

type GrpcKFServingServer struct {
Expand Down Expand Up @@ -44,8 +45,8 @@ func (g GrpcKFServingServer) ServerReady(ctx context.Context, request *inference
func (g GrpcKFServingServer) ModelReady(ctx context.Context, request *inference.ModelReadyRequest) (*inference.ModelReadyResponse, error) {
md := grpc.CollectMetadata(ctx)
header := protoGrpcMetadata.Pairs(payload.SeldonPUIDHeader, md.Get(payload.SeldonPUIDHeader)[0])
protoGrpc.SetHeader(ctx, header)
ctx = context.WithValue(ctx, payload.SeldonPUIDHeader, md.Get(payload.SeldonPUIDHeader)[0])
_ = protoGrpc.SetHeader(ctx, header)
ctx = context.WithValue(ctx, payload.SeldonPUIDHeaderIdentifier(payload.SeldonPUIDHeader), md.Get(payload.SeldonPUIDHeader)[0])
seldonPredictorProcess := predictor.NewPredictorProcess(ctx, g.Client, logf.Log.WithName("infer"), g.ServerUrl, g.Namespace, md, request.GetName())
reqPayload := payload.ProtoPayload{Msg: request}
resPayload, err := seldonPredictorProcess.Status(&g.predictor.Graph, request.Name, &reqPayload)
Expand All @@ -62,8 +63,8 @@ func (g GrpcKFServingServer) ServerMetadata(ctx context.Context, request *infere
func (g GrpcKFServingServer) ModelMetadata(ctx context.Context, request *inference.ModelMetadataRequest) (*inference.ModelMetadataResponse, error) {
md := grpc.CollectMetadata(ctx)
header := protoGrpcMetadata.Pairs(payload.SeldonPUIDHeader, md.Get(payload.SeldonPUIDHeader)[0])
protoGrpc.SetHeader(ctx, header)
ctx = context.WithValue(ctx, payload.SeldonPUIDHeader, md.Get(payload.SeldonPUIDHeader)[0])
_ = protoGrpc.SetHeader(ctx, header)
ctx = context.WithValue(ctx, payload.SeldonPUIDHeaderIdentifier(payload.SeldonPUIDHeader), md.Get(payload.SeldonPUIDHeader)[0])
seldonPredictorProcess := predictor.NewPredictorProcess(ctx, g.Client, logf.Log.WithName("infer"), g.ServerUrl, g.Namespace, md, request.GetName())
reqPayload := payload.ProtoPayload{Msg: request}
resPayload, err := seldonPredictorProcess.Metadata(&g.predictor.Graph, request.Name, &reqPayload)
Expand All @@ -76,8 +77,8 @@ func (g GrpcKFServingServer) ModelMetadata(ctx context.Context, request *inferen
func (g GrpcKFServingServer) ModelInfer(ctx context.Context, request *inference.ModelInferRequest) (*inference.ModelInferResponse, error) {
md := grpc.CollectMetadata(ctx)
header := protoGrpcMetadata.Pairs(payload.SeldonPUIDHeader, md.Get(payload.SeldonPUIDHeader)[0])
protoGrpc.SetHeader(ctx, header)
ctx = context.WithValue(ctx, payload.SeldonPUIDHeader, md.Get(payload.SeldonPUIDHeader)[0])
_ = protoGrpc.SetHeader(ctx, header)
ctx = context.WithValue(ctx, payload.SeldonPUIDHeaderIdentifier(payload.SeldonPUIDHeader), md.Get(payload.SeldonPUIDHeader)[0])
seldonPredictorProcess := predictor.NewPredictorProcess(ctx, g.Client, logf.Log.WithName("infer"), g.ServerUrl, g.Namespace, md, request.GetModelName())
reqPayload := payload.ProtoPayload{Msg: request}
resPayload, err := seldonPredictorProcess.Predict(&g.predictor.Graph, &reqPayload)
Expand Down
14 changes: 8 additions & 6 deletions executor/api/grpc/seldon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ package seldon
import (
"context"
"fmt"
"math/rand"
"sync"

"github.com/go-logr/logr"
"github.com/pkg/errors"
"github.com/seldonio/seldon-core/executor/api/client"
"math/rand"
"sync"

"io"
"math"
"net/http"

"github.com/golang/protobuf/ptypes/empty"
grpc2 "github.com/seldonio/seldon-core/executor/api/grpc"
Expand All @@ -16,10 +21,7 @@ import (
"github.com/seldonio/seldon-core/executor/api/util"
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1"
"google.golang.org/grpc"
"io"
"math"
"net/http"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

// TODO: make this configurable
Expand Down
11 changes: 7 additions & 4 deletions executor/api/grpc/seldon/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"encoding/json"
"fmt"
"net"
"testing"

"github.com/golang/protobuf/jsonpb"
. "github.com/onsi/gomega"
"github.com/seldonio/seldon-core/executor/api/grpc"
Expand All @@ -12,9 +15,7 @@ import (
"github.com/seldonio/seldon-core/executor/api/payload"
"github.com/seldonio/seldon-core/executor/k8s"
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1"
"net"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"testing"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

var testProtoModelMetadata = proto.SeldonModelMetadata{
Expand Down Expand Up @@ -64,7 +65,9 @@ func createTestGrpcServer(g *GomegaWithT, annotations map[string]string) (*v1.Pr
testSeldonGrpcServer := test.NewSeldonTestServer(1, &testProtoModelMetadata)
proto.RegisterModelServer(grpcServer, testSeldonGrpcServer)

go grpcServer.Serve(lis)
go func() {
_ = grpcServer.Serve(lis)
}()
stopFunc := grpcServer.Stop

return &p, host, port, stopFunc
Expand Down
11 changes: 6 additions & 5 deletions executor/api/grpc/seldon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package seldon

import (
"context"
"net/url"

"github.com/go-logr/logr"
empty "github.com/golang/protobuf/ptypes/empty"
"github.com/seldonio/seldon-core/executor/api/client"
Expand All @@ -12,8 +14,7 @@ import (
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1"
protoGrpc "google.golang.org/grpc"
protoGrpcMetadata "google.golang.org/grpc/metadata"
"net/url"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

type GrpcSeldonServer struct {
Expand All @@ -37,8 +38,8 @@ func NewGrpcSeldonServer(predictor *v1.PredictorSpec, client client.SeldonApiCli
func (g GrpcSeldonServer) Predict(ctx context.Context, req *proto.SeldonMessage) (*proto.SeldonMessage, error) {
md := grpc.CollectMetadata(ctx)
header := protoGrpcMetadata.Pairs(payload.SeldonPUIDHeader, md.Get(payload.SeldonPUIDHeader)[0])
protoGrpc.SetHeader(ctx, header)
ctx = context.WithValue(ctx, payload.SeldonPUIDHeader, md.Get(payload.SeldonPUIDHeader)[0])
_ = protoGrpc.SetHeader(ctx, header)
ctx = context.WithValue(ctx, payload.SeldonPUIDHeaderIdentifier(payload.SeldonPUIDHeader), md.Get(payload.SeldonPUIDHeader)[0])
seldonPredictorProcess := predictor.NewPredictorProcess(ctx, g.Client, logf.Log.WithName("SeldonMessageRestClient"), g.ServerUrl, g.Namespace, md, "")
reqPayload := payload.ProtoPayload{Msg: req}
resPayload, err := seldonPredictorProcess.Predict(&g.predictor.Graph, &reqPayload)
Expand All @@ -52,7 +53,7 @@ func (g GrpcSeldonServer) Predict(ctx context.Context, req *proto.SeldonMessage)
func (g GrpcSeldonServer) SendFeedback(ctx context.Context, req *proto.Feedback) (*proto.SeldonMessage, error) {
md := grpc.CollectMetadata(ctx)
header := protoGrpcMetadata.Pairs(payload.SeldonPUIDHeader, md.Get(payload.SeldonPUIDHeader)[0])
protoGrpc.SetHeader(ctx, header)
_ = protoGrpc.SetHeader(ctx, header)
seldonPredictorProcess := predictor.NewPredictorProcess(ctx, g.Client, logf.Log.WithName("SeldonMessageRestClient"), g.ServerUrl, g.Namespace, md, "")
reqPayload := payload.ProtoPayload{Msg: req}
resPayload, err := seldonPredictorProcess.Feedback(&g.predictor.Graph, &reqPayload)
Expand Down
7 changes: 3 additions & 4 deletions executor/api/grpc/seldon/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ package seldon

import (
"context"
"net/url"
"testing"

"github.com/golang/protobuf/jsonpb"
empty "github.com/golang/protobuf/ptypes/empty"
. "github.com/onsi/gomega"
"github.com/seldonio/seldon-core/executor/api/grpc/seldon/proto"
"github.com/seldonio/seldon-core/executor/api/payload"
"github.com/seldonio/seldon-core/executor/api/test"
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1"
"net/url"
"testing"
)

const testSeldonPuid = "1"

func TestPredict(t *testing.T) {
t.Logf("Started")
g := NewGomegaWithT(t)
Expand Down
5 changes: 3 additions & 2 deletions executor/api/grpc/seldon/test/test_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package test

import (
"context"
"time"

"github.com/go-logr/logr"
"github.com/golang/protobuf/ptypes/empty"
"github.com/seldonio/seldon-core/executor/api/grpc/seldon/proto"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"time"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

type GrpcSeldonTestServer struct {
Expand Down
7 changes: 4 additions & 3 deletions executor/api/grpc/tensorflow/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package tensorflow
import (
"context"
"fmt"
"io"
"math"

"github.com/go-logr/logr"
"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
Expand All @@ -14,9 +17,7 @@ import (
"google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
"io"
"math"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

type TensorflowGrpcClient struct {
Expand Down
4 changes: 2 additions & 2 deletions executor/api/grpc/tensorflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/seldonio/seldon-core/executor/predictor"
"github.com/seldonio/seldon-core/executor/proto/tensorflow/serving"
v1 "github.com/seldonio/seldon-core/operator/apis/machinelearning.seldon.io/v1"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

type GrpcTensorflowServer struct {
Expand All @@ -36,7 +36,7 @@ func NewGrpcTensorflowServer(predictor *v1.PredictorSpec, client client.SeldonAp

func (g *GrpcTensorflowServer) execute(ctx context.Context, req proto.Message, method string, modelName string) (payload.SeldonPayload, error) {
md := grpc.CollectMetadata(ctx)
ctx = context.WithValue(ctx, payload.SeldonPUIDHeader, md.Get(payload.SeldonPUIDHeader)[0])
ctx = context.WithValue(ctx, payload.SeldonPUIDHeaderIdentifier(payload.SeldonPUIDHeader), md.Get(payload.SeldonPUIDHeader)[0])
seldonPredictorProcess := predictor.NewPredictorProcess(ctx, g.Client, logf.Log.WithName(method), g.ServerUrl, g.Namespace, md, modelName)
reqPayload := payload.ProtoPayload{Msg: req}
return seldonPredictorProcess.Predict(&g.predictor.Graph, &reqPayload)
Expand Down
9 changes: 5 additions & 4 deletions executor/api/grpc/tensorflow/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package tensorflow

import (
"context"
"io"
"net/http"
"net/url"
"testing"

"github.com/golang/protobuf/jsonpb"
. "github.com/onsi/gomega"
"github.com/seldonio/seldon-core/executor/api/client"
Expand All @@ -12,10 +17,6 @@ import (
codes "google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
status "google.golang.org/grpc/status"
"io"
"net/http"
"net/url"
"testing"
)

const (
Expand Down
Loading