Merge pull request #4765 from wkloucek/search-request-timeout
increase search client request timeouts
This commit is contained in:
4 files changed
+76
-28
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user