From 80d90d51c41ccf99e13b3ee3d4b86d7061b8ac05 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Mon, 10 Oct 2022 08:36:14 +0200 Subject: [PATCH] increase search client request timeouts --- ocis-pkg/service/grpc/client.go | 72 +++++++++++++++++++++++ ocis-pkg/service/grpc/service.go | 26 -------- services/search/pkg/command/index.go | 3 +- services/webdav/pkg/service/v0/service.go | 3 +- 4 files changed, 76 insertions(+), 28 deletions(-) create mode 100644 ocis-pkg/service/grpc/client.go diff --git a/ocis-pkg/service/grpc/client.go b/ocis-pkg/service/grpc/client.go new file mode 100644 index 00000000000..eb31ba63e39 --- /dev/null +++ b/ocis-pkg/service/grpc/client.go @@ -0,0 +1,72 @@ +package grpc + +import ( + "sync" + "time" + + mgrpcc "github.com/go-micro/plugins/v4/client/grpc" + mbreaker "github.com/go-micro/plugins/v4/wrapper/breaker/gobreaker" + "github.com/owncloud/ocis/v2/ocis-pkg/registry" + "go-micro.dev/v4/client" +) + +// DefaultClient is a custom oCIS grpc configured client. +var ( + defaultClient client.Client + once sync.Once +) + +// DefaultClient returns the default grpc client. +func DefaultClient() client.Client { + return getDefaultGrpcClient() +} + +func getDefaultGrpcClient() client.Client { + once.Do(func() { + reg := registry.GetRegistry() + + defaultClient = mgrpcc.NewClient( + client.Registry(reg), + client.Wrap(mbreaker.NewClientWrapper()), + ) + }) + return defaultClient +} + +// Client returns a configurable client. +func Client(opts ...ClientOption) client.Client { + copts := newClientOptions(opts...) + reg := registry.GetRegistry() + + return mgrpcc.NewClient( + client.Registry(reg), + client.Wrap(mbreaker.NewClientWrapper()), + client.RequestTimeout(copts.RequestTimeout), + ) +} + +// ClientOption defines a single client option function. +type ClientOption func(o *ClientOptions) + +// ClientOptions defines the available options for this package. +type ClientOptions struct { + RequestTimeout time.Duration +} + +// newClientOptions initializes the available client options. +func newClientOptions(opts ...ClientOption) ClientOptions { + opt := ClientOptions{} + + for _, o := range opts { + o(&opt) + } + + return opt +} + +// RequestTimeout provides a function to set the request timeout option. +func RequestTimeout(d time.Duration) ClientOption { + return func(o *ClientOptions) { + o.RequestTimeout = d + } +} diff --git a/ocis-pkg/service/grpc/service.go b/ocis-pkg/service/grpc/service.go index 458841ad23e..20f02374f25 100644 --- a/ocis-pkg/service/grpc/service.go +++ b/ocis-pkg/service/grpc/service.go @@ -2,41 +2,15 @@ package grpc import ( "strings" - "sync" "time" - mgrpcc "github.com/go-micro/plugins/v4/client/grpc" mgrpcs "github.com/go-micro/plugins/v4/server/grpc" - mbreaker "github.com/go-micro/plugins/v4/wrapper/breaker/gobreaker" "github.com/go-micro/plugins/v4/wrapper/monitoring/prometheus" "github.com/go-micro/plugins/v4/wrapper/trace/opencensus" "github.com/owncloud/ocis/v2/ocis-pkg/registry" "go-micro.dev/v4" - "go-micro.dev/v4/client" ) -// DefaultClient is a custom oCIS grpc configured client. -var ( - defaultClient client.Client - once sync.Once -) - -func DefaultClient() client.Client { - return getDefaultGrpcClient() -} - -func getDefaultGrpcClient() client.Client { - once.Do(func() { - reg := registry.GetRegistry() - - defaultClient = mgrpcc.NewClient( - client.Registry(reg), - client.Wrap(mbreaker.NewClientWrapper()), - ) - }) - return defaultClient -} - // Service simply wraps the go-micro grpc service. type Service struct { micro.Service diff --git a/services/search/pkg/command/index.go b/services/search/pkg/command/index.go index ecb44fa7dcf..2cc4dbd6647 100644 --- a/services/search/pkg/command/index.go +++ b/services/search/pkg/command/index.go @@ -3,6 +3,7 @@ package command import ( "context" "fmt" + "time" "github.com/urfave/cli/v2" @@ -37,7 +38,7 @@ func Index(cfg *config.Config) *cli.Command { return parser.ParseConfig(cfg) }, Action: func(c *cli.Context) error { - client := searchsvc.NewSearchProviderService("com.owncloud.api.search", grpc.DefaultClient()) + client := searchsvc.NewSearchProviderService("com.owncloud.api.search", grpc.Client(grpc.RequestTimeout(60*time.Second))) _, err := client.IndexSpace(context.Background(), &searchsvc.IndexSpaceRequest{ SpaceId: c.String("space"), UserId: c.String("user"), diff --git a/services/webdav/pkg/service/v0/service.go b/services/webdav/pkg/service/v0/service.go index 13e74c90648..64c6b03f5ea 100644 --- a/services/webdav/pkg/service/v0/service.go +++ b/services/webdav/pkg/service/v0/service.go @@ -9,6 +9,7 @@ import ( "path" "path/filepath" "strings" + "time" gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1" userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" @@ -69,7 +70,7 @@ func NewService(opts ...Option) (Service, error) { config: conf, log: options.Logger, mux: m, - searchClient: searchsvc.NewSearchProviderService("com.owncloud.api.search", grpc.DefaultClient()), + searchClient: searchsvc.NewSearchProviderService("com.owncloud.api.search", grpc.Client(grpc.RequestTimeout(60*time.Second))), thumbnailsClient: thumbnailssvc.NewThumbnailService("com.owncloud.api.thumbnails", grpc.DefaultClient()), revaClient: gwc, }