Skip to content

Commit

Permalink
Init time logger for eosgrpc storage driver (cs3org#4311)
Browse files Browse the repository at this point in the history
* init time logger for eosgrpc storage driver

* add changelog

* rewritten init time logs
  • Loading branch information
gmgigi96 authored Nov 7, 2023
1 parent 4106052 commit afe9144
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
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

0 comments on commit afe9144

Please sign in to comment.