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

Init time logger for eosgrpc storage driver #4311

Merged
merged 3 commits into from
Nov 7, 2023
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
7 changes: 7 additions & 0 deletions changelog/unreleased/init-logger-eosgrpc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Init time logger for eosgrpc storage driver

Before the `eosgrpc` driver was using a custom logger.
Now that the reva logger is available at init time,
the driver will use this.

https://github.com/cs3org/reva/pull/4311
27 changes: 13 additions & 14 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import (
"github.com/cs3org/reva/pkg/eosclient"
erpc "github.com/cs3org/reva/pkg/eosclient/eosgrpc/eos_grpc"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/logger"
"github.com/cs3org/reva/pkg/storage/utils/acl"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand Down Expand Up @@ -138,16 +138,15 @@ type Client struct {
}

// Create and connect a grpc eos Client.
func newgrpc(ctx context.Context, opt *Options) (erpc.EosClient, error) {
log := appctx.GetLogger(ctx)
log.Info().Str("Setting up GRPC towards ", "'"+opt.GrpcURI+"'").Msg("")
func newgrpc(ctx context.Context, log *zerolog.Logger, opt *Options) (erpc.EosClient, error) {
log.Debug().Msgf("Setting up GRPC towards '%s'", opt.GrpcURI)

conn, err := grpc.Dial(opt.GrpcURI, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Warn().Str("Error connecting to ", "'"+opt.GrpcURI+"' ").Str("err", err.Error()).Msg("")
log.Warn().Err(err).Msgf("Error connecting to '%s'", opt.GrpcURI)
}

log.Debug().Str("Going to ping ", "'"+opt.GrpcURI+"' ").Msg("")
log.Debug().Msgf("Going to ping '%s'", opt.GrpcURI)
ecl := erpc.NewEosClient(conn)
// If we can't ping... just print warnings. In the case EOS is down, grpc will take care of
// connecting later
Expand All @@ -156,30 +155,30 @@ func newgrpc(ctx context.Context, opt *Options) (erpc.EosClient, error) {
prq.Message = []byte("hi this is a ping from reva")
prep, err := ecl.Ping(ctx, prq)
if err != nil {
log.Warn().Str("Could not ping to ", "'"+opt.GrpcURI+"' ").Str("err", err.Error()).Msg("")
log.Warn().Err(err).Msgf("Could not ping to '%s'", opt.GrpcURI)
}

if prep == nil {
log.Warn().Str("Could not ping to ", "'"+opt.GrpcURI+"' ").Str("nil response", "").Msg("")
log.Warn().Msgf("Could not ping to '%s': nil response", opt.GrpcURI)
}
log.Debug().Str("Ping to ", "'"+opt.GrpcURI+"' succeeded").Msg("")
log.Debug().Msgf("Ping to '%s' succeeded", opt.GrpcURI)

return ecl, nil
}

// New creates a new client with the given options.
func New(opt *Options, httpOpts *HTTPOptions) (*Client, error) {
tlog := logger.New().With().Int("pid", os.Getpid()).Logger()
tlog.Debug().Str("Creating new eosgrpc client. opt: ", "'"+fmt.Sprintf("%#v", opt)+"' ").Msg("")
func New(ctx context.Context, opt *Options, httpOpts *HTTPOptions) (*Client, error) {
log := appctx.GetLogger(ctx)

log.Debug().Interface("options", opt).Msgf("Creating new eosgrpc client")

opt.init()
httpcl, err := NewEOSHTTPClient(httpOpts)
if err != nil {
return nil, err
}

tctx := appctx.WithLogger(context.Background(), &tlog)
cl, err := newgrpc(tctx, opt)
cl, err := newgrpc(ctx, log, opt)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func NewEOSFS(ctx context.Context, c *Config) (storage.FS, error) {
ClientCAFiles: c.ClientCAFiles,
Authkey: c.HTTPSAuthkey,
}
eosClient, err = eosgrpc.New(eosClientOpts, eosHTTPOpts)
eosClient, err = eosgrpc.New(ctx, eosClientOpts, eosHTTPOpts)
} else {
eosClientOpts := &eosbinary.Options{
XrdcopyBinary: c.XrdcopyBinary,
Expand Down