From c2715ff81e689721b4783366e3689294db524c48 Mon Sep 17 00:00:00 2001 From: Thomas Desveaux Date: Tue, 18 Oct 2022 14:57:00 +0200 Subject: [PATCH] Cherry-pick tracelog additions from https://github.com/go-gitea/gitea/pull/18732 --- modules/queue/setting.go | 7 ++++--- modules/queue/workerpool.go | 10 +++++----- services/pull/check.go | 7 +++++++ services/pull/patch.go | 2 ++ services/repository/archiver/archiver.go | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/modules/queue/setting.go b/modules/queue/setting.go index 880770f073957..5f671b99bb7d4 100644 --- a/modules/queue/setting.go +++ b/modules/queue/setting.go @@ -38,7 +38,7 @@ func getQueueSettings(name string) (setting.QueueSettings, []byte) { // CreateQueue for name with provided handler and exemplar func CreateQueue(name string, handle HandlerFunc, exemplar interface{}) Queue { - q, cfg := getQueueSettings(name) + q, cfg := getQueueSettings(string(name)) if len(cfg) == 0 { return nil } @@ -58,7 +58,7 @@ func CreateQueue(name string, handle HandlerFunc, exemplar interface{}) Queue { MaxAttempts: q.MaxAttempts, Config: cfg, QueueLength: q.QueueLength, - Name: name, + Name: string(name), }, exemplar) } if err != nil { @@ -80,7 +80,7 @@ func CreateQueue(name string, handle HandlerFunc, exemplar interface{}) Queue { // CreateUniqueQueue for name with provided handler and exemplar func CreateUniqueQueue(name string, handle HandlerFunc, exemplar interface{}) UniqueQueue { - q, cfg := getQueueSettings(name) + q, cfg := getQueueSettings(string(name)) if len(cfg) == 0 { return nil } @@ -107,6 +107,7 @@ func CreateUniqueQueue(name string, handle HandlerFunc, exemplar interface{}) Un MaxAttempts: q.MaxAttempts, Config: cfg, QueueLength: q.QueueLength, + Name: string(name), }, exemplar) } if err != nil { diff --git a/modules/queue/workerpool.go b/modules/queue/workerpool.go index bdf04a363b79f..42d1841c18755 100644 --- a/modules/queue/workerpool.go +++ b/modules/queue/workerpool.go @@ -500,7 +500,7 @@ func (p *WorkerPool) doWork(ctx context.Context) { case <-paused: log.Trace("Worker for Queue %d Pausing", p.qid) if len(data) > 0 { - log.Trace("Handling: %d data, %v", len(data), data) + log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data) if unhandled := p.handle(data...); unhandled != nil { log.Error("Unhandled Data in queue %d", p.qid) } @@ -523,7 +523,7 @@ func (p *WorkerPool) doWork(ctx context.Context) { // go back around case <-ctx.Done(): if len(data) > 0 { - log.Trace("Handling: %d data, %v", len(data), data) + log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data) if unhandled := p.handle(data...); unhandled != nil { log.Error("Unhandled Data in queue %d", p.qid) } @@ -535,7 +535,7 @@ func (p *WorkerPool) doWork(ctx context.Context) { if !ok { // the dataChan has been closed - we should finish up: if len(data) > 0 { - log.Trace("Handling: %d data, %v", len(data), data) + log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data) if unhandled := p.handle(data...); unhandled != nil { log.Error("Unhandled Data in queue %d", p.qid) } @@ -548,7 +548,7 @@ func (p *WorkerPool) doWork(ctx context.Context) { util.StopTimer(timer) if len(data) >= p.batchLength { - log.Trace("Handling: %d data, %v", len(data), data) + log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data) if unhandled := p.handle(data...); unhandled != nil { log.Error("Unhandled Data in queue %d", p.qid) } @@ -560,7 +560,7 @@ func (p *WorkerPool) doWork(ctx context.Context) { case <-timer.C: delay = time.Millisecond * 100 if len(data) > 0 { - log.Trace("Handling: %d data, %v", len(data), data) + log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data) if unhandled := p.handle(data...); unhandled != nil { log.Error("Unhandled Data in queue %d", p.qid) } diff --git a/services/pull/check.go b/services/pull/check.go index 288f4dc0b73b7..da8f645708177 100644 --- a/services/pull/check.go +++ b/services/pull/check.go @@ -155,9 +155,12 @@ func checkAndUpdateStatus(pr *issues_model.PullRequest) { } if !has { + log.Trace("Updating PR[%d] in %d: Status:%d Conflicts:%s Protected:%s", pr.ID, pr.BaseRepoID, pr.Status, pr.ConflictedFiles, pr.ChangedProtectedFiles) if err := pr.UpdateColsIfNotMerged("merge_base", "status", "conflicted_files", "changed_protected_files"); err != nil { log.Error("Update[%d]: %v", pr.ID, err) } + } else { + log.Trace("Not updating PR[%d] in %d as still in the queue", pr.ID, pr.BaseRepoID) } } @@ -329,12 +332,15 @@ func testPR(id int64) { log.Error("GetPullRequestByID[%d]: %v", id, err) return } + log.Trace("Testing PR[%d] in %d", pr.ID, pr.BaseRepoID) if pr.HasMerged { + log.Trace("PR[%d] in %d: already merged", pr.ID, pr.BaseRepoID) return } if manuallyMerged(ctx, pr) { + log.Trace("PR[%d] in %d: manually merged", pr.ID, pr.BaseRepoID) return } @@ -346,6 +352,7 @@ func testPR(id int64) { } return } + log.Trace("PR[%d] in %d: patch tested new Status:%d ConflictedFiles:%s ChangedProtectedFiles:%s", pr.ID, pr.BaseRepoID, pr.Status, pr.ConflictedFiles, pr.ChangedProtectedFiles) checkAndUpdateStatus(pr) } diff --git a/services/pull/patch.go b/services/pull/patch.go index 32895b2e784fc..e8ed8b5daea90 100644 --- a/services/pull/patch.go +++ b/services/pull/patch.go @@ -296,12 +296,14 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo * var treeHash string treeHash, _, err = git.NewCommand(ctx, "write-tree").RunStdString(&git.RunOpts{Dir: tmpBasePath}) if err != nil { + log.Debug("Unable to write unconflicted tree for PR[%d] %s/%s#%d. Error: %v", pr.ID, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, pr.Index, err) lsfiles, _, _ := git.NewCommand(ctx, "ls-files", "-u").RunStdString(&git.RunOpts{Dir: tmpBasePath}) return false, fmt.Errorf("unable to write unconflicted tree: %w\n`git ls-files -u`:\n%s", err, lsfiles) } treeHash = strings.TrimSpace(treeHash) baseTree, err := gitRepo.GetTree("base") if err != nil { + log.Debug("Unable to get base tree for PR[%d] %s/%s#%d. Error: %v", pr.ID, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, pr.Index, err) return false, err } if treeHash == baseTree.ID.String() { diff --git a/services/repository/archiver/archiver.go b/services/repository/archiver/archiver.go index ae43503bae125..9ec969d8dd5e2 100644 --- a/services/repository/archiver/archiver.go +++ b/services/repository/archiver/archiver.go @@ -317,7 +317,7 @@ func Init() error { archiverQueue = queue.CreateUniqueQueue("repo-archive", handler, new(ArchiveRequest)) if archiverQueue == nil { - return errors.New("unable to create codes indexer queue") + return errors.New("unable to create repo archiver queue") } go graceful.GetManager().RunWithShutdownFns(archiverQueue.Run)