diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2020-04-08 16:06:22 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2020-04-09 09:47:13 +0300 |
commit | b647d26c4ec8bf272f153d9a7437d7b76279d3d5 (patch) | |
tree | 3944cb5c8683e1b9dcb86f55c1ec2711840b3a1b | |
parent | 0887bf430d11fdf8e9b54070e85d5dd2e7cce6ea (diff) |
lint (static code analysis) enhancements
lint must use Go1.13 as it is highest supported version.
Fix deprecated use of `grpc_logrus.Extract`.
New linters introduced and replacement of old ones in favor
of new ones with same purpose.
Fix of new linter errors.
36 files changed, 90 insertions, 101 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e7998d861..fd9b5248c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -245,15 +245,12 @@ praefect_sql_test: - make test-postgres lint: + # Only Go 1.13 currently officially supported + image: registry.gitlab.com/gitlab-org/gitlab-build-images:ruby-2.6-golang-1.13-git-2.24 stage: test script: - go version - make lint - # Temporary allowed to fail because https://github.com/golangci/golangci-lint/issues/896 - # The job fails frequently https://gitlab.com/gitlab-org/gitaly/-/jobs/494211383 - # and it stops further development process, so it is temporary measure. - # Must be fixed under: https://gitlab.com/gitlab-org/gitaly/-/issues/2605 - allow_failure: true code_navigation: allow_failure: true diff --git a/.golangci.yml b/.golangci.yml index ddc73d4d2..32a30deb5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,22 +4,17 @@ run: timeout: 5m modules-download-mode: readonly -# all available settings of specific linters -linters-settings: - staticcheck: - checks: - - inherit - # list of useful linters could be found at https://github.com/golangci/awesome-go-linters linters: disable-all: true enable: - - golint - - goimports # https://godoc.org/golang.org/x/tools/cmd/goimports - - staticcheck # https://github.com/dominikh/go-tools/tree/master/cmd/staticcheck - - gosimple # https://github.com/dominikh/go-tools/tree/master/cmd/gosimple - - unused + - goimports + - stylecheck + - deadcode - govet + - ineffassign + - megacheck + - varcheck issues: # Excluding configuration per-path, per-linter, per-text and per-source diff --git a/_support/Makefile.template b/_support/Makefile.template index 09aacab45..a56aca3e5 100644 --- a/_support/Makefile.template +++ b/_support/Makefile.template @@ -141,9 +141,8 @@ check-mod-tidy: .PHONY: lint lint: {{ .GoLint }} @cd {{ .SourceDir }} && \ - {{ .GoLint }} run --out-format tab --config .golangci.yml; \ - EXIT_CODE=$$?;\ - exit $$EXIT_CODE + {{ .GoLint }} cache clean; \ + {{ .GoLint }} run --out-format tab --config .golangci.yml .PHONY: check-formatting check-formatting: {{ .GitalyFmt }} diff --git a/internal/cache/cachedb.go b/internal/cache/cachedb.go index f756fa31e..a70724596 100644 --- a/internal/cache/cachedb.go +++ b/internal/cache/cachedb.go @@ -9,7 +9,7 @@ import ( "sync" "github.com/golang/protobuf/proto" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/safe" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) @@ -85,7 +85,7 @@ func (sdb *StreamDB) GetStream(ctx context.Context, repo *gitalypb.Repository, r return nil, err } - grpc_logrus.Extract(ctx). + ctxlogrus.Extract(ctx). WithField("stream_path", respPath). Info("getting stream") @@ -120,7 +120,7 @@ func (sdb *StreamDB) PutStream(ctx context.Context, repo *gitalypb.Repository, r return err } - grpc_logrus.Extract(ctx). + ctxlogrus.Extract(ctx). WithField("stream_path", reqPath). Info("putting stream") diff --git a/internal/cache/keyer.go b/internal/cache/keyer.go index 350c13851..de1a9c4b0 100644 --- a/internal/cache/keyer.go +++ b/internal/cache/keyer.go @@ -13,7 +13,7 @@ import ( "github.com/golang/protobuf/proto" "github.com/google/uuid" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/safe" @@ -106,7 +106,7 @@ func updateLatest(ctx context.Context, repo *gitalypb.Repository) (string, error return "", err } - grpc_logrus.Extract(ctx). + ctxlogrus.Extract(ctx). WithField("diskcache", nextGenID). Infof("diskcache state change") diff --git a/internal/command/command.go b/internal/command/command.go index ae374f3a8..3477c33ea 100644 --- a/internal/command/command.go +++ b/internal/command/command.go @@ -14,9 +14,8 @@ import ( "syscall" "time" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "github.com/sirupsen/logrus" - log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/config" ) @@ -127,7 +126,7 @@ func GitPath() string { // This shouldn't happen outside of testing, SetGitPath should be called by // main.go to ensure correctness of the configuration on start-up. if err := config.SetGitPath(); err != nil { - log.Fatal(err) // Bail out. + logrus.Fatal(err) // Bail out. } } @@ -182,7 +181,7 @@ func New(ctx context.Context, cmd *exec.Cmd, stdin io.Reader, stdout, stderr io. logPid := -1 defer func() { - grpc_logrus.Extract(ctx).WithFields(log.Fields{ + ctxlogrus.Extract(ctx).WithFields(logrus.Fields{ "pid": logPid, "path": cmd.Path, "args": cmd.Args, @@ -235,7 +234,7 @@ func New(ctx context.Context, cmd *exec.Cmd, stdin io.Reader, stdout, stderr io. command.stderrCloser = &noopWriteCloser{stderr} close(command.stderrDone) } else { - command.stderrCloser = escapeNewlineWriter(grpc_logrus.Extract(ctx).WriterLevel(log.ErrorLevel), command.stderrDone, MaxStderrBytes) + command.stderrCloser = escapeNewlineWriter(ctxlogrus.Extract(ctx).WriterLevel(logrus.ErrorLevel), command.stderrDone, MaxStderrBytes) } cmd.Stderr = command.stderrCloser @@ -392,7 +391,7 @@ func (c *Command) logProcessComplete(ctx context.Context, exitCode int) { userTime := cmd.ProcessState.UserTime() realTime := time.Since(c.startTime) - entry := grpc_logrus.Extract(ctx).WithFields(log.Fields{ + entry := ctxlogrus.Extract(ctx).WithFields(logrus.Fields{ "pid": cmd.ProcessState.Pid(), "path": cmd.Path, "args": cmd.Args, @@ -403,7 +402,7 @@ func (c *Command) logProcessComplete(ctx context.Context, exitCode int) { }) if rusage, ok := cmd.ProcessState.SysUsage().(*syscall.Rusage); ok { - entry = entry.WithFields(log.Fields{ + entry = entry.WithFields(logrus.Fields{ "command.maxrss": rusage.Maxrss, "command.inblock": rusage.Inblock, "command.oublock": rusage.Oublock, diff --git a/internal/command/spawntoken.go b/internal/command/spawntoken.go index a3bfddeba..8c5b21783 100644 --- a/internal/command/spawntoken.go +++ b/internal/command/spawntoken.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "github.com/kelseyhightower/envconfig" "github.com/prometheus/client_golang/prometheus" ) @@ -80,5 +80,5 @@ func logTime(ctx context.Context, start time.Time, msg string) { return } - grpc_logrus.Extract(ctx).WithField("spawn_queue_ms", delta.Seconds()*1000).Info(msg) + ctxlogrus.Extract(ctx).WithField("spawn_queue_ms", delta.Seconds()*1000).Info(msg) } diff --git a/internal/git/bitmap.go b/internal/git/bitmap.go index 01f55b059..f557557f7 100644 --- a/internal/git/bitmap.go +++ b/internal/git/bitmap.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags" "github.com/prometheus/client_golang/prometheus" "gitlab.com/gitlab-org/gitaly/internal/git/packfile" @@ -28,7 +28,7 @@ func init() { prometheus.MustRegister(badBitmapRequestCount) } // repoPath, and if it finds any, it logs a warning. This is to help us // investigate https://gitlab.com/gitlab-org/gitaly/issues/1728. func WarnIfTooManyBitmaps(ctx context.Context, repo repository.GitRepo) { - logEntry := grpc_logrus.Extract(ctx) + logEntry := ctxlogrus.Extract(ctx) storageRoot, err := helper.GetStorageByName(repo.GetStorageName()) if err != nil { diff --git a/internal/git/dirs.go b/internal/git/dirs.go index e619b6ccf..0a192ae3b 100644 --- a/internal/git/dirs.go +++ b/internal/git/dirs.go @@ -8,7 +8,7 @@ import ( "path/filepath" "strings" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" ) // alternateOutsideStorageError is returned when an alternates file contains an @@ -44,7 +44,7 @@ func AlternateObjectDirectories(ctx context.Context, storageRoot, repoPath strin } func altObjectDirs(ctx context.Context, storagePrefix, objDir string, depth int) ([]string, error) { - logEntry := grpc_logrus.Extract(ctx) + logEntry := ctxlogrus.Extract(ctx) const maxAlternatesDepth = 5 // Taken from https://github.com/git/git/blob/v2.23.0/sha1-file.c#L575 if depth > maxAlternatesDepth { logEntry.WithField("objdir", objDir).Warn("ignoring deeply nested alternate object directory") diff --git a/internal/helper/housekeeping/housekeeping.go b/internal/helper/housekeeping/housekeeping.go index 41ee05247..7dfc57c60 100644 --- a/internal/helper/housekeeping/housekeeping.go +++ b/internal/helper/housekeeping/housekeeping.go @@ -7,7 +7,7 @@ import ( "strings" "time" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" ) @@ -64,7 +64,7 @@ func Perform(ctx context.Context, repoPath string) error { } func myLogger(ctx context.Context) *log.Entry { - return grpc_logrus.Extract(ctx).WithField("system", "housekeeping") + return ctxlogrus.Extract(ctx).WithField("system", "housekeeping") } // FixDirectoryPermissions does a recursive directory walk to look for diff --git a/internal/middleware/cache/cache_test.go b/internal/middleware/cache/cache_test.go index d01087235..0d9d126de 100644 --- a/internal/middleware/cache/cache_test.go +++ b/internal/middleware/cache/cache_test.go @@ -168,7 +168,7 @@ func streamFileDesc(t testing.TB) *descriptor.FileDescriptorProto { return fdp } -func newTestSvc(t testing.TB, ctx context.Context, srvr *grpc.Server, svc testdata.TestServiceServer) (testdata.TestServiceClient, *grpc.ClientConn, func()) { //nolint:golint +func newTestSvc(t testing.TB, ctx context.Context, srvr *grpc.Server, svc testdata.TestServiceServer) (testdata.TestServiceClient, *grpc.ClientConn, func()) { healthSrvr := health.NewServer() grpc_health_v1.RegisterHealthServer(srvr, healthSrvr) healthSrvr.SetServingStatus("TestService", grpc_health_v1.HealthCheckResponse_SERVING) diff --git a/internal/middleware/limithandler/metrics.go b/internal/middleware/limithandler/metrics.go index 3e5f68f97..78c628cb9 100644 --- a/internal/middleware/limithandler/metrics.go +++ b/internal/middleware/limithandler/metrics.go @@ -5,7 +5,7 @@ import ( "strings" "time" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "github.com/prometheus/client_golang/prometheus" ) @@ -82,7 +82,7 @@ func (c *promMonitor) Enter(ctx context.Context, acquireTime time.Duration) { c.inprogressGauge.Inc() if acquireTime > acquireDurationLogThreshold { - logger := grpc_logrus.Extract(ctx) + logger := ctxlogrus.Extract(ctx) logger.WithField("acquire_ms", acquireTime.Seconds()*1000).Info("Rate limit acquire wait") } diff --git a/internal/praefect/grpc-proxy/proxy/helper_test.go b/internal/praefect/grpc-proxy/proxy/helper_test.go index 7e001b8c6..c240f8d71 100644 --- a/internal/praefect/grpc-proxy/proxy/helper_test.go +++ b/internal/praefect/grpc-proxy/proxy/helper_test.go @@ -18,7 +18,7 @@ func newListener(tb testing.TB) net.Listener { return listener } -func newBackendPinger(tb testing.TB, ctx context.Context) (*grpc.ClientConn, *interceptPinger, func()) { //nolint:golint +func newBackendPinger(tb testing.TB, ctx context.Context) (*grpc.ClientConn, *interceptPinger, func()) { ip := &interceptPinger{} done := make(chan struct{}) @@ -52,7 +52,7 @@ func newBackendPinger(tb testing.TB, ctx context.Context) (*grpc.ClientConn, *in return cc, ip, cleanup } -func newProxy(tb testing.TB, ctx context.Context, director proxy.StreamDirector, svc, method string) (*grpc.ClientConn, func()) { //nolint:golint +func newProxy(tb testing.TB, ctx context.Context, director proxy.StreamDirector, svc, method string) (*grpc.ClientConn, func()) { proxySrvr := grpc.NewServer( grpc.CustomCodec(proxy.NewCodec()), grpc.UnknownServiceHandler(proxy.TransparentHandler(director)), diff --git a/internal/praefect/service/server/info.go b/internal/praefect/service/server/info.go index 64360f171..5ec8a2c4e 100644 --- a/internal/praefect/service/server/info.go +++ b/internal/praefect/service/server/info.go @@ -4,7 +4,7 @@ import ( "context" "sync" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/praefect/nodes" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -49,7 +49,7 @@ func (s *Server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest) client := gitalypb.NewServerServiceClient(node.GetConnection()) resp, err := client.ServerInfo(ctx, &gitalypb.ServerInfoRequest{}) if err != nil { - grpc_logrus.Extract(ctx).WithField("storage", node.GetStorage()).WithError(err).Error("error getting sever info") + ctxlogrus.Extract(ctx).WithField("storage", node.GetStorage()).WithError(err).Error("error getting sever info") return nil } diff --git a/internal/service/cleanup/internalrefs/cleaner.go b/internal/service/cleanup/internalrefs/cleaner.go index 6efb4d618..5dd6889d4 100644 --- a/internal/service/cleanup/internalrefs/cleaner.go +++ b/internal/service/cleanup/internalrefs/cleaner.go @@ -7,7 +7,7 @@ import ( "io" "strings" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/updateref" @@ -96,7 +96,7 @@ func (c *Cleaner) processEntry(oldSHA, newSHA string) error { return nil } - grpc_logrus.Extract(c.ctx).WithFields(log.Fields{ + ctxlogrus.Extract(c.ctx).WithFields(log.Fields{ "sha": oldSHA, "refs": refs, }).Info("removing internal references") @@ -128,7 +128,7 @@ func buildLookupTable(ctx context.Context, repo *gitalypb.Repository) (map[strin return nil, err } - logger := grpc_logrus.Extract(ctx) + logger := ctxlogrus.Extract(ctx) out := make(map[string][]string) scanner := bufio.NewScanner(cmd) diff --git a/internal/service/commit/commits_helper.go b/internal/service/commit/commits_helper.go index d18f44fec..3c419bd68 100644 --- a/internal/service/commit/commits_helper.go +++ b/internal/service/commit/commits_helper.go @@ -3,7 +3,7 @@ package commit import ( "context" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/log" "gitlab.com/gitlab-org/gitaly/internal/helper/chunk" @@ -39,7 +39,7 @@ func sendCommits(ctx context.Context, sender chunk.Sender, repo *gitalypb.Reposi if err := cmd.Wait(); err != nil { // We expect this error to be caused by non-existing references. In that // case, we just log the error and send no commits to the `sender`. - grpc_logrus.Extract(ctx).WithError(err).Info("ignoring git-log error") + ctxlogrus.Extract(ctx).WithError(err).Info("ignoring git-log error") } return nil diff --git a/internal/service/commit/count_commits.go b/internal/service/commit/count_commits.go index 51916195f..a02515d7f 100644 --- a/internal/service/commit/count_commits.go +++ b/internal/service/commit/count_commits.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "google.golang.org/grpc/codes" @@ -55,11 +55,11 @@ func (s *server) CountCommits(ctx context.Context, in *gitalypb.CountCommitsRequ var count int64 countStr, readAllErr := ioutil.ReadAll(cmd) if readAllErr != nil { - grpc_logrus.Extract(ctx).WithError(err).Info("ignoring git rev-list error") + ctxlogrus.Extract(ctx).WithError(err).Info("ignoring git rev-list error") } if err := cmd.Wait(); err != nil { - grpc_logrus.Extract(ctx).WithError(err).Info("ignoring git rev-list error") + ctxlogrus.Extract(ctx).WithError(err).Info("ignoring git rev-list error") count = 0 } else if readAllErr == nil { var err error diff --git a/internal/service/commit/isancestor.go b/internal/service/commit/isancestor.go index 2b56a6acf..6bff2ac62 100644 --- a/internal/service/commit/isancestor.go +++ b/internal/service/commit/isancestor.go @@ -3,7 +3,7 @@ package commit import ( "context" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -25,7 +25,7 @@ func (s *server) CommitIsAncestor(ctx context.Context, in *gitalypb.CommitIsAnce // Assumes that `path`, `ancestorID` and `childID` are populated :trollface: func commitIsAncestorName(ctx context.Context, repo *gitalypb.Repository, ancestorID, childID string) (bool, error) { - grpc_logrus.Extract(ctx).WithFields(log.Fields{ + ctxlogrus.Extract(ctx).WithFields(log.Fields{ "ancestorSha": ancestorID, "childSha": childID, }).Debug("commitIsAncestor") diff --git a/internal/service/commit/list_files.go b/internal/service/commit/list_files.go index 95b455897..441cae9a5 100644 --- a/internal/service/commit/list_files.go +++ b/internal/service/commit/list_files.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/lstree" @@ -15,7 +15,7 @@ import ( ) func (s *server) ListFiles(in *gitalypb.ListFilesRequest, stream gitalypb.CommitService_ListFilesServer) error { - grpc_logrus.Extract(stream.Context()).WithFields(log.Fields{ + ctxlogrus.Extract(stream.Context()).WithFields(log.Fields{ "Revision": in.GetRevision(), }).Debug("ListFiles") diff --git a/internal/service/commit/raw_blame.go b/internal/service/commit/raw_blame.go index 6b923187d..6b7aacac5 100644 --- a/internal/service/commit/raw_blame.go +++ b/internal/service/commit/raw_blame.go @@ -4,7 +4,7 @@ import ( "fmt" "io" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/streamio" @@ -44,7 +44,7 @@ func (s *server) RawBlame(in *gitalypb.RawBlameRequest, stream gitalypb.CommitSe } if err := cmd.Wait(); err != nil { - grpc_logrus.Extract(ctx).WithError(err).Info("ignoring git-blame error") + ctxlogrus.Extract(ctx).WithError(err).Info("ignoring git-blame error") } return nil diff --git a/internal/service/commit/tree_entries.go b/internal/service/commit/tree_entries.go index d0c36f34d..70c386271 100644 --- a/internal/service/commit/tree_entries.go +++ b/internal/service/commit/tree_entries.go @@ -3,7 +3,7 @@ package commit import ( "fmt" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/catfile" @@ -86,7 +86,7 @@ func (c *treeEntriesSender) Send() error { return c.stream.Send(c.response) } func (c *treeEntriesSender) Reset() { c.response = &gitalypb.GetTreeEntriesResponse{} } func (s *server) GetTreeEntries(in *gitalypb.GetTreeEntriesRequest, stream gitalypb.CommitService_GetTreeEntriesServer) error { - grpc_logrus.Extract(stream.Context()).WithFields(log.Fields{ + ctxlogrus.Extract(stream.Context()).WithFields(log.Fields{ "Revision": in.Revision, "Path": in.Path, }).Debug("GetTreeEntries") diff --git a/internal/service/diff/commit.go b/internal/service/diff/commit.go index ccabef38b..654fe4db6 100644 --- a/internal/service/diff/commit.go +++ b/internal/service/diff/commit.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/diff" "gitlab.com/gitlab-org/gitaly/internal/git" @@ -19,7 +19,7 @@ type requestWithLeftRightCommitIds interface { } func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.DiffService_CommitDiffServer) error { - grpc_logrus.Extract(stream.Context()).WithFields(log.Fields{ + ctxlogrus.Extract(stream.Context()).WithFields(log.Fields{ "LeftCommitId": in.LeftCommitId, "RightCommitId": in.RightCommitId, "IgnoreWhitespaceChange": in.IgnoreWhitespaceChange, @@ -117,7 +117,7 @@ func (s *server) CommitDiff(in *gitalypb.CommitDiffRequest, stream gitalypb.Diff } func (s *server) CommitDelta(in *gitalypb.CommitDeltaRequest, stream gitalypb.DiffService_CommitDeltaServer) error { - grpc_logrus.Extract(stream.Context()).WithFields(log.Fields{ + ctxlogrus.Extract(stream.Context()).WithFields(log.Fields{ "LeftCommitId": in.LeftCommitId, "RightCommitId": in.RightCommitId, "Paths": logPaths(in.Paths), diff --git a/internal/service/objectpool/alternates.go b/internal/service/objectpool/alternates.go index db0206ec8..c43e074ea 100644 --- a/internal/service/objectpool/alternates.go +++ b/internal/service/objectpool/alternates.go @@ -11,7 +11,7 @@ import ( "strings" "time" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/helper/text" @@ -182,7 +182,7 @@ func removeAlternatesIfOk(ctx context.Context, repo *gitalypb.Repository, altFil return } - logger := grpc_logrus.Extract(ctx) + logger := ctxlogrus.Extract(ctx) // If we would do a os.Rename, and then someone else comes and clobbers // our file, it's gone forever. This trick with os.Link and os.Rename diff --git a/internal/service/objectpool/get.go b/internal/service/objectpool/get.go index c04d27139..d5500dbc2 100644 --- a/internal/service/objectpool/get.go +++ b/internal/service/objectpool/get.go @@ -4,7 +4,7 @@ import ( "context" "errors" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git/objectpool" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -18,7 +18,7 @@ func (s *server) GetObjectPool(ctx context.Context, in *gitalypb.GetObjectPoolRe objectPool, err := objectpool.FromRepo(in.GetRepository()) if err != nil { - grpc_logrus.Extract(ctx). + ctxlogrus.Extract(ctx). WithError(err). WithField("storage", in.GetRepository().GetStorageName()). WithField("storage", in.GetRepository().GetRelativePath()). diff --git a/internal/service/operations/rebase_test.go b/internal/service/operations/rebase_test.go index 228284530..ff9c530b8 100644 --- a/internal/service/operations/rebase_test.go +++ b/internal/service/operations/rebase_test.go @@ -427,13 +427,13 @@ func recvTimeout(bidi gitalypb.OperationService_UserRebaseConfirmableClient, tim } } -func buildHeaderRequest(repo *gitalypb.Repository, user *gitalypb.User, rebaseId string, branchName string, branchSha string, remoteRepo *gitalypb.Repository, remoteBranch string) *gitalypb.UserRebaseConfirmableRequest { // nolint:golint +func buildHeaderRequest(repo *gitalypb.Repository, user *gitalypb.User, rebaseID string, branchName string, branchSha string, remoteRepo *gitalypb.Repository, remoteBranch string) *gitalypb.UserRebaseConfirmableRequest { return &gitalypb.UserRebaseConfirmableRequest{ UserRebaseConfirmableRequestPayload: &gitalypb.UserRebaseConfirmableRequest_Header_{ - &gitalypb.UserRebaseConfirmableRequest_Header{ + Header: &gitalypb.UserRebaseConfirmableRequest_Header{ Repository: repo, User: user, - RebaseId: rebaseId, + RebaseId: rebaseID, Branch: []byte(branchName), BranchSha: branchSha, RemoteRepository: remoteRepo, diff --git a/internal/service/repository/gc.go b/internal/service/repository/gc.go index dcf57fc5a..ab4099855 100644 --- a/internal/service/repository/gc.go +++ b/internal/service/repository/gc.go @@ -8,7 +8,7 @@ import ( "os" "path/filepath" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/catfile" @@ -20,7 +20,7 @@ import ( ) func (*server) GarbageCollect(ctx context.Context, in *gitalypb.GarbageCollectRequest) (*gitalypb.GarbageCollectResponse, error) { - ctxlogger := grpc_logrus.Extract(ctx) + ctxlogger := ctxlogrus.Extract(ctx) ctxlogger.WithFields(log.Fields{ "WriteBitmaps": in.GetCreateBitmap(), }).Debug("GarbageCollect") diff --git a/internal/service/repository/size.go b/internal/service/repository/size.go index 63adc13b9..b966f4bd8 100644 --- a/internal/service/repository/size.go +++ b/internal/service/repository/size.go @@ -8,7 +8,7 @@ import ( "os/exec" "strconv" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -35,30 +35,30 @@ func (s *server) GetObjectDirectorySize(ctx context.Context, in *gitalypb.GetObj func getPathSize(ctx context.Context, path string) int64 { cmd, err := command.New(ctx, exec.Command("du", "-sk", path), nil, nil, nil) if err != nil { - grpc_logrus.Extract(ctx).WithError(err).Warn("ignoring du command error") + ctxlogrus.Extract(ctx).WithError(err).Warn("ignoring du command error") return 0 } sizeLine, err := ioutil.ReadAll(cmd) if err != nil { - grpc_logrus.Extract(ctx).WithError(err).Warn("ignoring command read error") + ctxlogrus.Extract(ctx).WithError(err).Warn("ignoring command read error") return 0 } if err := cmd.Wait(); err != nil { - grpc_logrus.Extract(ctx).WithError(err).Warn("ignoring du wait error") + ctxlogrus.Extract(ctx).WithError(err).Warn("ignoring du wait error") return 0 } sizeParts := bytes.Split(sizeLine, []byte("\t")) if len(sizeParts) != 2 { - grpc_logrus.Extract(ctx).Warn(fmt.Sprintf("ignoring du malformed output: %q", sizeLine)) + ctxlogrus.Extract(ctx).Warn(fmt.Sprintf("ignoring du malformed output: %q", sizeLine)) return 0 } size, err := strconv.ParseInt(string(sizeParts[0]), 10, 0) if err != nil { - grpc_logrus.Extract(ctx).WithError(err).Warn("ignoring parsing size error") + ctxlogrus.Extract(ctx).WithError(err).Warn("ignoring parsing size error") return 0 } diff --git a/internal/service/repository/snapshot.go b/internal/service/repository/snapshot.go index 4cb4d2bea..acfd833af 100644 --- a/internal/service/repository/snapshot.go +++ b/internal/service/repository/snapshot.go @@ -7,7 +7,7 @@ import ( "path/filepath" "regexp" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/archive" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -90,7 +90,7 @@ func addAlternateFiles(ctx context.Context, repository *gitalypb.Repository, bui altObjDirs, err := git.AlternateObjectDirectories(ctx, storageRoot, repoPath) if err != nil { - grpc_logrus.Extract(ctx).WithField("error", err).Warn("error getting alternate object directories") + ctxlogrus.Extract(ctx).WithField("error", err).Warn("error getting alternate object directories") return nil } diff --git a/internal/service/server/info.go b/internal/service/server/info.go index 636a302ba..93cbe8516 100644 --- a/internal/service/server/info.go +++ b/internal/service/server/info.go @@ -6,7 +6,7 @@ import ( "os" "path" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/config" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -29,7 +29,7 @@ func (s *server) ServerInfo(ctx context.Context, in *gitalypb.ServerInfoRequest) gitalyMetadata, err := storage.ReadMetadataFile(shard) if err != nil { - grpc_logrus.Extract(ctx).WithField("storage", shard).WithError(err).Error("reading gitaly metadata file") + ctxlogrus.Extract(ctx).WithField("storage", shard).WithError(err).Error("reading gitaly metadata file") } storageStatuses = append(storageStatuses, &gitalypb.ServerInfoResponse_StorageStatus{ diff --git a/internal/service/smarthttp/cache.go b/internal/service/smarthttp/cache.go index 7666c1af5..1993868ac 100644 --- a/internal/service/smarthttp/cache.go +++ b/internal/service/smarthttp/cache.go @@ -5,7 +5,7 @@ import ( "io" "sync" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/cache" @@ -56,7 +56,7 @@ func tryCache(ctx context.Context, in *gitalypb.InfoRefsRequest, w io.Writer, mi return missFn(w) } - logger := grpc_logrus.Extract(ctx).WithFields(log.Fields{"service": uploadPackSvc}) + logger := ctxlogrus.Extract(ctx).WithFields(log.Fields{"service": uploadPackSvc}) logger.Debug("Attempting to fetch cached response") countAttempt() diff --git a/internal/service/smarthttp/inforefs.go b/internal/service/smarthttp/inforefs.go index 1d3fe52f9..724afd736 100644 --- a/internal/service/smarthttp/inforefs.go +++ b/internal/service/smarthttp/inforefs.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/pktline" @@ -40,7 +40,7 @@ func (s *server) InfoRefsReceivePack(in *gitalypb.InfoRefsRequest, stream gitaly } func handleInfoRefs(ctx context.Context, service string, req *gitalypb.InfoRefsRequest, w io.Writer) error { - grpc_logrus.Extract(ctx).WithFields(log.Fields{ + ctxlogrus.Extract(ctx).WithFields(log.Fields{ "service": service, }).Debug("handleInfoRefs") diff --git a/internal/service/smarthttp/receive_pack.go b/internal/service/smarthttp/receive_pack.go index ed11ce77f..775942a8a 100644 --- a/internal/service/smarthttp/receive_pack.go +++ b/internal/service/smarthttp/receive_pack.go @@ -4,7 +4,7 @@ import ( "fmt" "strconv" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git" @@ -23,7 +23,7 @@ func (s *server) PostReceivePack(stream gitalypb.SmartHTTPService_PostReceivePac return err } - grpc_logrus.Extract(ctx).WithFields(log.Fields{ + ctxlogrus.Extract(ctx).WithFields(log.Fields{ "GlID": req.GlId, "GlRepository": req.GlRepository, "GlUsername": req.GlUsername, diff --git a/internal/service/smarthttp/upload_pack.go b/internal/service/smarthttp/upload_pack.go index ff513a42c..63854d72d 100644 --- a/internal/service/smarthttp/upload_pack.go +++ b/internal/service/smarthttp/upload_pack.go @@ -5,7 +5,7 @@ import ( "fmt" "io" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/stats" @@ -47,7 +47,7 @@ func (s *server) PostUploadPack(stream gitalypb.SmartHTTPService_PostUploadPackS stats, err := stats.ParsePackfileNegotiation(pr) if err != nil { - grpc_logrus.Extract(stream.Context()).WithError(err).Debug("failed parsing packfile negotiation") + ctxlogrus.Extract(stream.Context()).WithError(err).Debug("failed parsing packfile negotiation") return } stats.UpdateMetrics(s.packfileNegotiationMetrics) @@ -109,7 +109,7 @@ func (s *server) PostUploadPack(stream gitalypb.SmartHTTPService_PostUploadPackS return status.Errorf(codes.Unavailable, "PostUploadPack: %v", err) } - grpc_logrus.Extract(ctx).WithField("request_sha", fmt.Sprintf("%x", h.Sum(nil))).WithField("response_bytes", respBytes).Info("request details") + ctxlogrus.Extract(ctx).WithField("request_sha", fmt.Sprintf("%x", h.Sum(nil))).WithField("response_bytes", respBytes).Info("request details") return nil } diff --git a/internal/service/ssh/receive_pack.go b/internal/service/ssh/receive_pack.go index af03f68b8..9044dda57 100644 --- a/internal/service/ssh/receive_pack.go +++ b/internal/service/ssh/receive_pack.go @@ -4,7 +4,7 @@ import ( "fmt" "strconv" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git" @@ -20,7 +20,7 @@ func (s *server) SSHReceivePack(stream gitalypb.SSHService_SSHReceivePackServer) return helper.ErrInternal(err) } - grpc_logrus.Extract(stream.Context()).WithFields(log.Fields{ + ctxlogrus.Extract(stream.Context()).WithFields(log.Fields{ "GlID": req.GlId, "GlRepository": req.GlRepository, "GlUsername": req.GlUsername, diff --git a/internal/service/ssh/upload_pack.go b/internal/service/ssh/upload_pack.go index 6731942f6..cf1a4c527 100644 --- a/internal/service/ssh/upload_pack.go +++ b/internal/service/ssh/upload_pack.go @@ -6,7 +6,7 @@ import ( "io" "sync" - grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git" @@ -30,7 +30,7 @@ func (s *server) SSHUploadPack(stream gitalypb.SSHService_SSHUploadPackServer) e repository = req.Repository.GlRepository } - grpc_logrus.Extract(stream.Context()).WithFields(log.Fields{ + ctxlogrus.Extract(stream.Context()).WithFields(log.Fields{ "GlRepository": repository, "GitConfigOptions": req.GitConfigOptions, "GitProtocol": req.GitProtocol, @@ -100,7 +100,7 @@ func (s *server) sshUploadPack(stream gitalypb.SSHService_SSHUploadPackServer, r stats, err := stats.ParsePackfileNegotiation(pr) if err != nil { - grpc_logrus.Extract(stream.Context()).WithError(err).Debug("failed parsing packfile negotiation") + ctxlogrus.Extract(stream.Context()).WithError(err).Debug("failed parsing packfile negotiation") return } stats.UpdateMetrics(s.packfileNegotiationMetrics) diff --git a/internal/testhelper/testserver.go b/internal/testhelper/testserver.go index b2fa98fb7..4090799d2 100644 --- a/internal/testhelper/testserver.go +++ b/internal/testhelper/testserver.go @@ -32,7 +32,6 @@ import ( serverauth "gitlab.com/gitlab-org/gitaly/internal/server/auth" "google.golang.org/grpc" "google.golang.org/grpc/health" - "google.golang.org/grpc/health/grpc_health_v1" healthpb "google.golang.org/grpc/health/grpc_health_v1" "gopkg.in/yaml.v2" ) @@ -511,8 +510,8 @@ type HTTPSettings struct { func NewServerWithHealth(t TB, socketName string) (*grpc.Server, *health.Server) { srv := NewTestGrpcServer(t, nil, nil) healthSrvr := health.NewServer() - grpc_health_v1.RegisterHealthServer(srv, healthSrvr) - healthSrvr.SetServingStatus("", grpc_health_v1.HealthCheckResponse_SERVING) + healthpb.RegisterHealthServer(srv, healthSrvr) + healthSrvr.SetServingStatus("", healthpb.HealthCheckResponse_SERVING) lis, err := net.Listen("unix", socketName) require.NoError(t, err) |