Skip to content
  • Watch
    Notifications
  • Fork

    Fork sourcegraph

    If this dialog fails to load, you can visit the fork page directly.

/sourcegraph

gitserver: Use opentracing for exec endpoint #3257

Merged
merged 1 commit into from 18 days ago
Merged
Changes from all commits
Commits
Show all changes
1 commit
Show changes since your last review
You haven’t reviewed this pull request yet
Select commit
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+22 −16
Diff settings

Always

Just for now

Select a reply ctrl .

Attach files by dragging & dropping, selecting or pasting them. Uploading your files… We don’t support that file type. with a GIF, JPEG, JPG, PNG, DOCX, GZ, LOG, PDF, PPTX, TXT, XLSX or ZIP. Attaching documents requires write permission to this repository. with a GIF, JPEG, JPG, PNG, DOCX, GZ, LOG, PDF, PPTX, TXT, XLSX or ZIP. We don’t support that file type. with a GIF, JPEG, JPG, PNG, DOCX, GZ, LOG, PDF, PPTX, TXT, XLSX or ZIP. Yowza, that’s a big file with a file smaller than 10MB. This file is empty. with a file that’s not empty. This file is hidden. with another file. Something went really wrong, and we can’t process that file.

Nothing to preview

@@ -40,7 +40,6 @@ import (
"github.com/sourcegraph/sourcegraph/pkg/repotrackutil"
"github.com/sourcegraph/sourcegraph/pkg/trace"
"github.com/sourcegraph/sourcegraph/pkg/vcs/git"
nettrace "golang.org/x/net/trace"
log15 "gopkg.in/inconshreveable/log15.v2"
)

@@ -467,7 +466,7 @@ func (s *Server) handleExec(w http.ResponseWriter, r *http.Request) {
exitStatus := -10810 // sentinel value to indicate not set
var stdoutN, stderrN int64
var status string
var errStr string
var execErr error
var ensureRevisionStatus string

req.Repo = protocol.NormalizeRepo(req.Repo)
@@ -481,15 +480,17 @@ func (s *Server) handleExec(w http.ResponseWriter, r *http.Request) {
}
args := strings.Join(req.Args, " ")

tr := nettrace.New("exec."+cmd, string(req.Repo))
var tr *trace.Trace
tr, ctx = trace.New(ctx, "exec."+cmd, string(req.Repo))
tr.LazyPrintf("args: %s", args)
execRunning.WithLabelValues(cmd, repo).Inc()
defer func() {
tr.LazyPrintf("status=%s stdout=%d stderr=%d", status, stdoutN, stderrN)
if errStr != "" {
tr.LazyPrintf("error: %s", errStr)
tr.SetError()
}
tr.LogFields(
otlog.String("status", status),
otlog.Int64("stdout", stdoutN),
otlog.Int64("stderr", stderrN),
)
tr.SetError(execErr)
tr.Finish()

duration := time.Since(start)
@@ -517,8 +518,8 @@ func (s *Server) handleExec(w http.ResponseWriter, r *http.Request) {
ev.AddField("stderr_size", stderrN)
ev.AddField("exit_status", exitStatus)
ev.AddField("status", status)
if errStr != "" {
ev.AddField("error", errStr)
if execErr != nil {
ev.AddField("error", execErr.Error())
}
if !cmdStart.IsZero() {
ev.AddField("cmd_duration_ms", cmdDuration.Seconds()*1000)
@@ -616,11 +617,7 @@ func (s *Server) handleExec(w http.ResponseWriter, r *http.Request) {
cmd.Stdout = stdoutW
cmd.Stderr = stderrW

var err error
exitStatus, err = runCommand(ctx, cmd)
if err != nil {
errStr = err.Error()
}
exitStatus, execErr = runCommand(ctx, cmd)

status = strconv.Itoa(exitStatus)
stdoutN = stdoutW.n
@@ -632,7 +629,7 @@ func (s *Server) handleExec(w http.ResponseWriter, r *http.Request) {
}

// write trailer
w.Header().Set("X-Exec-Error", errStr)
w.Header().Set("X-Exec-Error", errorString(execErr))
w.Header().Set("X-Exec-Exit-Status", status)
w.Header().Set("X-Exec-Stderr", string(stderr))
}
@@ -1332,3 +1329,12 @@ func quickRevParseHead(dir string) (string, error) {
// Didn't find the refs/heads/$HEAD_BRANCH in packed_refs
return "", errors.New("could not compute `git rev-parse HEAD` in-process, try running `git` process")
}

// errorString returns the error string. If err is nil it returns the empty
// string.
func errorString(err error) string {
if err == nil {
return ""
}
return err.Error()
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.