Skip to content

Commit

Permalink
log PreparePathsForExport
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Pleshakov committed Nov 8, 2024
1 parent c9e554e commit e96b2bd
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 15 deletions.
23 changes: 15 additions & 8 deletions cmd/ydbcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"flag"
"fmt"
"github.com/ydb-platform/ydb-go-sdk/v3/log"
"os"
"os/signal"
"sync"
Expand Down Expand Up @@ -43,9 +44,21 @@ func main() {

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

configInstance, err := config.InitConfig(ctx, confPath)

if err != nil {
log.Error(fmt.Errorf("unable to initialize config: %w", err))
os.Exit(1)
}

var wg sync.WaitGroup

logger := xlog.SetupLogging(true)
logger, err := xlog.SetupLogging(configInstance.GRPCServer.LogLevel)
if err != nil {
log.Error(err)
os.Exit(1)
}
xlog.SetInternalLogger(logger)
defer func() {
err := logger.Sync()
Expand All @@ -54,17 +67,11 @@ func main() {
}
}()

_, err := maxprocs.Set(maxprocs.Logger(func(f string, p ...interface{}) { xlog.Info(ctx, fmt.Sprintf(f, p...)) }))
_, err = maxprocs.Set(maxprocs.Logger(func(f string, p ...interface{}) { xlog.Info(ctx, fmt.Sprintf(f, p...)) }))
if err != nil {
xlog.Error(ctx, "Can't set maxprocs", zap.Error(err))
}

configInstance, err := config.InitConfig(ctx, confPath)

if err != nil {
xlog.Error(ctx, "Unable to initialize config", zap.Error(err))
os.Exit(1)
}
if confStr, err := configInstance.ToString(); err == nil {
xlog.Debug(
ctx, "Use configuration file",
Expand Down
14 changes: 12 additions & 2 deletions internal/backup_operations/make_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,22 @@ func MakeBackup(

pathsForExport, err := clientConn.PreparePathsForExport(ctx, client, sourcePaths, req.SourcePathsToExclude)
if err != nil {
xlog.Error(ctx, "error preparing paths for export", zap.Error(err))
xlog.Error(
ctx,
"error preparing paths for export",
zap.Strings("sourcePaths", req.SourcePaths),
zap.String("scheduleID", *req.ScheduleID),
zap.Error(err),
)
return nil, nil, status.Errorf(codes.Unknown, "error preparing paths for export, dsn %s", dsn)
}

if len(pathsForExport) == 0 {
xlog.Error(ctx, "empty list of paths for export")
xlog.Error(
ctx,
"empty list of paths for export",
zap.String("scheduleID", *req.ScheduleID),
)
return nil, nil, status.Error(codes.FailedPrecondition, "empty list of paths for export")
}

Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type GRPCServerConfig struct {
BindPort uint16 `yaml:"bind_port" default:"2135"`
TLSCertificatePath string `yaml:"tls_certificate_path"`
TLSKeyPath string `yaml:"tls_key_path"`
LogLevel string `yaml:"log_level"`
}

type MetricsServerConfig struct {
Expand Down
7 changes: 7 additions & 0 deletions internal/connectors/client/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ func listDirectory(ctx context.Context, clientDb *ydb.Driver, initialPath string
func (d *ClientYdbConnector) PreparePathsForExport(
ctx context.Context, clientDb *ydb.Driver, sourcePaths []string, sourcePathsToExclude []string,
) ([]string, error) {
xlog.Debug(
ctx,
"Preparing paths for export",
zap.String("database_name", clientDb.Name()),
zap.Strings("paths", sourcePaths),
zap.Strings("paths_to_exclude", sourcePathsToExclude),
)
if clientDb == nil {
return nil, fmt.Errorf("unititialized client db driver")
}
Expand Down
11 changes: 6 additions & 5 deletions internal/util/xlog/init.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package xlog

import (
"fmt"
"log"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func SetupLogging(verbose bool) *zap.Logger {
var level zapcore.Level = zapcore.WarnLevel
if verbose {
level = zapcore.DebugLevel
func SetupLogging(logLevel string) (*zap.Logger, error) {
level, err := zapcore.ParseLevel(logLevel)
if err != nil {
return nil, fmt.Errorf("parse log level error: %w", err)
}
cfg := zap.NewProductionConfig()
cfg.Level.SetLevel(level)
Expand All @@ -20,5 +21,5 @@ func SetupLogging(verbose bool) *zap.Logger {
if err != nil {
log.Fatalln("Failed to create logger:", err)
}
return l
return l, nil
}
1 change: 1 addition & 0 deletions local_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ s3:

grpc_server:
bind_port: 50051
log_level: INFO

0 comments on commit e96b2bd

Please sign in to comment.