update agent logs

This commit is contained in:
Brad Rydzewski 2016-09-29 17:45:13 -04:00
parent 17a77127b6
commit 76b0286b68
3 changed files with 19 additions and 17 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/drone/drone/build" "github.com/drone/drone/build"
"github.com/drone/drone/model" "github.com/drone/drone/model"
"github.com/drone/mq/logger"
"github.com/drone/mq/stomp" "github.com/drone/mq/stomp"
) )
@ -27,7 +28,7 @@ func NewClientUpdater(client *stomp.Client) UpdateFunc {
return func(w *model.Work) { return func(w *model.Work) {
err := client.SendJSON("/queue/updates", w) err := client.SendJSON("/queue/updates", w)
if err != nil { if err != nil {
logrus.Errorf("Error updating %s/%s#%d.%d. %s", logger.Warningf("Error updating %s/%s#%d.%d. %s",
w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number, err) w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number, err)
} }
if w.Job.Status != model.StatusRunning { if w.Job.Status != model.StatusRunning {
@ -38,7 +39,7 @@ func NewClientUpdater(client *stomp.Client) UpdateFunc {
} }
if err := client.Send(dest, []byte("eof"), opts...); err != nil { if err := client.Send(dest, []byte("eof"), opts...); err != nil {
logrus.Errorf("Error sending eof %s/%s#%d.%d. %s", logger.Warningf("Error sending eof %s/%s#%d.%d. %s",
w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number, err) w.Repo.Owner, w.Repo.Name, w.Build.Number, w.Job.Number, err)
} }
} }

View file

@ -175,7 +175,6 @@ func (p *Pipeline) exec(c *yaml.Container) error {
} }
p.containers = append(p.containers, name) p.containers = append(p.containers, name)
logrus.Debugf("wait.add(1) for %s logs", name)
p.wait.Add(1) p.wait.Add(1)
go func() { go func() {
defer func() { defer func() {
@ -183,7 +182,6 @@ func (p *Pipeline) exec(c *yaml.Container) error {
logrus.Errorln("recover writing build output", r) logrus.Errorln("recover writing build output", r)
} }
logrus.Debugf("wait.done() for %s logs", name)
p.wait.Done() p.wait.Done()
}() }()
@ -217,7 +215,6 @@ func (p *Pipeline) exec(c *yaml.Container) error {
return err return err
} }
logrus.Debugf("wait.add(1) for %s exit code", name)
p.wait.Add(1) p.wait.Add(1)
go func() { go func() {
defer func() { defer func() {
@ -225,7 +222,6 @@ func (p *Pipeline) exec(c *yaml.Container) error {
logrus.Errorln("recover writing exit code to output", r) logrus.Errorln("recover writing exit code to output", r)
} }
p.wait.Done() p.wait.Done()
logrus.Debugf("wait.done() for %s exit code", name)
}() }()
p.pipe <- &Line{ p.pipe <- &Line{

View file

@ -9,7 +9,9 @@ import (
"time" "time"
"github.com/drone/drone/model" "github.com/drone/drone/model"
"github.com/drone/mq/logger"
"github.com/drone/mq/stomp" "github.com/drone/mq/stomp"
"github.com/tidwall/redlog"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
@ -136,9 +138,15 @@ var AgentCmd = cli.Command{
func start(c *cli.Context) { func start(c *cli.Context) {
log := redlog.New(os.Stderr)
log.SetLevel(0)
logger.SetLogger(log)
// debug level if requested by user // debug level if requested by user
if c.Bool("debug") { if c.Bool("debug") {
logrus.SetLevel(logrus.DebugLevel) logrus.SetLevel(logrus.DebugLevel)
log.SetLevel(1)
} else { } else {
logrus.SetLevel(logrus.WarnLevel) logrus.SetLevel(logrus.WarnLevel)
} }
@ -152,10 +160,7 @@ func start(c *cli.Context) {
accessToken = c.String("drone-token") accessToken = c.String("drone-token")
} }
logrus.Infof("Connecting to %s with token %s", logger.Noticef("connecting to server%s", c.String("drone-server"))
c.String("drone-server"),
accessToken,
)
server := strings.TrimRight(c.String("drone-server"), "/") server := strings.TrimRight(c.String("drone-server"), "/")
@ -203,7 +208,7 @@ func start(c *cli.Context) {
// dial the drone server to establish a TCP connection. // dial the drone server to establish a TCP connection.
client, err = stomp.Dial(server) client, err = stomp.Dial(server)
if err != nil { if err != nil {
logrus.Errorf("Failed to establish server connection, %s, retry in %v", err, backoff) logger.Warningf("connection failed, retry in %v. %s", backoff, err)
<-time.After(backoff) <-time.After(backoff)
continue continue
} }
@ -213,7 +218,7 @@ func start(c *cli.Context) {
// initialize the stomp session and authenticate. // initialize the stomp session and authenticate.
if err = client.Connect(opts...); err != nil { if err = client.Connect(opts...); err != nil {
logrus.Errorf("Failed to establish server session, %s, retry in %v", err, backoff) logger.Warningf("session failed, retry in %v", backoff, err)
<-time.After(backoff) <-time.After(backoff)
continue continue
} }
@ -233,10 +238,10 @@ func start(c *cli.Context) {
go handler(m) // HACK until we a channel based Subscribe implementation go handler(m) // HACK until we a channel based Subscribe implementation
}), opts...) }), opts...)
logrus.Infof("Server connection establish, ready to process builds.") logger.Noticef("connection establish, ready to process builds.")
<-client.Done() <-client.Done()
logrus.Warnf("Server connection interrupted, attempting to reconnect.") logger.Warningf("connection interrupted, attempting to reconnect.")
} }
} }
@ -251,10 +256,10 @@ func handleSignals() {
go func() { go func() {
<-c <-c
logrus.Debugln("SIGTERM received.") logger.Warningf("SIGTERM received.")
logrus.Debugln("wait for running builds to finish.") logger.Warningf("wait for running builds to finish.")
running.Wait() running.Wait()
logrus.Debugln("done.") logger.Warningf("done.")
os.Exit(0) os.Exit(0)
}() }()
} }