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

Add logger to every task #203

Merged
merged 1 commit into from
Mar 31, 2022
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
3 changes: 3 additions & 0 deletions ci/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ port=$2
export GOPATH=/usr/local/nebula/
export GO111MODULE=on

# build git
apk add git

# build nebula-console
mkdir -p nebulaconsolebuild
cd nebulaconsolebuild
Expand Down
11 changes: 7 additions & 4 deletions cmd/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/vesoft-inc/nebula-importer/pkg/cmd"
"github.com/vesoft-inc/nebula-importer/pkg/config"
"github.com/vesoft-inc/nebula-importer/pkg/errors"
"github.com/vesoft-inc/nebula-importer/pkg/logger"
"github.com/vesoft-inc/nebula-importer/pkg/web"
)

Expand All @@ -28,12 +29,14 @@ func main() {
log.Println("--- START OF NEBULA IMPORTER ---")

flag.Parse()

runnerLogger := logger.NewRunnerLogger("")
if port != nil && *port > 0 && callback != nil && *callback != "" {

// Start http server
svr := &web.WebServer{
Port: *port,
Callback: *callback,
Port: *port,
Callback: *callback,
RunnerLogger: runnerLogger,
}

if err := svr.Start(); err != nil {
Expand All @@ -44,7 +47,7 @@ func main() {
panic("please configure yaml file")
}

conf, err := config.Parse(*configuration)
conf, err := config.Parse(*configuration, runnerLogger)
if err != nil {
e := err.(errors.ImporterError)
log.Println(e.ErrMsg.Error())
Expand Down
3 changes: 2 additions & 1 deletion pkg/base/tools_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package base

import (
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

func TestFileExists(t *testing.T) {
Expand Down
15 changes: 9 additions & 6 deletions pkg/client/clientmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import (
)

type NebulaClientMgr struct {
config *config.NebulaClientSettings
pool *ClientPool
config *config.NebulaClientSettings
pool *ClientPool
runnerLogger *logger.RunnerLogger
}

func NewNebulaClientMgr(settings *config.NebulaClientSettings, statsCh chan<- base.Stats) (*NebulaClientMgr, error) {
func NewNebulaClientMgr(settings *config.NebulaClientSettings, statsCh chan<- base.Stats,
runnerLogger *logger.RunnerLogger) (*NebulaClientMgr, error) {
mgr := NebulaClientMgr{
config: settings,
config: settings,
runnerLogger: runnerLogger,
}

if pool, err := NewClientPool(settings, statsCh); err != nil {
if pool, err := NewClientPool(settings, statsCh, runnerLogger); err != nil {
return nil, err
} else {
if err := pool.Init(); err != nil {
Expand All @@ -25,7 +28,7 @@ func NewNebulaClientMgr(settings *config.NebulaClientSettings, statsCh chan<- ba
mgr.pool = pool
}

logger.Infof("Create %d Nebula Graph clients", mgr.GetNumConnections())
mgr.runnerLogger.Infof("Create %d Nebula Graph clients", mgr.GetNumConnections())

return &mgr, nil
}
Expand Down
38 changes: 20 additions & 18 deletions pkg/client/clientpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ import (
)

type ClientPool struct {
retry int
concurrency int
space string
postStart *config.NebulaPostStart
preStop *config.NebulaPreStop
statsCh chan<- base.Stats
pool *nebula.ConnectionPool
Sessions []*nebula.Session
requestChs []chan base.ClientRequest
retry int
concurrency int
space string
postStart *config.NebulaPostStart
preStop *config.NebulaPreStop
statsCh chan<- base.Stats
pool *nebula.ConnectionPool
Sessions []*nebula.Session
requestChs []chan base.ClientRequest
runnerLogger *logger.RunnerLogger
}

func NewClientPool(settings *config.NebulaClientSettings, statsCh chan<- base.Stats) (*ClientPool, error) {
func NewClientPool(settings *config.NebulaClientSettings, statsCh chan<- base.Stats, runnerLogger *logger.RunnerLogger) (*ClientPool, error) {
addrs := strings.Split(*settings.Connection.Address, ",")
var hosts []nebula.HostAddress
for _, addr := range addrs {
Expand All @@ -45,16 +46,17 @@ func NewClientPool(settings *config.NebulaClientSettings, statsCh chan<- base.St
MaxConnPoolSize: len(addrs) * *settings.Concurrency,
MinConnPoolSize: 1,
}
connPool, err := nebula.NewConnectionPool(hosts, conf, logger.NebulaLogger{})
connPool, err := nebula.NewConnectionPool(hosts, conf, logger.NewNebulaLogger(runnerLogger))
if err != nil {
return nil, err
}
pool := ClientPool{
space: *settings.Space,
postStart: settings.PostStart,
preStop: settings.PreStop,
statsCh: statsCh,
pool: connPool,
space: *settings.Space,
postStart: settings.PostStart,
preStop: settings.PreStop,
statsCh: statsCh,
pool: connPool,
runnerLogger: runnerLogger,
}
pool.retry = *settings.Retry
pool.concurrency = (*settings.Concurrency) * len(addrs)
Expand Down Expand Up @@ -105,7 +107,7 @@ func (p *ClientPool) Close() {
if p.preStop != nil && p.preStop.Commands != nil {
if i := p.getActiveConnIdx(); i != -1 {
if err := p.exec(i, *p.preStop.Commands); err != nil {
logger.Errorf("%s", err.Error())
p.runnerLogger.Errorf("%s", err.Error())
}
}
}
Expand Down Expand Up @@ -153,7 +155,7 @@ func (p *ClientPool) Init() error {
func (p *ClientPool) startWorker(i int) {
stmt := fmt.Sprintf("USE `%s`;", p.space)
if err := p.exec(i, stmt); err != nil {
logger.Error(err.Error())
p.runnerLogger.Error(err.Error())
return
}
for {
Expand Down
12 changes: 5 additions & 7 deletions pkg/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ func (r *Runner) Run(yaml *config.YAMLConfig) {
}
}()

if !*yaml.RemoveTempFiles {
logger.Init(*yaml.LogPath)
}
runnerLogger := logger.NewRunnerLogger(*yaml.LogPath)

statsMgr := stats.NewStatsMgr(yaml.Files)
statsMgr := stats.NewStatsMgr(yaml.Files, runnerLogger)
defer statsMgr.Close()

clientMgr, err := client.NewNebulaClientMgr(yaml.NebulaClientSettings, statsMgr.StatsCh)
clientMgr, err := client.NewNebulaClientMgr(yaml.NebulaClientSettings, statsMgr.StatsCh, runnerLogger)
if err != nil {
r.errs = append(r.errs, importerError.Wrap(importerError.NebulaError, err))
return
Expand All @@ -60,14 +58,14 @@ func (r *Runner) Run(yaml *config.YAMLConfig) {
freaders := make([]*reader.FileReader, len(yaml.Files))

for i, file := range yaml.Files {
errCh, err := errHandler.Init(file, clientMgr.GetNumConnections(), *yaml.RemoveTempFiles)
errCh, err := errHandler.Init(file, clientMgr.GetNumConnections(), *yaml.RemoveTempFiles, runnerLogger)
if err != nil {
r.errs = append(r.errs, importerError.Wrap(importerError.ConfigError, err))
statsMgr.StatsCh <- base.NewFileDoneStats(*file.Path)
continue
}

if fr, err := reader.New(i, file, *yaml.RemoveTempFiles, clientMgr.GetRequestChans(), errCh); err != nil {
if fr, err := reader.New(i, file, *yaml.RemoveTempFiles, clientMgr.GetRequestChans(), errCh, runnerLogger); err != nil {
r.errs = append(r.errs, importerError.Wrap(importerError.ConfigError, err))
statsMgr.StatsCh <- base.NewFileDoneStats(*file.Path)
continue
Expand Down
Loading