Skip to content

Commit d4179a9

Browse files
authored
Merge pull request #151 from devtron-labs/main-watcher-logs
misc: Main watcher logs
2 parents 00d0cbe + a3436b1 commit d4179a9

26 files changed

+1467
-4
lines changed

git-sensor/go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/gammazero/workerpool v1.1.3
1414
github.com/go-git/go-git/v5 v5.11.0
1515
github.com/go-pg/pg v6.15.1+incompatible
16+
github.com/google/uuid v1.6.0
1617
github.com/google/wire v0.6.0
1718
github.com/gorilla/handlers v1.4.2
1819
github.com/gorilla/mux v1.8.0

git-sensor/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
6666
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
6767
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
6868
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
69+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
70+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
6971
github.com/google/wire v0.6.0 h1:HBkoIh4BdSxoyo9PveV8giw7ZsaBOvzWKfcg/6MrVwI=
7072
github.com/google/wire v0.6.0/go.mod h1:F4QhpQ9EDIdJ1Mbop/NZBRB+5yrR6qg3BnctaoUk6NA=
7173
github.com/gorilla/handlers v1.4.2 h1:0QniY0USkHQ1RGCLfKxeNHK9bkDHGRYGNDFBCS+YARg=

git-sensor/pkg/git/GitBaseManager.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"os/exec"
3232
"regexp"
3333
"strings"
34+
"time"
3435
)
3536

3637
type GitManager interface {
@@ -196,6 +197,12 @@ func (impl *GitManagerBaseImpl) runCommandWithCred(cmd *exec.Cmd, gitCtx GitCont
196197

197198
func (impl *GitManagerBaseImpl) runCommand(gitCtx GitContext, cmd *exec.Cmd) (response, errMsg string, err error) {
198199
cmd.Env = append(cmd.Env, "HOME=/dev/null")
200+
startTime := time.Now()
201+
// logging context deadline for the command
202+
deadline, ok := gitCtx.Deadline()
203+
if ok {
204+
impl.logger.Infow("context deadline", "deadline", deadline)
205+
}
199206
outBytes, err := cmd.CombinedOutput()
200207
output := string(outBytes)
201208
output = strings.TrimSpace(output)
@@ -204,7 +211,8 @@ func (impl *GitManagerBaseImpl) runCommand(gitCtx GitContext, cmd *exec.Cmd) (re
204211
errMsg = output
205212
if errors.Is(gitCtx.Err(), context.DeadlineExceeded) {
206213
errMsg = "command timed out"
207-
impl.logger.Errorw("command timed out", "cmd", cmd.String())
214+
impl.logger.Errorw(errMsg, "startTime", startTime, "processingTime", time.Since(startTime).Seconds(), "cmd", cmd.String())
215+
208216
// prometheus event count for timeout
209217
middleware.GitFetchTimeoutCounter.WithLabelValues().Inc()
210218
return output, errMsg, err

git-sensor/pkg/git/Watcher.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/devtron-labs/git-sensor/internals/sql"
3131
util2 "github.com/devtron-labs/git-sensor/util"
3232
"github.com/gammazero/workerpool"
33+
"github.com/google/uuid"
3334
"github.com/robfig/cron/v3"
3435
"go.uber.org/zap"
3536
"runtime/debug"
@@ -112,16 +113,17 @@ func (impl GitWatcherImpl) StopCron() {
112113
}
113114

114115
func (impl GitWatcherImpl) Watch() {
115-
impl.logger.Infow("starting git watch thread")
116+
watchID := uuid.New().String()
117+
impl.logger.Infow("starting git watch thread", "watchID", watchID)
116118
materials, err := impl.materialRepo.FindActive()
117119
if err != nil {
118-
impl.logger.Error("error in fetching watchlist", "err", err)
120+
impl.logger.Error("error in fetching watchlist", "err", err, "watchID", watchID)
119121
return
120122
}
121123
// impl.Publish(materials)
122124
middleware.ActiveGitRepoCount.WithLabelValues().Set(float64(len(materials)))
123125
impl.RunOnWorker(materials)
124-
impl.logger.Infow("stop git watch thread")
126+
impl.logger.Infow("stop git watch thread", "watchID", watchID)
125127
}
126128

127129
func (impl *GitWatcherImpl) RunOnWorker(materials []*sql.GitMaterial) {

git-sensor/vendor/github.com/google/uuid/CHANGELOG.md

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-sensor/vendor/github.com/google/uuid/CONTRIBUTING.md

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-sensor/vendor/github.com/google/uuid/CONTRIBUTORS

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-sensor/vendor/github.com/google/uuid/LICENSE

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-sensor/vendor/github.com/google/uuid/README.md

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-sensor/vendor/github.com/google/uuid/dce.go

+80
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-sensor/vendor/github.com/google/uuid/doc.go

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-sensor/vendor/github.com/google/uuid/hash.go

+59
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-sensor/vendor/github.com/google/uuid/marshal.go

+38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)