Skip to content

Commit

Permalink
feat(api): add more context in some logs (#3253)
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored and bnjjj committed Aug 23, 2018
1 parent f6c30c5 commit 9123b00
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion engine/api/repositoriesmanager/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func processEvent(ctx context.Context, db *gorp.DbMap, event sdk.Event, store ca

if err := c.SetStatus(ctx, event); err != nil {
RetryEvent(&event, err, store)
return fmt.Errorf("repositoriesmanager>processEvent> SetStatus > err:%s", err)
return fmt.Errorf("repositoriesmanager>processEvent> SetStatus > event.EventType:%s err:%s", event.EventType, err)
}

return nil
Expand Down
25 changes: 17 additions & 8 deletions engine/api/workflow/workflow_run_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,18 @@ func ResyncCommitStatus(ctx context.Context, db gorp.SqlExecutor, store cache.St
if !node.IsLinkedToRepo() {
return nil
}

vcsServer := repositoriesmanager.GetProjectVCSServer(proj, node.Context.Application.VCSServer)
if vcsServer == nil {
return nil
}

details := fmt.Sprintf("on project:%s workflow:%s node:%s num:%d sub:%d vcs:%s", proj.Name, wr.Workflow.Name, nodeRun.WorkflowNodeName, nodeRun.Number, nodeRun.SubNumber, vcsServer.Name)

//Get the RepositoriesManager Client
client, errClient := repositoriesmanager.AuthorizedClient(ctx, db, store, vcsServer)
if errClient != nil {
return sdk.WrapError(errClient, "resyncCommitStatus> Cannot get client")
return sdk.WrapError(errClient, "resyncCommitStatus> Cannot get client %s", details)
}

ref := nodeRun.VCSHash
Expand All @@ -97,7 +100,7 @@ func ResyncCommitStatus(ctx context.Context, db gorp.SqlExecutor, store cache.St
}
statuses, errStatuses := client.ListStatuses(ctx, node.Context.Application.RepositoryFullname, ref)
if errStatuses != nil {
return sdk.WrapError(errStatuses, "resyncCommitStatus> Cannot get statuses")
return sdk.WrapError(errStatuses, "resyncCommitStatus> Cannot get statuses %s", details)
}

var statusFound *sdk.VCSCommitStatus
Expand All @@ -112,28 +115,34 @@ func ResyncCommitStatus(ctx context.Context, db gorp.SqlExecutor, store cache.St
}
}

if statusFound == nil {
if statusFound == nil || statusFound.State == "" {
if err := sendVCSEventStatus(ctx, db, store, proj, wr, &nodeRun); err != nil {
log.Error("resyncCommitStatus> Error sending status: %v", err)
log.Error("resyncCommitStatus> Error sending status %s err: %v", details, err)
}
continue
}

if statusFound.State == sdk.StatusBuilding.String() {
if err := sendVCSEventStatus(ctx, db, store, proj, wr, &nodeRun); err != nil {
log.Error("resyncCommitStatus> Error sending status: %v", err)
log.Error("resyncCommitStatus> Error sending status %s err: %v", details, err)
}
continue
}

switch statusFound.State {
case sdk.StatusBuilding.String():
if err := sendVCSEventStatus(ctx, db, store, proj, wr, &nodeRun); err != nil {
log.Error("resyncCommitStatus> Error sending status %s %s err:%v", statusFound.State, details, err)
}
continue

case sdk.StatusSuccess.String():
switch nodeRun.Status {
case sdk.StatusSuccess.String():
continue
default:
if err := sendVCSEventStatus(ctx, db, store, proj, wr, &nodeRun); err != nil {
log.Error("resyncCommitStatus> Error sending status: %v", err)
log.Error("resyncCommitStatus> Error sending status %s %s err:%v", statusFound.State, details, err)
}
continue
}
Expand All @@ -144,7 +153,7 @@ func ResyncCommitStatus(ctx context.Context, db gorp.SqlExecutor, store cache.St
continue
default:
if err := sendVCSEventStatus(ctx, db, store, proj, wr, &nodeRun); err != nil {
log.Error("resyncCommitStatus> Error sending status: %v", err)
log.Error("resyncCommitStatus> Error sending status %s %s err:%v", statusFound.State, details, err)
}
continue
}
Expand All @@ -155,7 +164,7 @@ func ResyncCommitStatus(ctx context.Context, db gorp.SqlExecutor, store cache.St
continue
default:
if err := sendVCSEventStatus(ctx, db, store, proj, wr, &nodeRun); err != nil {
log.Error("resyncCommitStatus> Error sending status: %v", err)
log.Error("resyncCommitStatus> Error sending status %s %s err:%v", statusFound.State, details, err)
}
continue
}
Expand Down
9 changes: 7 additions & 2 deletions engine/api/workflow_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ func (api *API) postTakeWorkflowJobHandler() service.Handler {
return sdk.WrapError(err, "postTakeWorkflowJobHandler> cannot unmarshal request")
}

p, errP := project.LoadProjectByNodeJobRunID(ctx, api.mustDB(), api.Cache, id, getUser(ctx), project.LoadOptions.WithVariables, project.LoadOptions.WithClearKeys)
user := getUser(ctx)
p, errP := project.LoadProjectByNodeJobRunID(ctx, api.mustDB(), api.Cache, id, user, project.LoadOptions.WithVariables, project.LoadOptions.WithClearKeys)
if errP != nil {
return sdk.WrapError(errP, "postTakeWorkflowJobHandler> Cannot load project by nodeJobRunID:%d", id)
var username string
if user != nil {
username = user.Username
}
return sdk.WrapError(errP, "postTakeWorkflowJobHandler> Cannot load project by nodeJobRunID:%d requester:%s", id, username)
}

//Load worker model
Expand Down
6 changes: 3 additions & 3 deletions engine/hatchery/marathon/marathon.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,15 @@ func (h *HatcheryMarathon) killDisabledWorkers() error {
return err
}

for _, w := range workers {
for wk, w := range workers {
if w.Status != sdk.StatusDisabled {
continue
}

// check that there is a worker matching
for _, app := range apps {
for ak, app := range apps {
if strings.HasSuffix(app, w.Name) {
log.Info("killing disabled worker %s", app)
log.Info("killing disabled worker %s id:%s wk:%d ak:%d", app, w.ID, wk, ak)
if _, err := h.marathonClient.DeleteApplication(app, true); err != nil {
log.Warning("killDisabledWorkers> Error while delete app %s err:%s", app, err)
// continue to next app
Expand Down
9 changes: 7 additions & 2 deletions engine/vcs/bitbucket/client_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ func (b *bitbucketClient) SetStatus(ctx context.Context, event sdk.Event) error
return sdk.WrapError(err, "bitbucketClient.SetStatus: Cannot process Event")
}

state := getBitbucketStateFromStatus(statusData.status)
status := Status{
Key: statusData.key,
Name: fmt.Sprintf("%s%d", statusData.key, statusData.buildNumber),
State: getBitbucketStateFromStatus(statusData.status),
State: state,
URL: statusData.url,
Description: statusData.description,
}
Expand All @@ -56,7 +57,11 @@ func (b *bitbucketClient) SetStatus(ctx context.Context, event sdk.Event) error
if err != nil {
return sdk.WrapError(err, "bitbucketClient.SetStatus> Unable to marshall status")
}
return b.do(ctx, "POST", "build-status", fmt.Sprintf("/commits/%s", statusData.hash), nil, values, nil, nil)

if err := b.do(ctx, "POST", "build-status", fmt.Sprintf("/commits/%s", statusData.hash), nil, values, nil, nil); err != nil {
return sdk.WrapError(err, "bitbucketClient.SetStatus> Unable to post build-status name:%s status:%s", status.Name, state)
}
return nil
}

func (b *bitbucketClient) ListStatuses(ctx context.Context, repo string, ref string) ([]sdk.VCSCommitStatus, error) {
Expand Down
2 changes: 1 addition & 1 deletion engine/vcs/github/client_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (g *githubClient) SetStatus(ctx context.Context, event sdk.Event) error {
}

if res.StatusCode != 201 {
return sdk.WrapError(err, "github.SetStatus> Unable to create status on github. Status code : %d - Body: %s", res.StatusCode, body)
return sdk.WrapError(err, "github.SetStatus> Unable to create status on github. Status code : %d - Body: %s - target:%s", res.StatusCode, body, data.urlPipeline)
}

s := &Status{}
Expand Down
2 changes: 1 addition & 1 deletion engine/vcs/gitlab/client_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *gitlabClient) SetStatus(ctx context.Context, event sdk.Event) error {
}

if _, _, err := c.client.Commits.SetCommitStatus(data.repoFullName, data.hash, opt); err != nil {
return err
return sdk.WrapError(err, "gitlabClient.SetStatus> Cannot process event %s - repo:%s hash:%s", event, data.repoFullName, data.hash)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion engine/vcs/vcs_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ func (s *Service) postStatusHandler() service.Handler {
}

if err := client.SetStatus(ctx, evt); err != nil {
return sdk.WrapError(err, "VCS> postStatusHandler> Unable to set status")
return sdk.WrapError(err, "VCS> postStatusHandler> Unable to set status on %s", name)
}

return nil
Expand Down

0 comments on commit 9123b00

Please sign in to comment.