Skip to content

Commit

Permalink
enhance: use application logger (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockopp authored Dec 15, 2021
1 parent 6bfdda2 commit c123efa
Show file tree
Hide file tree
Showing 30 changed files with 330 additions and 311 deletions.
47 changes: 29 additions & 18 deletions cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ func (w *Worker) exec(index int) error {
// setup the version
v := version.New()

// setup the runtime
//
// https://pkg.go.dev/github.com/go-vela/worker/runtime?tab=doc#New
w.Runtime, err = runtime.New(w.Config.Runtime)
if err != nil {
return err
}

// capture an item from the queue
item, err := w.Queue.Pop(context.Background())
if err != nil {
Expand All @@ -43,10 +35,39 @@ func (w *Worker) exec(index int) error {
return nil
}

// create logger with extra metadata
//
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#WithFields
logger := logrus.WithFields(logrus.Fields{
"build": item.Build.GetNumber(),
"executor": w.Config.Executor.Driver,
"host": w.Config.API.Address.Hostname(),
"repo": item.Repo.GetFullName(),
"runtime": w.Config.Runtime.Driver,
"user": item.User.GetName(),
"version": v.Semantic(),
})

// setup the runtime
//
// https://pkg.go.dev/github.com/go-vela/worker/runtime?tab=doc#New
w.Runtime, err = runtime.New(&runtime.Setup{
Logger: logger,
Driver: w.Config.Runtime.Driver,
ConfigFile: w.Config.Runtime.ConfigFile,
HostVolumes: w.Config.Runtime.HostVolumes,
Namespace: w.Config.Runtime.Namespace,
PrivilegedImages: w.Config.Runtime.PrivilegedImages,
})
if err != nil {
return err
}

// setup the executor
//
// https://godoc.org/github.com/go-vela/worker/executor#New
_executor, err := executor.New(&executor.Setup{
Logger: logger,
Driver: w.Config.Executor.Driver,
LogMethod: w.Config.Executor.LogMethod,
MaxLogSize: w.Config.Executor.MaxLogSize,
Expand All @@ -63,16 +84,6 @@ func (w *Worker) exec(index int) error {
// add the executor to the worker
w.Executors[index] = _executor

// create logger with extra metadata
//
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#WithFields
logger := logrus.WithFields(logrus.Fields{
"build": item.Build.GetNumber(),
"host": w.Config.API.Address.Hostname(),
"repo": item.Repo.GetFullName(),
"version": v.Semantic(),
})

// capture the configured build timeout
t := w.Config.Build.Timeout
// check if the repository has a custom timeout
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ services:
EXECUTOR_LOG_METHOD: 'time-chunks'
QUEUE_DRIVER: redis
QUEUE_ADDR: 'redis://redis:6379'
QUEUE_ROUTES: 'docker,local,docker:local'
VELA_BUILD_LIMIT: 1
VELA_BUILD_TIMEOUT: 30m
VELA_LOG_LEVEL: trace
Expand Down Expand Up @@ -61,7 +60,6 @@ services:
DATABASE_ENCRYPTION_KEY: 'C639A572E14D5075C526FDDD43E4ECF6'
QUEUE_DRIVER: redis
QUEUE_ADDR: 'redis://redis:6379'
QUEUE_ROUTES: 'docker,local,docker:local'
SCM_DRIVER: github
SCM_CONTEXT: 'continuous-integration/vela'
SECRET_VAULT: 'true'
Expand Down
18 changes: 0 additions & 18 deletions executor/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@ import (
//
// https://pkg.go.dev/github.com/urfave/cli?tab=doc#Flag
var Flags = []cli.Flag{

// Logging Flags

&cli.StringFlag{
EnvVars: []string{"VELA_LOG_FORMAT", "EXECUTOR_LOG_FORMAT"},
FilePath: "/vela/executor/log_format",
Name: "executor.log.format",
Usage: "format of logs to output",
Value: "json",
},
&cli.StringFlag{
EnvVars: []string{"VELA_LOG_LEVEL", "EXECUTOR_LOG_LEVEL"},
FilePath: "/vela/executor/log_level",
Name: "executor.log.level",
Usage: "level of logs to output",
Value: "info",
},

// Executor Flags

&cli.StringFlag{
Expand Down
2 changes: 1 addition & 1 deletion executor/linux/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (c *client) CancelBuild() (*library.Build, error) {

err = c.DestroyBuild(context.Background())
if err != nil {
c.logger.Errorf("unable to destroy build: %v", err)
c.Logger.Errorf("unable to destroy build: %v", err)
}

return b, nil
Expand Down
Loading

0 comments on commit c123efa

Please sign in to comment.