Skip to content

Commit db1931c

Browse files
committed
Add some more trace and debug logging to process and testpatch
Given the repeated issues here I've just added some plain trace logging which should allow for easier tracing of when processes are created. Signed-off-by: Andrew Thornton <[email protected]>
1 parent b06b088 commit db1931c

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

modules/process/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"strconv"
1616
"sync"
1717
"time"
18+
19+
"code.gitea.io/gitea/modules/log"
1820
)
1921

2022
// TODO: This packages still uses a singleton for the Manager.
@@ -103,6 +105,7 @@ func (pm *Manager) AddContextTimeout(parent context.Context, timeout time.Durati
103105
func (pm *Manager) Add(parentPID IDType, description string, cancel context.CancelFunc) (IDType, FinishedFunc) {
104106
pm.mutex.Lock()
105107
start, pid := pm.nextPID()
108+
log.Trace("Adding Process[%s:%s] %s", parentPID, pid, description)
106109

107110
parent := pm.processes[parentPID]
108111
if parent == nil {
@@ -120,6 +123,7 @@ func (pm *Manager) Add(parentPID IDType, description string, cancel context.Canc
120123
finished := func() {
121124
cancel()
122125
pm.remove(process)
126+
log.Trace("Finished Process[%d:%d] %s", parentPID, pid, description)
123127
}
124128

125129
if parent != nil {

modules/queue/workerpool.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
484484
case <-paused:
485485
log.Trace("Worker for Queue %d Pausing", p.qid)
486486
if len(data) > 0 {
487-
log.Trace("Handling: %d data, %v", len(data), data)
487+
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
488488
if unhandled := p.handle(data...); unhandled != nil {
489489
log.Error("Unhandled Data in queue %d", p.qid)
490490
}
@@ -507,7 +507,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
507507
// go back around
508508
case <-ctx.Done():
509509
if len(data) > 0 {
510-
log.Trace("Handling: %d data, %v", len(data), data)
510+
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
511511
if unhandled := p.handle(data...); unhandled != nil {
512512
log.Error("Unhandled Data in queue %d", p.qid)
513513
}
@@ -519,7 +519,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
519519
if !ok {
520520
// the dataChan has been closed - we should finish up:
521521
if len(data) > 0 {
522-
log.Trace("Handling: %d data, %v", len(data), data)
522+
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
523523
if unhandled := p.handle(data...); unhandled != nil {
524524
log.Error("Unhandled Data in queue %d", p.qid)
525525
}
@@ -532,7 +532,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
532532
util.StopTimer(timer)
533533

534534
if len(data) >= p.batchLength {
535-
log.Trace("Handling: %d data, %v", len(data), data)
535+
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
536536
if unhandled := p.handle(data...); unhandled != nil {
537537
log.Error("Unhandled Data in queue %d", p.qid)
538538
}
@@ -544,7 +544,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
544544
case <-timer.C:
545545
delay = time.Millisecond * 100
546546
if len(data) > 0 {
547-
log.Trace("Handling: %d data, %v", len(data), data)
547+
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
548548
if unhandled := p.handle(data...); unhandled != nil {
549549
log.Error("Unhandled Data in queue %d", p.qid)
550550
}

services/pull/check.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ func checkAndUpdateStatus(pr *models.PullRequest) {
6262
}
6363

6464
if !has {
65+
log.Trace("Updating PR[%d] in %d: Status:%d Conflicts:%s Protected:%s", pr.ID, pr.BaseRepoID, pr.Status, pr.ConflictedFiles, pr.ChangedProtectedFiles)
6566
if err := pr.UpdateColsIfNotMerged("merge_base", "status", "conflicted_files", "changed_protected_files"); err != nil {
6667
log.Error("Update[%d]: %v", pr.ID, err)
6768
}
69+
} else {
70+
log.Trace("Not updating PR[%d] in %d as still in the queue", pr.ID, pr.BaseRepoID)
6871
}
6972
}
7073

@@ -234,12 +237,15 @@ func testPR(id int64) {
234237
log.Error("GetPullRequestByID[%d]: %v", id, err)
235238
return
236239
}
240+
log.Trace("Testing PR[%d] in %d", pr.ID, pr.BaseRepoID)
237241

238242
if pr.HasMerged {
243+
log.Trace("PR[%d] in %d: already merged", pr.ID, pr.BaseRepoID)
239244
return
240245
}
241246

242247
if manuallyMerged(ctx, pr) {
248+
log.Trace("PR[%d] in %d: manually merged", pr.ID, pr.BaseRepoID)
243249
return
244250
}
245251

@@ -251,6 +257,8 @@ func testPR(id int64) {
251257
}
252258
return
253259
}
260+
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)
261+
254262
checkAndUpdateStatus(pr)
255263
}
256264

services/pull/patch.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,13 @@ func checkConflicts(ctx context.Context, pr *models.PullRequest, gitRepo *git.Re
280280
if !conflict {
281281
treeHash, err := git.NewCommand(ctx, "write-tree").RunInDir(tmpBasePath)
282282
if err != nil {
283+
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)
283284
return false, err
284285
}
285286
treeHash = strings.TrimSpace(treeHash)
286287
baseTree, err := gitRepo.GetTree("base")
287288
if err != nil {
289+
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)
288290
return false, err
289291
}
290292
pr.Status = models.PullRequestStatusMergeable

0 commit comments

Comments
 (0)