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: operate/exec logging #461

Merged
merged 1 commit into from
Apr 14, 2023
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
5 changes: 3 additions & 2 deletions cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ func (w *Worker) exec(index int) error {
return nil
}

// GET build token from server to setup execBuildClient
// retrieve a build token from the server to setup the execBuildClient
bt, _, err := w.VelaClient.Build.GetBuildToken(item.Repo.GetOrg(), item.Repo.GetName(), item.Build.GetNumber())
if err != nil {
logrus.Errorf("Unable to GetBuildToken: %s", err)
logrus.Errorf("unable to retrieve build token: %s", err)
return err
}

// set up build client with build token as auth
execBuildClient, err := setupClient(w.Config.Server, bt.GetToken())
if err != nil {
Expand Down
18 changes: 14 additions & 4 deletions cmd/vela-worker/operate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ func (w *Worker) operate(ctx context.Context) error {
registryWorker.SetBuildLimit(int64(w.Config.Build.Limit))

// pull registration token from configuration if provided; wait if not
logrus.Trace("waiting for register token")

token := <-w.RegisterToken

logrus.Trace("received register token")

// setup the vela client with the token
w.VelaClient, err = setupClient(w.Config.Server, token)
if err != nil {
Expand All @@ -50,7 +54,7 @@ func (w *Worker) operate(ctx context.Context) error {
for {
select {
case <-gctx.Done():
logrus.Info("Completed looping on worker registration")
logrus.Info("completed looping on worker registration")
return nil
default:
// check in attempt loop
Expand All @@ -70,6 +74,8 @@ func (w *Worker) operate(ctx context.Context) error {
// token has expired
if expired && len(w.Config.Server.Secret) == 0 {
// wait on new registration token, return to check in attempt
logrus.Trace("check-in token has expired, waiting for new register token")

token = <-w.RegisterToken

// setup the vela client with the token
Expand All @@ -83,7 +89,7 @@ func (w *Worker) operate(ctx context.Context) error {

// check in failed, token is still valid, retry
logrus.Errorf("unable to check-in worker %s on the server: %v", registryWorker.GetHostname(), err)
logrus.Info("retrying...")
logrus.Info("retrying check-in...")

time.Sleep(5 * time.Second)

Expand Down Expand Up @@ -125,7 +131,7 @@ func (w *Worker) operate(ctx context.Context) error {
// log a message indicating the start of an operator thread
//
// https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#Info
logrus.Infof("Thread ID %d listening to queue...", id)
logrus.Infof("thread ID %d listening to queue...", id)

// spawn errgroup routine for operator subprocess
//
Expand All @@ -143,9 +149,13 @@ func (w *Worker) operate(ctx context.Context) error {
case <-gctx.Done():
logrus.WithFields(logrus.Fields{
"id": id,
}).Info("Completed looping on worker executor")
}).Info("completed looping on worker executor")
return nil
default:
logrus.WithFields(logrus.Fields{
"id": id,
}).Info("running worker executor exec")

// exec operator subprocess to poll and execute builds
// (do not pass the context to avoid errors in one
// executor+build inadvertently canceling other builds)
Expand Down
2 changes: 2 additions & 0 deletions cmd/vela-worker/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ func run(c *cli.Context) error {

// if server secret is provided, use as register token on start up
if len(c.String("server.secret")) > 0 {
logrus.Trace("registering worker with embedded server secret")

w.RegisterToken <- c.String("server.secret")
}

Expand Down