diff options
author | Andrew Newdigate <andrew@gitlab.com> | 2017-07-24 20:23:38 +0300 |
---|---|---|
committer | Alejandro Rodríguez <alejorro70@gmail.com> | 2017-07-24 20:23:38 +0300 |
commit | 76709c8fdf84e97128c2ae94b59a0bc7af1c86fa (patch) | |
tree | fe057faf8afd6d5e2e8efa844537f921b485b2e4 /internal/helper | |
parent | 5e42e3f194dc4f17cc7b262f4b360f3d79020c09 (diff) |
Log all spawned commands
Diffstat (limited to 'internal/helper')
-rw-r--r-- | internal/helper/command.go | 13 | ||||
-rw-r--r-- | internal/helper/command_test.go | 3 | ||||
-rw-r--r-- | internal/helper/repo.go | 5 |
3 files changed, 15 insertions, 6 deletions
diff --git a/internal/helper/command.go b/internal/helper/command.go index 48d8e8b43..f3c506f51 100644 --- a/internal/helper/command.go +++ b/internal/helper/command.go @@ -1,12 +1,14 @@ package helper import ( + "context" "fmt" "io" "os" "os/exec" "syscall" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus" "gitlab.com/gitlab-org/gitaly/internal/config" log "github.com/Sirupsen/logrus" @@ -39,12 +41,17 @@ func (c *Command) Kill() { } // GitCommandReader creates a git Command with the given args -func GitCommandReader(args ...string) (*Command, error) { - return NewCommand(exec.Command(GitPath(), args...), nil, nil, nil) +func GitCommandReader(ctx context.Context, args ...string) (*Command, error) { + return NewCommand(ctx, exec.Command(GitPath(), args...), nil, nil, nil) } // NewCommand creates a Command from an exec.Cmd -func NewCommand(cmd *exec.Cmd, stdin io.Reader, stdout, stderr io.Writer, env ...string) (*Command, error) { +func NewCommand(ctx context.Context, cmd *exec.Cmd, stdin io.Reader, stdout, stderr io.Writer, env ...string) (*Command, error) { + grpc_logrus.Extract(ctx).WithFields(log.Fields{ + "path": cmd.Path, + "args": cmd.Args, + }).Info("spawn") + command := &Command{Cmd: cmd} // Explicitly set the environment for the command diff --git a/internal/helper/command_test.go b/internal/helper/command_test.go index 58192a69c..574d001f2 100644 --- a/internal/helper/command_test.go +++ b/internal/helper/command_test.go @@ -2,6 +2,7 @@ package helper import ( "bytes" + "context" "os" "os/exec" "testing" @@ -14,7 +15,7 @@ func TestNewCommand_Env(t *testing.T) { os.Setenv("TZ", "foobar") buff := &bytes.Buffer{} - cmd, err := NewCommand(exec.Command("env"), nil, buff, nil) + cmd, err := NewCommand(context.Background(), exec.Command("env"), nil, buff, nil) if err != nil { t.Fatal(err) } diff --git a/internal/helper/repo.go b/internal/helper/repo.go index de8b2a846..40924c5a2 100644 --- a/internal/helper/repo.go +++ b/internal/helper/repo.go @@ -1,6 +1,7 @@ package helper import ( + "context" "os" "path" "strings" @@ -73,12 +74,12 @@ func IsGitDirectory(dir string) bool { } // IsValidRef checks if a ref in a repo is valid -func IsValidRef(path, ref string) bool { +func IsValidRef(ctx context.Context, path, ref string) bool { if path == "" || ref == "" { return false } - cmd, err := GitCommandReader("--git-dir", path, "log", "-1", ref) + cmd, err := GitCommandReader(ctx, "--git-dir", path, "log", "-1", ref) if err != nil { return false } |