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

enhance: use application logger #246

Merged
merged 18 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
42 changes: 24 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,34 @@ 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(),
jbrockopp marked this conversation as resolved.
Show resolved Hide resolved
"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(),
})

w.Config.Runtime.Logger = logger

// 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
}

// 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,
Client: w.VelaClient,
Expand All @@ -62,16 +78,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
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